Hi,
I’m having trouble understanding the logic of the authenticate method in this page
http://www.yiiframework.com/doc/blog/1.1/en/prototype.auth
particularly the return statement
return $this->errorCode==self::ERROR_NONE;
why not do the return inside each if statements?
Also the return looks like an error, but it’s not, so how is it possible that for example, the user is null, then $this->errorCode=self::ERROR_USERNAME_INVALID was called, but after that, the code returned $this->errorCode=self::ERROR_NONE but was yet able to inform the user of an invalid entry and block the user from passing the login form?
public function authenticate()
{
$username=strtolower($this->username);
$user=User::model()->find('LOWER(username)=?',array($username));
if($user===null)
$this->errorCode=self::ERROR_USERNAME_INVALID;
else if(!$user->validatePassword($this->password))
$this->errorCode=self::ERROR_PASSWORD_INVALID;
else
{
$this->_id=$user->id;
$this->username=$user->username;
$this->errorCode=self::ERROR_NONE;
}
return $this->errorCode==self::ERROR_NONE;
}