Yii Framework Forum: How To Add More Information To Yii::app()->User - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How To Add More Information To Yii::app()->User Rate Topic: -----

#1 User is offline   p30tec 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 78
  • Joined: 03-March 13

Posted 29 June 2013 - 11:13 AM

Hello
in this Wiki http://www.yiiframew...to-yii-app-user
we have this code
class UserIdentity extends CUserIdentity
{
    private $_id;
 
    public function authenticate()
    {
        $user=User::model()->findByAttributes(array('username'=>$this->username));
        if($user===null)
            $this->errorCode=self::ERROR_USERNAME_INVALID;
        else if($user->password!==md5($this->password))
            $this->errorCode=self::ERROR_PASSWORD_INVALID;
        else
        {
            $this->_id=$user->id;
            $this->setState('lastLoginTime', $user->lastLoginTime);
            $this->errorCode=self::ERROR_NONE;
        }
        return !$this->errorCode;
    }
 
    public function getId()
    {
        return $this->_id;
    }
}


I want to know , Just lastLoginTime will save in Cookie if allowAutoLogin==true , Or both $_id and lastLoginTime will save in Cookie if allowAutoLogin==true

I want to create these class

For FrontEnd
class FrontEndIdentity extends CUserIdentity{
 public $isAdmin = false;
}


For Backend
class BackEndIdentity extends CUserIdentity{
  public $isAdmin = true;
}


and in use Yii::app()->user->isAdmin to detect admin , Is it SAFE ??
(I save admin and user information in deferent Database table and may be admin and user have equal ID)
0

#2 User is offline   redguy 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 779
  • Joined: 02-July 10
  • Location:Central Poland

Posted 30 June 2013 - 03:41 AM

1. both states will be saved in cookie for auto login

2. CUserIdentity is NOT what is visible under Yii::app()->user. in order to extend this component and add "isAdmin" attribute you need to to extend also CWebUser and configure applicatio to use instead of the default class.
red
0

#3 User is offline   p30tec 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 78
  • Joined: 03-March 13

Posted 01 July 2013 - 03:56 AM

ok thanks
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users