Exemplo n.º 1
0
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = User::findByEmail($this->email);
     }
     return $this->_user;
 }
Exemplo n.º 2
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.');
     }
 }
Exemplo n.º 3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = User::find();
     // add conditions that should always apply here
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id, 'is_root' => $this->is_root, 'created_at' => $this->created_at, 'last_login_at' => $this->last_login_at]);
     $query->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'password_hash', $this->password_hash])->andFilterWhere(['like', 'auth_key', $this->auth_key]);
     return $dataProvider;
 }
Exemplo n.º 4
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]);
     }
 }
 public function down()
 {
     $this->dropTable(User::tableName());
 }