kipkapkup
(Kipkapkup)
October 28, 2010, 11:30am
1
Can we extend CWebUser without the present of User model class? Currently I do not define User model class, instead I’m using other class name ( and table ) to define user class ( LdapUser ) I tried to create this class :
class WebUser extends CWebUser {
private $_model;
function isAdmin() {
$user = $this->loadUser(Yii::app()->user->id);
return intval($user->role_id)==1;
}
protected loadUser($id){
if($id===null){
if($id!==null){
$this->_model = Ldapuser::model()->findByAttributes(array('user_id'=>$id))
}
}
return $this->_model;
}
}
and configuration file :
'components'=>array(
'user'=>array(
'class'=>'WebUser',
// enable cookie-based authentication
'allowAutoLogin'=>true,
),
)
But Im getting white screen with these option.
Please help
stianlik
(Stianlik)
October 29, 2010, 10:46am
2
If you generated the application, you should take a look at WebRoot/protected/components/UserIdentity.php, that is where authentication is configured.
"CWebUser should be used together with an identity which implements the actual authentication algorithm." - CWebUser
Example:
function authenticate() {
$user = Ldapuser::model()->findByAttributes(array('user_id'=>$id)); // why not findByPk($id) ?
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
$this->errorCode=self::ERROR_NONE;
}
}
return !$this->errorCode;
}
public function getId() {
return $this->_id;
}
zaccaria
(Matteo Falsitta)
October 29, 2010, 11:03am
3
If you get white screen it means that you have some syintax error that is not displayed.
Put this in your index.php:
error_reporting(E_ALL);
ini_set('display_errors',1);
in order to display all errors.
kipkapkup
(Kipkapkup)
November 5, 2010, 8:56am
4
zaccaria:
If you get white screen it means that you have some syintax error that is not displayed.
Put this in your index.php:
error_reporting(E_ALL);
ini_set('display_errors',1);
in order to display all errors.
Thanks zaccaria, it was indeed a syntax error. Now I get the custom WebUser class running smoothly.