I’m quite new with this framework and I have a simple question regarding the authenticate:
I modified the function authenticate to this:
public function authenticate()
{
$user = Users::model()->findByAttributes(array('user' => $this->username));
if ($user === null) {
$this->errorCode = self::ERROR_USERNAME_INVALID;
} else {
if ($user->password !== $user->encrypt($this->password)) {
$this->errorCode = self::ERROR_PASSWORD_INVALID;
} else {
$this->_id = $user->id;
if (null === $user->lastlogin) {
$lastLogin = time();
} else {
$lastLogin = strtotime($user->lastlogin);
}
$this->setState('lastlogin', $lastLogin);
$this->errorCode = self::ERROR_NONE;
if($user->admin == 1)
// FUNCTION TO SET THE USER TO ADMIN? - Admin right rules <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/smile.gif' class='bbc_emoticon' alt=':)' />
else
// FUNCTION TO SET THE USER TO NORMAL - I'm just a normal user <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/sad.gif' class='bbc_emoticon' alt=':(' />
}
}
return !$this->errorCode;
}
Exists there any call to set simple the user to admin or to a normal user like the default configuration "demo/demo" and "admin/admin" ?
public function authenticate()
{
$user = Users::model()->findByAttributes(array('user' => $this->username));
if ($user === null) {
$this->errorCode = self::ERROR_USERNAME_INVALID;
} else {
if ($user->password !== $user->encrypt($this->password)) {
$this->errorCode = self::ERROR_PASSWORD_INVALID;
} else {
$this->_id = $user->id;
if (null === $user->lastlogin) {
$lastLogin = time();
} else {
$lastLogin = strtotime($user->lastlogin);
}
$this->setState('lastlogin', $lastLogin);
$this->errorCode = self::ERROR_NONE;
/*if($user->admin == 1)
// FUNCTION TO SET THE USER TO ADMIN? - Admin right rules <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/smile.gif' class='bbc_emoticon' alt=':)' />
$this->setState('amin')
else
// FUNCTION TO SET THE USER TO NORMAL - I'm just a normal user <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/sad.gif' class='bbc_emoticon' alt=':(' />
*/
$this->setState('admin', $user->admin == 1)
}
}
return !$this->errorCode;
}