public function testResetPassword(FunctionalTester $I) { $user = Commons::createUnconfirmedUser(); $token = Commons::createTokenForUser($user->id); $I->amGoingTo('test that the reset password functionality is working properly'); $I->amGoingTo('to confirm the email for the user'); PasswordResetPage::openBy($I, ['code' => $token->code]); $I->expectTo('see successful reset'); $I->dontSeeRecord(Token::className(), ['user_id' => $user->id]); $I->expectTo('see the user is sent to the change password form'); $I->see('Change password'); $I->seeElement('#changepasswordform-newpassword'); $I->seeElement('#changepasswordform-newpasswordrepeat'); }
public static function createTokenForUser($userId, $type = Token::TYPE_RECOVERY) { $token = Yii::createObject(['class' => Token::className(), 'user_id' => $userId, 'type' => $type]); $token->save(false); return $token; }
/** * Performs the actual user registration by validation the data and persisting the user. * * @param UserModel $model * @return bool */ public function register(UserModel $model) { Yii::info("Registering user [{$model->email}]", __CLASS__); if ($this->enableConfirmation == false) { $model->confirmed_on = time(); } $event = Event::createUserEvent($model); $this->trigger(self::EVENT_BEFORE_REGISTER, $event); Yii::info("Saving user [{$model->email}] to the database", __CLASS__); if ($model->save()) { Yii::info("User [{$model->email}] successfuly registered!", __CLASS__); // Raise event that the user is persisted $this->trigger(self::EVENT_AFTER_REGISTER, $event); //Add confirmation token(if enabled) and notify user if ($this->enableConfirmation) { Yii::info("Creating token of user [{$model->email}]", __CLASS__); $token = Yii::createObject(['class' => Token::className(), 'type' => Token::TYPE_CONFIRMATION]); $token->link('user', $model); Yii::info("Sending confirmation email to [{$model->email}]", __CLASS__); $this->getNotificator()->sendConfirmationMessage($model, $token); } return true; } Yii::error("An error occurred while registering user [{$model->email}][{$model->register_ip}].\n" . VarDumper::dumpAsString($model->getErrors()), __CLASS__); return false; }
public function getTokens() { return $this->hasMany(Token::className(), ['user_id' => 'id']); }