/** * @dataProvider invalidDataProvider */ public function testInvalid($scenario, $attributes, $errors) { $form = new models\LoginForm($scenario); $form->webUser = \Yii::$app->user; $form->setAttributes($attributes); $this->assertFalse($form->validate()); $this->assertEquals($errors, $form->getErrors()); }
/** * @param LoginForm $localLogin * @param AuthForm $remoteLogin * @param boolean|UserIdentityInterface $localIdentity if not false, try to authenticate this identity instead * @return LoginForm validated $localLogin */ protected function performLocalLogin(LoginForm $localLogin, AuthForm $remoteLogin, $localIdentity = false) { if (!isset($_POST['LoginForm'])) { return $localLogin; } if (is_object($localIdentity)) { // force to authorize against the $localIdentity $attributes = $localIdentity->getIdentityAttributes(); if (isset($attributes['username'])) { $_POST['LoginForm']['username'] = $attributes['username']; } } $localLogin->setAttributes($_POST['LoginForm']); if ($localLogin->validate() && $localLogin->login()) { // don't forget to associate the new profile with remote provider if (!$remoteLogin->associate($localLogin->getIdentity()->getId())) { Yii::$app->session->setFlash('error', Yii::t('usr', 'Failed to associate current user with {provider}.', ['provider' => $remoteLogin->provider])); return $this->redirect(['login', 'provider' => $remoteLogin->provider]); } $this->afterLogin(); } return $localLogin; }