Example #1
0
 /**
  * 保存日志
  * @param $content 日志内容
  * @param $targetid 所属对象id
  * @param $targetType 所属对象类型
  * @param $creatorid 创建人id
  * @param $remark 备注
  */
 public function saveLog($content, $targetId, $targetType, $remark = null)
 {
     $operationLogModel = new OperationLog();
     $operationLogModel->targetid = $targetId;
     $operationLogModel->content = $content;
     if ($remark != null) {
         $operationLogModel->remark = $remark;
     }
     $operationLogModel->target_type = $targetType;
     $operationLogModel->creatorid = 0;
     // 暂时未0
     if (!$operationLogModel->save()) {
         $data['result'] = false;
         $data['message'] = $careerError;
         return $data;
     }
     $data['result'] = true;
     return $data;
 }
Example #2
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;
 }
Example #3
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 "激活失败";
     }
 }