Пример #1
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     $this->mailer = Instance::ensure($this->mailer, 'im\\users\\components\\UserMailerInterface');
     Event::on(User::className(), User::EVENT_BEFORE_REGISTRATION, [$this, 'beforeUserRegistration']);
     Event::on(User::className(), User::EVENT_AFTER_REGISTRATION, [$this, 'afterUserRegistration']);
 }
Пример #2
0
 /**
  *
  * @param \FunctionalTester $I
  * @param \Codeception\Scenario $scenario
  */
 public function testUserRegistration($I, $scenario)
 {
     /** @var Module $module */
     $module = \Yii::$app->getModule('users');
     $I->wantTo('ensure that registration works');
     $registrationPage = RegistrationPage::openBy($I);
     $I->see('Sign up', 'h1');
     $I->amGoingTo('submit registration form with no data');
     $registrationPage->submit([]);
     $I->expectTo('see validations errors');
     $I->see('Username cannot be blank.', '.help-block');
     $I->see('E-mail cannot be blank.', '.help-block');
     $I->see('Password cannot be blank.', '.help-block');
     $I->see('Repeated password cannot be blank.', '.help-block');
     $I->amGoingTo('submit registration form with not correct email and repeated password');
     $registrationPage->submit(['username' => 'tester', 'email' => 'tester.email', 'password' => 'tester_password', 'password2' => 'tester_password2']);
     $I->expectTo('see that email address and repeated password is wrong');
     $I->dontSee('Username cannot be blank.', '.help-block');
     $I->dontSee('Password cannot be blank.', '.help-block');
     $I->dontSee('Repeated password cannot be blank.', '.help-block');
     $I->see('E-mail is not a valid email address.', '.help-block');
     $I->see('Repeated password must be repeated exactly.', '.help-block');
     $I->amGoingTo('submit registration form with correct data');
     $registrationPage->submit(['username' => 'tester', 'email' => '*****@*****.**', 'password' => 'tester_password', 'password2' => 'tester_password']);
     $I->expectTo('see that user is created');
     /** @var User $user */
     $user = $I->grabRecord(User::className(), ['username' => 'tester', 'email' => '*****@*****.**']);
     if ($module->registrationConfirmation) {
         /** @var Token $token */
         $token = $I->grabRecord(Token::className(), ['user_id' => $user->id, 'type' => Token::TYPE_REGISTRATION_CONFIRMATION]);
         $I->seeInEmailSubject('Registration confirmation');
         $I->seeInEmailRecipients('*****@*****.**');
         $I->seeInEmail($token->token);
     }
     $registrationPage = RegistrationPage::openBy($I);
     $I->amGoingTo('submit registration form with same data');
     $registrationPage->submit(['username' => 'tester', 'email' => '*****@*****.**', 'password' => 'tester_password', 'password2' => 'tester_password']);
     $I->expectTo('see that username and email address have already been taken');
     $I->see('Username "tester" has already been taken.', '.help-block');
     $I->see('E-mail "*****@*****.**" has already been taken.', '.help-block');
     //        $I->expectTo('see that user logged in');
     //        $I->seeLink('Logout (tester)');
 }
Пример #3
0
 /**
  * Creates new password recovery token and sends it to the user.
  *
  * @param User $user user object
  * @return bool whether the recovery information was sent.
  */
 public function sendRecoveryToken(User $user)
 {
     /** @var Token $tokenClass */
     $tokenClass = $this->module->tokenModel;
     $expireTime = $this->module->passwordRecoveryTokenExpiration;
     $expireTime = $expireTime !== null ? (new DateTime())->modify('+' . $expireTime) : null;
     $token = $tokenClass::generate($user->getId(), $tokenClass::TYPE_PASSWORD_RECOVERY, $expireTime);
     return $this->mailer->sendPasswordRecoveryEmail($user, $token);
 }
Пример #4
0
 /**
  * This method is called after each
  * @param \Codeception\Event\TestEvent $event
  */
 public function _after($event)
 {
     User::deleteAll(['email' => '*****@*****.**', 'username' => 'tester']);
 }
Пример #5
0
 /**
  * @return ActiveQuery
  */
 public function getUser()
 {
     return $this->hasOne(User::className(), ['id' => 'user_id'])->inverseOf('profile');
 }