Advertisement
Guest User

Untitled

a guest
Jun 16th, 2011
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.38 KB | None | 0 0
  1. public function authenticate($attribute,$params)
  2.     {
  3.         if(!$this->hasErrors())
  4.         {
  5.             $this->_identity = new UserIdentity($this->email, $this->password);
  6.             $this->_identity->authenticate();
  7.      
  8.       switch($this->_identity->errorCode) {
  9.         case UserIdentity::ERROR_NONE:
  10.  
  11.             Yii::app()->user->login($this->_identity);
  12.             //Note: I don't see the point of logging in here - this method is
  13.             //just responsible for authentication of the password
  14.          
  15.             break;
  16.         case UserIdentity::ERROR_USERNAME_INVALID:
  17.             $this->addError('email','Email address is incorrect.');
  18.             break;
  19.         default: // UserIdentity::ERROR_PASSWORD_INVALID
  20.             $this->addError('password','Password is incorrect.');
  21.             break;
  22.       }
  23.                
  24.         }
  25.     }
  26.  
  27.     /**
  28.      * Logs in the user using the given username and password in the model.
  29.      * @return boolean whether login is successful
  30.      */
  31.     public function login()
  32.     {
  33.         if($this->_identity === null)
  34.         {
  35.             $this->_identity = new UserIdentity($this->email, $this->password);
  36.             $this->_identity->authenticate();
  37.         }
  38.    
  39.         if($this->_identity->errorCode === UserIdentity::ERROR_NONE)
  40.         {
  41.             $duration = $this->rememberMe ? 3600*24*30 : 0; // 30 days
  42.             Yii::app()->user->login($this->_identity, $duration);
  43.      
  44.             return true;
  45.         }
  46.         else
  47.             return false;
  48.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement