Sorry, this is a really newbie question. I’m following the blog tutorial from the official site, and I have my code like the following. After I made the changes, hitting login only goes to a blank page. Other pages are still accessible, but they still show that I’m not logged in. Any input is appreciated
Angela
/*UserIdentity.php*/
class UserIdentity extends CUserIdentity
{
private $_id;
public function getId() {
return $this->_id;
}
public function authenticate() {
$username = strtolower($this->username);
$user = User::model->find('LOWER(username)=?', array($username));
if($user === null) {
$this->errorCode = self::ERROR_USERNAME_INVALID;
} elseif(!$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;
}
}
/*User.php -> Under Models*/
public function hashPassword($password) {
return crypt($password, $this->generateSalt());
}
public function validatePassword($password) {
return crypt($password, $this->password) === $this->password;
}
/*LoginForm.php - Unmodified*/
/**
* Authenticates the password.
* This is the 'authenticate' validator as declared in rules().
*/
public function authenticate($attribute,$params)
{
if(!$this->hasErrors())
{
$this->_identity=new UserIdentity($this->username,$this->password);
if(!$this->_identity->authenticate())
$this->addError('password','Incorrect username or password.');
}
}
/**
* Logs in the user using the given username and password in the model.
* @return boolean whether login is successful
*/
public function login()
{
if($this->_identity===null)
{
$this->_identity=new UserIdentity($this->username,$this->password);
$this->_identity->authenticate();
}
if($this->_identity->errorCode===UserIdentity::ERROR_NONE)
{
$duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days
Yii::app()->user->login($this->_identity,$duration);
return true;
}
else
return false;
}