public function testLoginCorrect() { $model = new LoginForm(['username' => 'naumov.vil', 'password' => 'password_0']); $this->specify('user should be able to login with correct credentials', function () use($model) { expect('model should login user', $model->login())->true(); expect('error message should not be set', $model->errors)->hasntKey('password'); expect('user should be logged in', Yii::$app->user->isGuest)->false(); }); }
/** * @inheritdoc */ public function run() { if (!\Yii::$app->user->isGuest) { return $this->controller->goHome(); } $model = \Yii::createObject(LoginForm::className()); if ($model->load(\Yii::$app->request->post()) && $model->login()) { if ($this->returnUrl) { return $this->controller->redirect($this->returnUrl); } else { return $this->controller->goBack(); } } else { return $this->controller->render($this->tpl, ['model' => $model]); } }