I stumbled upon a simple post with the implementation of a simple admin . yii2 installed advanced. I did everything as described, but the problems did not pass by. At the exit: if you check the status by 10 (STATUS_ACTIVE) - login is fine in bacend, if you change it to 20 (STATUS_ADMIN) - wrong login or password! My code: commons \ modelsUser.php
public function rules() { return [ ['status', 'default', 'value' => self::STATUS_ADMIN], ['status', 'in', 'range' => [self::STATUS_ACTIVE, self::STATUS_DELETED, self::STATUS_ADMIN]], ]; } public static function isUserAdmin($username) { return static::findOne(['username' => $username, 'status' => self::STATUS_ACTIVE]); } common \ models \ LoginForm.php
public function loginAdmin() { if ($this->validate() && User::isUserAdmin($this->username)) { return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 30 : 0); } else { return false; } } backend \ controllers \ SiteController.php
public function actionLogin() { if (!Yii::$app->user->isGuest) { return $this->goHome(); } $model = new LoginForm(); if ($model->load(Yii::$app->request->post()) && $model->loginAdmin()) { return $this->goBack(); } else { return $this->render('login', [ 'model' => $model, ]); } }
status = 10- Blacknife