Ejemplo n.º 1
0
 protected function _initUser()
 {
     $this->bootstrap('Db');
     $auth = Rabotal_Auth::getInstance();
     $userTable = new Rabotal_Model_Users();
     $user = NULL;
     if (!$auth->hasIdentity() && !empty($_COOKIE['uid']) && !empty($_COOKIE['ask'])) {
         $_user = $userTable->find((int) $_COOKIE['uid'])->current();
         if ($_user && $_user->auto_signin_key === $_COOKIE['ask']) {
             Rabotal_Auth::identityWrite($_user);
         } else {
             $auth->clearIdentity();
         }
         unset($_user);
     }
     if ($auth->hasIdentity()) {
         $user = $userTable->find($auth->getIdentity()->id)->current();
         if (!$user) {
             $auth->clearIdentity();
         } else {
             $userProfile = $user->findDependentRowset('Rabotal_Model_UsersProfile', 'User')->current();
             if ($userProfile && $userProfile->forgot_key !== '') {
                 $userProfile->forgot_key = NULL;
                 $userProfile->save();
             }
             $user->id = (int) $user->id;
         }
     }
     return $user;
 }
Ejemplo n.º 2
0
 public function signOutAction()
 {
     Rabotal_Auth::getInstance()->clearIdentity();
     $this->_redirect('/');
 }
Ejemplo n.º 3
0
 private function _signIn($formData)
 {
     $security = $this->getInvokeArg('bootstrap')->getOption('secure');
     $authAdapter = new Zend_Auth_Adapter_DbTable($this->getInvokeArg('bootstrap')->getResource('DB'), 'users', 'email', 'password', 'sha1(?)');
     $auth = Rabotal_Auth::getInstance();
     $authAdapter->setIdentity($formData['email'])->setCredential($security['salt'] . $formData['password']);
     $result = $auth->authenticate($authAdapter);
     if ($result->isValid()) {
         Rabotal_Auth::identityWrite($authAdapter->getResultRowObject(array('id', 'username', 'email')));
     } else {
         throw new Zend_Exception("Неверное сочетание электронной почты и пароля");
     }
     return true;
 }