예제 #1
0
 /**
  * 修改个人资料
  * @return mixed
  */
 public function actionProfile()
 {
     $model = UserInfo::findOne(['user_id' => Yii::$app->user->id]);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $this->flash('更新成功', 'success');
         return $this->refresh();
     }
     return $this->render('profile', ['model' => $model]);
 }
예제 #2
0
 /**
  * 登陆之后更新用户资料
  * @return bool
  */
 public function updateUserInfo()
 {
     $model = UserInfo::findOne(['user_id' => Yii::$app->user->getId()]);
     $model->login_count += 1;
     $model->prev_login_time = $model->last_login_time;
     $model->prev_login_ip = $model->last_login_ip;
     $model->last_login_time = time();
     $model->last_login_ip = Yii::$app->getRequest()->getUserIP();
     if ($model->save()) {
         return true;
     } else {
         return false;
     }
 }
예제 #3
0
파일: LoginForm.php 프로젝트: iiyii/getyii
 /**
  * 登陆之后更新用户资料
  * @return bool
  */
 public function updateUserInfo()
 {
     /** @var UserInfo $model */
     $model = UserInfo::findOne(['user_id' => Yii::$app->user->getId()]);
     $model->login_count += 1;
     $model->prev_login_time = $model->last_login_time;
     $model->prev_login_ip = $model->last_login_ip;
     $model->last_login_time = time();
     $model->last_login_ip = Yii::$app->getRequest()->getUserIP();
     if (!Yii::$app->session->isActive) {
         Yii::$app->session->open();
     }
     $model->session_id = Yii::$app->session->id;
     Yii::$app->session->close();
     if ($model->save()) {
         return true;
     } else {
         return false;
     }
 }
 /**
  * Finds the UserInfo model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return UserInfo the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = UserInfo::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }