コード例 #1
0
 public function actionLogin()
 {
     if (!\Yii::$app->user->isGuest) {
         return $this->goHome();
     }
     //        $model = new LoginForm();
     $model = new AuthUser();
     if ($model->load(Yii::$app->request->post()) && $model->login()) {
         //            echo "<pre>" . print_r($model,1) . "</pre>";
         //            echo 'login true';
         //die('login true');
         return $this->goBack();
     }
     return $this->render('login', ['model' => $model]);
 }
コード例 #2
0
ファイル: LoginForm.php プロジェクト: SergAHell/yii2_etalon
 /**
  * Validates the password.
  * This method serves as the inline validation for password.
  *
  * @param string $attribute the attribute currently being validated
  * @param array $params the additional name-value pairs given in the rule
  * @return bool|void
  */
 public function validatePassword($attribute, $params)
 {
     if (!$this->hasErrors()) {
         $user = AuthUser::findByUsername($this->username);
         if (!$user || !$user->validatePassword($this->password)) {
             $this->addError($attribute, 'Incorrect username or password.');
         }
     }
 }
コード例 #3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = AuthUser::find();
     $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;
     }
     $query->andFilterWhere(['id' => $this->id, 'is_blocked' => $this->is_blocked]);
     $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'auth_key', $this->auth_key])->andFilterWhere(['like', 'password_hash', $this->password_hash])->andFilterWhere(['like', 'password_reset_token', $this->password_reset_token])->andFilterWhere(['like', 'role', $this->role]);
     return $dataProvider;
 }
コード例 #4
0
 /**
  * Creates a new AuthUser model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     /** @var AuthUser $model */
     $model = new AuthUser();
     return $model->load(Yii::$app->request->post()) && $model->validate() && $this->saveAvatar($model) && $model->save() ? $this->redirect(['index']) : $this->render('create', ['model' => $model]);
 }