예제 #1
0
 /**
  * The login form.
  *
  * @return string|\yii\web\Response
  * @throws \yii\base\InvalidConfigException
  */
 public function actionLogin()
 {
     // Before filled login form.
     if (!isset(Yii::$app->request->post()['LoginForm']['username'])) {
         return $this->render('login', ['model' => new LoginForm()]);
     }
     $identity = User::findByUsername([Yii::$app->request->post()['LoginForm']['username']]);
     // User not found by username.
     if ($identity == null) {
         // Login error.
         Yii::$app->session->setFlash('error', 'Wrong username. Please check.');
         return $this->render('login', ['model' => new LoginForm()]);
     }
     $inserted_password = Yii::$app->request->post()['LoginForm']['password'];
     // Successful login.
     if (Yii::$app->security->validatePassword($inserted_password, $identity->password_hash)) {
         Yii::$app->user->login($identity);
         PasswordController::teamSecretCheck();
         return $this->redirect('/');
     } else {
         // Login error.
         Yii::$app->session->setFlash('error', 'Wrong password. Please check.');
         return $this->render('login', ['model' => new LoginForm()]);
     }
 }
예제 #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = User::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, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'username', $this->username])->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', 'email', $this->email]);
     return $dataProvider;
 }
예제 #3
0
 public static function removeAllAuthAssignments($id)
 {
     // Remove the permission itself.
     $permission = \Yii::$app->authManager->getPermission('password-id-' . $id);
     if ($permission !== null) {
         $all_users = User::find()->all();
         foreach ($all_users as $user) {
             UserController::removePermissionFromUser($user->id, 'password-id-' . $id);
         }
         \Yii::$app->authManager->remove($permission);
     }
 }
예제 #4
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.');
     }
 }
예제 #5
0
 /**
  * @inheritdoc
  */
 public static function findIdentity($id)
 {
     return User::findOne(['id' => $id]);
 }