Beispiel #1
0
 /**
  * @todo Change the $dbAdapter for making it automatic according to the config, here we are stuck with MySQL
  * @param Zend_Controller_Request_Http $request
  * @param bool $encryptedPass
  * @return bool|Sydney_Auth_Adaptater_DbTable
  */
 public static function getAuthAdapter(Zend_Controller_Request_Http $request, $encryptedPass = false)
 {
     // Load cookie informations
     $identity = Sydney_Http_Cookie::getIdentity($request);
     $credential = Sydney_Http_Cookie::getCredential($request);
     // Load params
     $params = $request->getParams();
     // Auth with identity and credential loaded from cookie
     if (empty($identity) && empty($credential) && empty($params['username']) && empty($params['password'])) {
         // IF no username and no password then return false
         return false;
     } elseif (!empty($identity) && !empty($credential) && empty($params['username']) && empty($params['password'])) {
         // IF identity loaded from cookie then set as params
         $params['username'] = $identity;
         $params['password'] = $credential;
     }
     $where2 = " 1 = 2 ";
     $username = strtolower(addslashes($params['username']));
     $password = addslashes($params['password']);
     // get the user if any
     $uDB = new Users();
     $users = $uDB->fetchAll(" LOWER(login) LIKE '" . $username . "' ");
     // one user found
     if (count($users) == 1) {
         if ($users[0]->safinstances_id == Sydney_Tools::getSafinstancesId()) {
             $where2 = " 1 = 1 ";
         } else {
             $corDB = new SafinstancesUsers();
             $cors = $corDB->fetchAll(" safinstances_id = " . Sydney_Tools::getSafinstancesId() . " AND users_id = " . $users[0]->id . " ");
             if (count($cors) > 0) {
                 $where2 = " 1 = 1 ";
             }
         }
         $username = $users[0]->login;
     }
     $config = Zend_Registry::get('config');
     $dbAdapter = new Zend_Db_Adapter_Pdo_Mysql($config->db->params);
     if ($encryptedPass === false) {
         $authAdapter = new Sydney_Auth_Adaptater_DbTable($dbAdapter, 'users', 'login', 'password', 'MD5(?) AND valid = 1 AND active = 1 AND (TIMESTAMPADD(SECOND,timeValidityPassword,lastpwdchanges) > now() OR timeValidityPassword = 0) AND ' . $where2);
     } else {
         $authAdapter = new Sydney_Auth_Adaptater_DbTable($dbAdapter, 'users', 'login', 'password', '? AND valid = 1 AND active = 1 AND (TIMESTAMPADD(SECOND,timeValidityPassword,lastpwdchanges) > now() OR timeValidityPassword = 0) AND ' . $where2);
     }
     // Store username and pass to cookie
     if ($params['rememberme'] == "1") {
         Sydney_Http_Cookie::setAuthCookie($username, $password, 7);
     }
     $authAdapter->setIdentity($username)->setCredential($password);
     return $authAdapter;
 }
Beispiel #2
0
 /**
  *
  * @todo Change the $dbAdapter for making it automatic according to the config, here we are stuck with MySQL
  * @param $params
  * @return Zend_Auth_Adapter_DbTable
  */
 private function getAuthAdapter(Zend_Controller_Request_Http $request, $encryptedPass = false)
 {
     return Sydney_Auth_Adaptater_DbTable::getAuthAdapter($request, $encryptedPass);
 }
Beispiel #3
0
 /**
  * Auto initialization of important params for sydney
  * @return void
  */
 public function init()
 {
     // register general sydney helpers
     $this->view->addHelperPath(Sydney_Tools_Paths::getCorePath() . '/library/Sydney/View/Helper', 'Sydney_View_Helper');
     $this->_initWebInstanceHelpers();
     // setup the basics
     $this->_registry = Zend_Registry::getInstance();
     $this->_config = $this->_registry->get('config');
     $this->_db = $this->_registry->get('db');
     $this->safinstancesId = $this->_config->db->safinstances_id;
     $this->_translate = $this->_registry->get('Zend_Translate');
     $this->view->translate = $this->_registry->get('Zend_Translate');
     $this->_auth = Sydney_Auth::getInstance();
     // Auto Login if identity and credentials stored in cookie
     $u = $this->getRequest()->getParam('username');
     $p = $this->getRequest()->getParam('password');
     if (!$this->_auth->hasIdentity() && $this->_getParam('action') != 'login' && $this->_getParam('action') != 'logout' && empty($u) && empty($p)) {
         $adapter = Sydney_Auth_Adaptater_DbTable::getAuthAdapter($this->getRequest());
         if ($adapter instanceof Zend_Auth_Adapter_Interface) {
             $auth = Sydney_Auth::getInstance();
             if ($auth->authenticate($adapter)->isValid()) {
                 $this->_helper->redirector->gotoUrl($this->getRequest()->getRequestUri());
                 exit;
             }
         }
     }
     // Init list secured pages
     $this->setAuthPagelist();
     // setup user
     $udata = new Zend_Session_Namespace('userdata');
     if (isset($udata->user)) {
         $this->usersData = $udata->user;
     }
     if (isset($this->usersData['users_id'])) {
         $this->usersId = $this->usersData['users_id'];
     }
     // sets some interesting vars in the view
     $this->view->config = $this->_config;
     $this->view->cdn = $this->_config->general->cdn;
     $this->view->users_data = $this->usersData;
     $this->view->safinstances_id = $this->safinstancesId;
     $this->view->auth = $this->_auth;
     $this->view->siteTitle = $this->_config->general->siteTitle;
     $this->view->printme = $this->_getParam('printme', 'no');
     // @todo TODO change this ...
     $llg = 'en';
     if (isset($this->_config->general->lang) && $this->_config->general->lang != '') {
         $llg = $this->_config->general->lang;
     }
     $this->view->headScript()->appendFile($this->view->cdn . '/sydneyassets/scripts/i18n/' . $llg . '.js', 'text/javascript');
     // setup some layout vars
     if ($this->layout !== null) {
         $this->layout->registry = $this->_registry;
         $this->layout->auth = $this->_auth;
         $this->layout->translate = $this->_registry->get('Zend_Translate');
         $this->layout->avmodules = $this->availableModules;
     }
     $this->view->moduleName = $this->_getParam('module');
     $this->view->controllerName = $this->_getParam('controller');
     $this->view->actionName = $this->_getParam('action');
     // set up the log
     $this->logger = new Sydney_Log();
     $this->logger->setEventItem('className', get_class($this));
     $this->logger->addFilterDatabase();
     if (isset($this->getRequest()->sydneylayout) && $this->getRequest()->sydneylayout == 'no') {
         $this->_helper->layout->disableLayout();
         $this->sydneyLayout = 'no';
     }
     if (isset($this->getRequest()->sydneylayout) && $this->getRequest()->sydneylayout != 'no' && $this->getRequest()->sydneylayout != 'yes') {
         $this->_helper->layout->setLayout('layout-' . $this->getRequest()->sydneylayout);
     }
     $this->view->sydneylayout = $this->sydneyLayout;
     /**
      * load structure if not exist
      */
     if (!is_array($this->view->structure) && $this->getRequest()->layout != 'no') {
         $this->structure = new Pagstructure();
         $this->view->adminmode = false;
         // if identified then get structure from database
         if (Sydney_Auth::getInstance()->hasIdentity()) {
             $this->structure->setFilter('status', 'published');
             $this->view->structure = $this->structure->toArray($this->safinstancesId);
         } else {
             // else use structure cached or build cache
             $cache = Zend_Registry::get('cache');
             $cn = PagstructureOp::getCacheNames($this->safinstancesId);
             $this->view->structure = $cache->load($cn[0]);
             //cn[0] > cachename
             $this->structure->stringNodes = $cache->load($cn[1]);
             //cn[1] > cachename2
             if (!is_array($this->view->structure)) {
                 $this->structure->setFilter('status', 'published');
                 $this->view->structure = $this->structure->toArray($this->safinstancesId);
                 $cache->save($this->view->structure, $cn[0]);
                 $cache->save($this->structure->getStringNodes(), $cn[1]);
             }
         }
         $r = $this->getRequest();
         if (isset($r->layout) && $r->layout == 'no') {
             Zend_Layout::getMvcInstance()->disableLayout(true);
         }
         $pages = $this->_getPageId();
         $this->view->breadCrumData = $this->structure->getBreadCrumData($this->safinstancesId, $pages[0]);
     }
     // change language if necessary
     $settingsNms = new Zend_Session_Namespace('appSettings');
     $curLang = $this->getCurrentLangCode();
     if ($settingsNms->ApplicationLanguage != $curLang) {
         $settingsNms->ApplicationLanguage = $curLang;
         $bootstrapper = Zend_Registry::get('bootstrapper');
         $bootstrapper->setRequestLang($curLang);
         $bootstrapper->setTranslationObject();
     }
     $this->view->lang = $settingsNms->ApplicationLanguage;
     $pages = isset($pages) ? $pages : $this->_getPageId();
     $this->_manageCanonicalLinks($pages[0]);
 }