Пример #1
0
 /**
  * Finds the User model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return User the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = User::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Пример #2
0
 /**
  * Logins user
  * @return string|\yii\web\Response
  */
 public function actionLogin()
 {
     $this->layout = 'login';
     if (!Yii::$app->user->isGuest) {
         return $this->goHome();
     }
     $model = new LoginForm();
     if ($model->load(Yii::$app->request->post()) && $model->login()) {
         $user = User::findOne(Yii::$app->user->id);
         $user->last_login_at = new Expression('NOW()');
         $user->save();
         return $this->goBack();
     } else {
         return $this->render('login', ['model' => $model]);
     }
 }