Пример #1
0
 /**
  * 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.
  */
 public function authenticate()
 {
     $user_info = MemberModel::model()->find("username=:username", array(":username" => $this->username));
     if ($user_info) {
         if ($user_info['pswd'] != md5($this->password)) {
             $this->errorCode = self::ERROR_PASSWORD_INVALID;
         } else {
             $this->errorCode = self::ERROR_NONE;
         }
     } else {
         $this->errorCode = self::ERROR_USERNAME_INVALID;
     }
     return !$this->errorCode;
 }
Пример #2
0
 public function beforeAction($action)
 {
     if (parent::beforeAction($action)) {
         if (Yii::app()->user->isGuest) {
             $this->redirect(array('site/login'));
         } else {
             $userInfo = MemberModel::model()->find('username=:username', array(':username' => Yii::app()->user->name));
             foreach (GroupModel::model()->findAll() as $g) {
                 $group[$g->id] = $g;
             }
             Yii::app()->session['group'] = $group;
             Yii::app()->session['userInfo'] = array('uid' => $userInfo->uid, 'username' => $userInfo->username, 'nickname' => $userInfo->nickname, 'lv' => $userInfo->lv, 'groupId' => $userInfo->groupId);
         }
     }
     return true;
 }