/** * @dataProvider invalidDataProvider */ public function testInvalid($scenario, $attributes, $errors) { $form = new models\ProfileForm(); $form->webUser = \Yii::$app->user; $form->setScenario($scenario); $form->setAttributes($attributes); $this->assertFalse($form->validate()); $this->assertEquals($errors, $form->getErrors()); }
protected function registerLocalProfile(ProfileForm $localProfile, AuthForm $remoteLogin, $localIdentity = false) { if (!isset($_POST['ProfileForm']) && $localIdentity === false) { $localProfile->setAttributes($remoteLogin->getAuthClient()->getUserAttributes()); $localProfile->validate(); return $localProfile; } if ($localIdentity !== false) { $localProfile->setAttributes($remoteLogin->getAuthClient()->getUserAttributes()); } if (isset($_POST['ProfileForm']) && is_array($_POST['ProfileForm'])) { $localProfile->setAttributes($_POST['ProfileForm']); } if (!$localProfile->validate()) { return $localProfile; } $trx = Yii::$app->db->beginTransaction(); if (!$localProfile->save($this->module->requireVerifiedEmail)) { $trx->rollback(); Yii::$app->session->setFlash('error', Yii::t('usr', 'Failed to register a new user.') . ' ' . Yii::t('usr', 'Try again or contact the site administrator.')); return $localProfile; } $trx->commit(); if ($this->module->requireVerifiedEmail) { if ($this->sendEmail($localProfile, 'verify')) { Yii::$app->session->setFlash('success', Yii::t('usr', 'An email containing further instructions has been sent to provided email address.')); } else { Yii::$app->session->setFlash('error', Yii::t('usr', 'Failed to send an email.') . ' ' . Yii::t('usr', 'Try again or contact the site administrator.')); } } // don't forget to associate the new profile with remote provider if (!$remoteLogin->associate($localProfile->getIdentity()->getId())) { Yii::$app->session->setFlash('error', Yii::t('usr', 'Failed to associate current user with {provider}.', ['provider' => $remoteLogin->provider])); return $this->redirect('login'); } if ($localProfile->getIdentity()->isActive()) { // don't use the $localProfile->login() method because there is no password set so we can't authenticate this identity if (Yii::$app->user->login($localProfile->getIdentity(), 0)) { $this->afterLogin(); } else { Yii::$app->session->setFlash('error', Yii::t('usr', 'Failed to log in.') . ' ' . Yii::t('usr', 'Try again or contact the site administrator.')); } } else { if (!Yii::$app->session->hasFlash('success')) { Yii::$app->session->setFlash('success', Yii::t('usr', 'Please wait for the account to be activated. A notification will be send to provided email address.')); } return $this->redirect(['login', 'provider' => $remoteLogin->provider]); } return $localProfile; }