Because I wanna to access role type. I add some function in UserIdentity
<?php
class UserIdentity extends CUserIdentity
{
/**
* Authenticates a user.
* The example implementation makes sure if the username and password
* are both 'demo'.
* In practical applications, this should be changed to authenticate
* against some persistent user identity storage (e.g. database).
* @return boolean whether authentication succeeds.
*/
private $_id;
private $_roleId;
public function authenticate()
{
$user = Users::model()->findByAttributes(array('username' => $this->username) );
if($user->username !== $this->username){
$this->errorCode = self::ERROR_USERNAME_INVALID;
}elseif($user->password !== $this->hash($this->password)){
$this->errorCode = self::ERROR_PASSWORD_INVALID;
}else{
$this->errorCode = self::ERROR_NONE;
$this->_id = $user->user_id;
$this->roleId = $user->user_level_id;
}
return !$this->errorCode;
}
public function hash($string){
return sha1($string);
}
public function getId(){
return $this->_id;
}
public function getRoleType(){
return $this->_roleId;
}
}
I add getRoleType() function. but when I try to access it using
See here for more info about CWebUser. There you can see how authentication process between UserIdentity and CWebUser looks like. Should give you an idea how to implement the things you need.
the result is "CPhpAuthManager does not have a method named "isLoser"", and if i use:
var_dump(Yii::app()->user);
i get correctly a MyWebUser object, which is great… but with _id and _level set to null! so it looks like MyWebUser->_level is never set, even though i add something like:
public function login()
{
$this->_level="MYLEVEL";
}
in MyWebUser class. How should i set it?
please, help
WOW, got it!
class MyWebUser extends CWebUser
{
public function getLevel($name){
$user=BoUsers::model()->find('LOWER(emailAddress)=?',array($name));
return $user->powerUser;
}
}