Exemple #1
0
 /**
  * Logs in a user using the provided username and password.
  * @return boolean whether the user is logged in successfully
  */
 public function login($ip)
 {
     if ($this->validate()) {
         $user = $this->getUser();
         $logContent = array('options' => '登录', 'ip' => $ip);
         $resultLog = OperationLog::saveLog(json_encode($logContent), $user->id, OperationLog::TYPE_USER);
         if (!$resultLog['result']) {
             return false;
         }
         return Yii::$app->user->login($user, $this->rememberMe ? 60 : 0);
     }
     return false;
 }
Exemple #2
0
 /**
  * 验证注册邮箱
  */
 public function actionActivemail($token)
 {
     $userValidate = UserValidate::find()->where(['token' => $token])->one();
     if ($userValidate) {
         $user = User::find()->where(['id' => $userValidate->userid])->one();
         $transtion = Yii::$app->db->beginTransaction();
         try {
             $user->status = User::STATUS_DEF['active'];
             if (!$user->save()) {
                 $transtion->rollBack();
                 return "激活失败";
             }
             $resultLog = OperationLog::saveLog($user->username . "激活", $user->id, OperationLog::TYPE_USER);
             if (!$resultLog['result']) {
                 $transtion->rollBack();
                 return $resultLog['message'];
             }
             $transtion->commit();
             return "激活成功";
         } catch (Exception $e) {
             $transtion->rollBack();
             return "激活失败";
         }
     } else {
         return "激活失败";
     }
 }