Ejemplo n.º 1
0
 public function authenticate($admin_panel = false)
 {
     $user = User::model()->findByAttributes(array("email" => $this->username));
     if (!$user || $user->password != md5($this->password)) {
         $this->errorCode = self::ERROR_UNKNOWN;
         return;
     }
     switch ($user->status) {
         case User::STATUS_ACTIVE:
             $this->errorCode = self::ERROR_NONE;
             $this->_id = $user->id;
             if ($this->remember_me) {
                 Yii::app()->user->login($this, 3600 * 24 * 7);
             } else {
                 Yii::app()->user->login($this);
             }
             break;
         case User::STATUS_BLOCKED:
             $this->errorCode = self::ERROR_BLOCKED;
             break;
         case User::STATUS_NEW:
             $this->errorCode = self::ERROR_NOT_ACTIVE;
             break;
     }
     if (!$this->errorCode && $admin_panel) {
         WebUser::setRole($user->role);
         if (!RbacModule::isAllow('Admin_Main')) {
             Yii::app()->user->logout();
             $this->errorCode = self::ERROR_UNKNOWN;
             return false;
         }
     }
     return !$this->errorCode;
 }