Exemplo n.º 1
0
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     if (!isset($_SERVER['HTTP_USER_AGENT']) || isset($_SERVER['HTTP_USER_AGENT']) && false === strpos($_SERVER['HTTP_USER_AGENT'], 'sanmax-crawler-bot')) {
         return;
     }
     $config = array('accept_schemes' => 'basic', 'realm' => 'crawler', 'digest_domains' => '/', 'nonce_timeout' => 3600);
     $adapter = new Zend_Auth_Adapter_Http($config);
     $basicResolver = new Zend_Auth_Adapter_Http_Resolver_File(APPLICATION_PATH . '/var/bot-basic');
     $adapter->setBasicResolver($basicResolver);
     $response = Zend_Controller_Front::getInstance()->getResponse();
     $adapter->setRequest($request);
     $adapter->setResponse($response);
     $auth = Zend_Auth::getInstance();
     $result = $auth->authenticate($adapter);
     if (!$result->isValid()) {
         $response->sendHeaders();
         exit;
     }
     $user = new SxCms_User();
     $gMapper = new SxCms_Group_DataMapper();
     $groups = $gMapper->getAll();
     foreach ($groups as $group) {
         $user->addGroup($group);
     }
     $storage = $auth->getStorage();
     $storage->write($user);
     $front = Zend_Controller_Front::getInstance();
     $front->setParam('isBot', true);
     $mvc = Zend_Layout::getMvcInstance();
     $view = $mvc->getView();
     $view->isBot = true;
     return;
 }
Exemplo n.º 2
0
 /**
  * Validate user's data
  *
  * @return boolean
  */
 public function validate(SxCms_User $user)
 {
     $this->_user = $user;
     $this->_validateEmail();
     if ($user->getPassword()) {
         $this->_validatePassword();
         $this->_validateOldPassword();
     }
     $this->_validateFirstName();
     $this->_validateLastName();
     $msgr = Sanmax_MessageStack::getInstance('SxCms_User');
     if (!$msgr->getNamespaceMessages()) {
         return true;
     }
     return false;
 }
Exemplo n.º 3
0
 /**
  * Validates the last name
  *
  * @return boolean
  */
 protected function _validateLastName()
 {
     $validator = new Zend_Validate_StringLength(2, 255);
     if ($validator->isValid($this->_user->getLastName())) {
         return true;
     }
     $msg = Sanmax_MessageStack::getInstance('SxCms_User');
     $msg->addMessage('last_name', $validator->getMessages(), 'common');
     return false;
 }
Exemplo n.º 4
0
 /**
  * Delete a user on the datasource
  * 
  * @param SxCms_User $user
  * @return int
  */
 public function delete(SxCms_User $user)
 {
     $db = Zend_Registry::get('db');
     return $db->delete('User', 'user_id = ' . $user->getId());
 }
Exemplo n.º 5
0
 public function loginAction()
 {
     $user = new SxCms_User();
     $config = Zend_Registry::get('config');
     $this->view->sytemadminlng = $config->systemadmin->language->toArray();
     if ($this->getRequest()->isPost()) {
         $user->setEmail($this->_getParam('username'))->setPassword($this->_getParam('password'));
         $validator = new SxCms_User_LoginValidator();
         if ($validator->validate($user) && $user->login()) {
             $system = new Zend_Session_Namespace('System');
             $system->lng = $config->system->defaults->language;
             $systemAdmin = new Zend_Session_Namespace('SystemAdmin');
             if (array_key_exists($this->_getParam('systemAdminLng', $config->systemadmin->defaults->language), $config->systemadmin->language->toArray())) {
                 $systemAdmin->lng = $this->_getParam('systemAdminLng', $config->systemadmin->defaults->language);
             } else {
                 $systemAdmin->lng = $config->systemadmin->defaults->language;
             }
             $_SESSION['isLoggedIn'] = true;
             $this->_helper->redirector->gotoSimple('index', 'page');
         }
     }
     $this->view->user = $user;
     $this->view->messages = Sanmax_MessageStack::getInstance('SxCms_User');
     if (!$this->getRequest()->getParam('redirect')) {
         $this->_helper->layout->setLayout('login');
     }
 }