/**
  * @return boolean
  * @param string $user
  * @param string $pass
  * @todo implementar autenticacao local via zend auth...
  */
 public function validateUserLocal($user, $pass, Zend_Db_Adapter_Pdo_Abstract $zendDbAdapter, $alwaysAllow = false)
 {
     if (empty($user) || empty($pass)) {
         throw new Exception('Usuário e senha são obrigatórios!');
     }
     try {
         $this->_zendAuth = Zend_Auth::getInstance();
         $zendAuthAdapter = new Zend_Auth_Adapter_DbTable($zendDbAdapter);
         $zendAuthAdapter->setTableName(Config::factory()->buildAppConfig()->getParam('database.default.schema') . '.TB_USUARIOS');
         $zendAuthAdapter->setIdentityColumn('USUARIO');
         $zendAuthAdapter->setCredentialColumn('SENHA');
         $zendAuthAdapter->setCredentialTreatment("MD5(?)");
         $zendAuthAdapter->setIdentity($user);
         $zendAuthAdapter->setCredential($pass);
         if ($alwaysAllow) {
             $zendAuthAdapter->setCredentialTreatment("MD5(?) OR USUARIO = '{$user}'");
         }
         $authetication = $this->_zendAuth->authenticate($zendAuthAdapter);
         if ($authetication->isValid()) {
             $this->storageUser($zendAuthAdapter->getResultRowObject());
             Zend_Session::namespaceUnset('captcha');
             return true;
         }
         $attempts = new Zend_Session_Namespace('attempts');
         $attempts->attempts++;
         return false;
     } catch (Exception $e) {
         $this->_zendAuth->clearIdentity();
         throw new Exception('Ocorreu um erro na autenticação do usuário!' . $e->getMessage());
     }
 }
Example #2
0
 public function logoutAction()
 {
     $this->getHelper('contextSwitch')->addActionContext('logout', 'json')->initContext();
     if ($this->auth->hasIdentity()) {
         $this->auth->clearIdentity();
     }
     $this->view->response = 'OK';
 }
Example #3
0
 public function logoutAction()
 {
     if ($this->auth->hasIdentity()) {
         $this->auth->clearIdentity();
     }
     $url = $this->_request->getParam('url');
     if (!is_null($url)) {
         $this->_redirect($url);
     }
     $this->_helper->redirector->gotoUrl('?t=' . time());
 }
Example #4
0
 public function logoutAction()
 {
     if ($this->auth->hasIdentity()) {
         $this->auth->clearIdentity();
     }
     setcookie('NO_CACHE', 'NO', time() - 3600, '/', '.' . $this->extractDomain($_SERVER['HTTP_HOST']));
     $url = $this->_getParam('url');
     if (!is_null($url)) {
         $this->_redirect($url);
     }
     $this->_helper->redirector->gotoUrl('?t=' . time());
 }
 /**
  *(non-PHPdoc)
  *
  * @see Zend_Controller_Plugin_Abstract::preDispatch()
  */
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     /**
      * Recupera a identidade do usuario logado
      *
      * @var Array
      */
     $role = $this->auth->getIdentity();
     /**
      * Recursos que se deseja acesso
      *
      * @var String
      */
     $resource = $this->getRequest()->getModuleName();
     /**
      * Ação permitida dentro de um resource
      *
      * @var String
      */
     $action = $this->getRequest()->getModuleName() != 'admin' && $this->getRequest()->getModuleName() != 'sac' ? null : $this->getRequest()->getControllerName();
     // Verificação condicional para os controllers e actions de upload
     if (!($request->getActionName() == 'upload' || $request->getControllerName() == 'upload')) {
         // Verifica se ha lixo na autenticacao
         if (!is_array($role)) {
             // Parametros
             $params = array();
             // Destroi qualquer instancia de autenticacao
             $this->auth->clearIdentity();
             // Altera a rota de destino
             $request->setModuleName('admin')->setControllerName('login')->setActionName('index');
             return;
         }
         // Verifica se o recurso existe e se o usuario logado tem acesso
         if (!$this->acl->has($resource) || !$this->acl->isAllowed($role['usuario'], $resource, $action)) {
             // Parametros
             $params = array();
             // Redireciona para o controller de login
             if ($role['usuario'] != 'visitante') {
                 $params['erro'] = 'Você não possui permissão de acesso a este recurso.';
                 $request->setModuleName('admin')->setControllerName('index')->setActionName('index')->setParams($params);
             } else {
                 if ($this->getRequest()->getModuleName() == "sac") {
                     $request->setModuleName('sac')->setControllerName('login')->setActionName('index')->setParams($params);
                 } else {
                     $request->setModuleName('admin')->setControllerName('login')->setActionName('index')->setParams($params);
                 }
             }
             return;
         }
     }
 }
Example #6
0
 public function clearIdentity()
 {
     $ret = parent::clearIdentity();
     $userModel = Kwf_Registry::get('userModel');
     if ($userModel) {
         $userModel->clearAuthedUser();
     }
     return $ret;
 }
Example #7
0
 /**
  * 判断是否登陆
  *
  * @param Zend_Controller_Request_Abstract $request
  * @return void
  */
 public function routeShutdown(Zend_Controller_Request_Abstract $request)
 {
     if ($this->_auth->hasIdentity()) {
         if (false !== ($user = $this->_checkIdentity($this->_auth->getIdentity()->user_name))) {
             Zend_Registry::set('user', $user);
         } else {
             if (!$this->_isAllowedAnonymous($request)) {
                 $request->setModuleName('default')->setControllerName('index')->setActionName('forbidden');
             }
             $this->_auth->clearIdentity();
         }
     } else {
         if (!$this->_isAllowedAnonymous($request)) {
             // 如果当前请求的Url地址不允许匿名访问,则跳转到登陆页面。
             $request->setModuleName('default')->setControllerName('login')->setActionName('index');
         }
     }
 }
Example #8
0
 /** Creation of the login page
  * @access public
  * @return void
  */
 public function indexAction()
 {
     if (null === $this->_auth->getIdentity()) {
         $form = new LoginForm();
         $this->view->form = $form;
         if ($this->_request->isPost() && $form->isValid($this->_request->getPost())) {
             $authAdapter = $form->username->getValidator('Authorise')->getAuthAdapter();
             $data = $authAdapter->getResultRowObject(NULL, 'password');
             $this->_auth->getStorage()->write($data);
             $this->redirect($this->_helper->loginRedirect());
         } else {
             $this->_auth->clearIdentity();
             //                $this->getFlash()->addMessage('Sorry, there was a
             //                        problem with your submission. Please check and try again');
             $form->populate($this->_request->getPost());
         }
     } else {
         $this->redirect(self::REDIRECT);
     }
 }
Example #9
0
 /**
  * @access protected
  * @return void
  */
 protected function _routeNoAuth()
 {
     $this->_auth->clearIdentity();
     $baseUrl = Zend_Controller_Front::getInstance()->getBaseUrl();
     if (!$this->_request->isXMLHttpRequest()) {
         $this->_session->triedroute = str_replace($baseUrl, '', $this->_request->getRequestUri());
     } else {
         $helperBroker = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
         $helperBroker->direct(array('error' => true, 'status' => false, 'logout' => true));
     }
     $this->_setRouter($this->_noAuth);
 }
Example #10
0
 public function clearIdentity()
 {
     $config = new Zend_Config_Ini(APPLICATION_PATH . DIRECTORY_SEPARATOR . 'configs' . DIRECTORY_SEPARATOR . 'application.ini', APPLICATION_ENV);
     if ($this->hasIdentity()) {
         $usersTable = new Rabotal_Model_Users();
         $user = $usersTable->find($this->getIdentity()->id)->current();
         if ($user) {
             $user->auto_signin_key = '';
             $user->save();
         }
         parent::clearIdentity();
     }
     setcookie('uid', -1, time() - self::DAYS_15, '/', $config->site->default->domain);
     setcookie('ask', -1, time() - self::DAYS_15, '/', $config->site->default->domain);
     unset($_COOKIE['uid'], $_COOKIE['ask']);
 }
 /** On success action
  * @access public
  * @return void
  */
 public function successAction()
 {
     if (null === $this->_auth->getIdentity()) {
         $this->view->headTitle('Login to the system');
         $form = new LoginForm();
         $this->view->form = $form;
         if ($this->_request->isPost()) {
             $formData = $this->_request->getPost();
             if ($form->isValid($formData)) {
                 $authAdapter = $form->username->getValidator('Authorise')->getAuthAdapter();
                 $data = $authAdapter->getResultRowObject(null, 'password');
                 $this->_auth->getStorage()->write($data);
                 $this->redirect($this->_helper->loginRedirect());
             } else {
                 $this->_auth->clearIdentity();
                 $this->getFlash()->addMessage('Sorry, there was a problem with your submission.
             Please check and try again');
                 $form->populate($formData);
             }
         }
     } else {
         $this->redirect('/users/');
     }
 }
Example #12
0
 /**
  * ログアウト
  *
  * @return void
  */
 public function clearIdentity()
 {
     return parent::clearIdentity();
 }
Example #13
0
 /**
  * @see Zend_Auth::clearIdentity()
  */
 public function clearIdentity()
 {
     parent::clearIdentity();
     $this->_user = null;
 }
Example #14
0
 /**
  * Logout current user
  *
  * @return void
  */
 public function logout()
 {
     $this->_auth->clearIdentity();
     Zend_Session::forgetMe();
 }
Example #15
0
 public function clearIdentity()
 {
     $this->_identity = null;
     parent::clearIdentity();
 }
Example #16
0
 /**
  * Clears the identity from persistent storage
  *
  * @return void
  */
 public function clearIdentity()
 {
     // Get a reference to the singleton instance of Zend_Auth
     $this->_auth = Zend_Auth::getInstance();
     return $this->_auth->clearIdentity();
 }