예제 #1
0
 /**
  * Logs in the user using the given username and password in the model.
  * @return boolean whether login is successful
  */
 public function change()
 {
     $user = UserAR::model()->find('ID=:id', array(':id' => Yii::app()->user->getId()));
     if ($user->verifyPassword($user->Login, $this->oldpassword, $user->Password)) {
         $user->Password = $user->hashPassword($user->Login, $this->password);
         //$user->Password = CPasswordHelper::hashPassword($user->Login.'@'.$this->password);
         $user->save();
         return true;
     } else {
         $this->addError('oldpassword', "Старый пароль указан неверно");
         //$this->message = "Старый пароль указан неверно";
         return false;
     }
 }
예제 #2
0
 /**
  * Authenticates a user.
  * @return boolean whether authentication succeeds.
  */
 public function authenticate()
 {
     $user = UserAR::model()->find('LOWER(user_name)=?', array(strtolower($this->username)));
     if ($user === null) {
         $user = UserAR::model()->find('LOWER(email)=?', array(strtolower($this->username)));
     }
     if ($user === null) {
         $this->errorCode = self::ERROR_USERNAME_INVALID;
     } else {
         if (!$user->validatePassword($this->password)) {
             $this->errorCode = self::ERROR_PASSWORD_INVALID;
         } else {
             $this->_id = $user->user_id;
             $this->username = $user->user_name;
             $this->errorCode = self::ERROR_NONE;
         }
     }
     return $this->errorCode == self::ERROR_NONE;
 }
예제 #3
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 = UserAR::model()->find('Login=:login', array(':login' => $this->username));
     if (empty($user)) {
         //Yii::app()->user->getId();
         //echo(Yii::app()->db->last_query());
         //die("wrong name");
         $this->errorCode = self::ERROR_USERNAME_INVALID;
     } else {
         if (!$user->verifyPassword($this->username, $this->password, $user->Password)) {
             $this->errorCode = self::ERROR_PASSWORD_INVALID;
         } else {
             $this->errorCode = self::ERROR_NONE;
             $this->_id = $user->ID;
             $user->LastVisitDate = $user->CurrentVisitDate;
             $this->setState('isAdmin', $user->IsAdmin);
             $user->CurrentVisitDate = new CDbExpression('NOW()');
             $user->save();
             //$this->setState("Admin","true");
         }
     }
     return !$this->errorCode;
 }
예제 #4
0
 public function actionIndex($uid = 0)
 {
     $is_self = 0;
     $user_id = $uid;
     if (empty($uid)) {
         $user_id = Yii::app()->user->id;
         $is_self = 1;
     }
     //基本信息
     $user_base_info = UserAR::model()->findByPk($user_id);
     if (empty($user_base_info)) {
         echo "no user";
         exit;
     }
     $this->assign('is_self', $is_self);
     $user_base_info->sex = $user_base_info->sex ? '男' : '女';
     $this->assign('user', $user_base_info);
     //more info 带外键的
     $user_more_info = UserInfoAR::model()->findByPk($user_id);
     $this->assign('user_more', $user_more_info);
     $this->use_view();
     $this->display();
 }
예제 #5
0
 public function actionView()
 {
     $user = UserAR::model()->find('ID=:id', array(':id' => $_GET['ID']));
     $this->render('view', array('model' => $user));
 }
예제 #6
0
 /**
  * This is the default 'index' action that is invoked
  * when an action is not explicitly requested by users.
  *
  * This is the action to handle external exceptions.
  */
 public function actionIndex()
 {
     $user = UserAR::model()->find('ID=:id', array(':id' => Yii::app()->user->getId()));
     $this->render('index', array('model' => $user));
 }