Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor RecoveryController to use own view; makes it easier to override messages #900

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 8 additions & 17 deletions controllers/RecoveryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,7 @@ public function actionRequest()

if ($model->load(\Yii::$app->request->post()) && $model->sendRecoveryMessage()) {
$this->trigger(self::EVENT_AFTER_REQUEST, $event);
return $this->render('/message', [
'title' => \Yii::t('user', 'Recovery message sent'),
'module' => $this->module,
]);
return $this->render('request_sent');
}

return $this->render('request', [
Expand Down Expand Up @@ -153,15 +150,12 @@ public function actionReset($id, $code)
$this->trigger(self::EVENT_BEFORE_TOKEN_VALIDATE, $event);

if ($token === null || $token->isExpired || $token->user === null) {
$this->trigger(self::EVENT_AFTER_TOKEN_VALIDATE, $event);
\Yii::$app->session->setFlash(
'danger',
\Yii::t('user', 'Recovery link is invalid or expired. Please try requesting a new one.')
);
return $this->render('/message', [
'title' => \Yii::t('user', 'Invalid or expired link'),
'module' => $this->module,
]);
$this->trigger(self::EVENT_AFTER_TOKEN_VALIDATE, $event);
\Yii::$app->session->setFlash(
'danger',
\Yii::t('user', 'Recovery link is invalid or expired. Please try requesting a new one.')
);
return $this->render('link_invalid');
}

/** @var RecoveryForm $model */
Expand All @@ -176,10 +170,7 @@ public function actionReset($id, $code)

if ($model->load(\Yii::$app->getRequest()->post()) && $model->resetPassword($token)) {
$this->trigger(self::EVENT_AFTER_RESET, $event);
return $this->render('/message', [
'title' => \Yii::t('user', 'Password has been changed'),
'module' => $this->module,
]);
return $this->render('password_change_success');
}

return $this->render('reset', [
Expand Down
5 changes: 1 addition & 4 deletions controllers/RegistrationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,7 @@ public function actionRegister()
if ($model->load(\Yii::$app->request->post()) && $model->register()) {
$this->trigger(self::EVENT_AFTER_REGISTER, $event);

return $this->render('/message', [
'title' => \Yii::t('user', 'Your account has been created'),
'module' => $this->module,
]);
return $this->render('register_success');
}

return $this->render('register', [
Expand Down
4 changes: 3 additions & 1 deletion messages/de/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@
'Account details' => 'Kontodetails',
'Account details have been updated' => 'Kontodetails wurden gespeichert',
'Account settings' => 'Kontoeinstellungen',
'An email has been sent with instructions for resetting your password' => 'Eine E-Mail mit weiteren Instruktionen, um Ihr Passwort zurück zu setzen, wurde gesendet.',
'An email has been sent with instructions for resetting your password' => 'Wir haben Ihnen eine E-Mail geschickt, um ein neues Passwort vergeben zu können',
'Please follow the instructions to change your password' => 'Bitte öffnen Sie Ihr E-Mail-Postfach und folgen Sie der beschriebenen Vorgehensweise, um Ihr Passwort zurückzusetzen',
'An error occurred and your password has not been changed. Please try again later.' => 'Es ist ein Problem aufgetreten. Ihr Passwort wurde nicht verändert. Bitte versuchen Sie es später noch einmal.',
'An error occurred processing your request' => 'Ein Fehler ist aufgetreten',
'Assignments' => 'Zuordnungen',
'Are you sure you want to switch to this user for the rest of this Session?' => 'Sind Sie sicher, dass sie für den Rest der Sitzung zu diesem Benutzer wechseln möchten?',
'Awesome, almost there. Now you need to click the confirmation link sent to your new email address' => 'Fast geschafft. Nun müssen Sie nur noch den Aktivierungslink besuchen, der an ihre neue E-Mail Adresse gesendet wurde',
'Awesome, almost there. Now you need to click the confirmation link sent to your old email address' => 'Fast geschafft. Nun müssen Sie nur noch den Aktivierungslink besuchen, der an ihre alte E-Mail Adresse gesendet wurde',
'Back to Login' => 'Zurück zur Anmeldung',
'Become this user' => 'Zu diesem Nutzer wechseln',
'Complete password reset on {0}' => 'Passwort komplett zurücksetzen auf {0}',
'Confirm account on {0}' => 'Passwort bestätigen auf {0}',
Expand Down
7 changes: 7 additions & 0 deletions models/RecoveryForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ class RecoveryForm extends Model
*/
public $password;

/**
* @var string
*/
public $password_confirmation;

/**
* @var Mailer
*/
Expand Down Expand Up @@ -65,6 +70,7 @@ public function attributeLabels()
return [
'email' => \Yii::t('user', 'Email'),
'password' => \Yii::t('user', 'Password'),
'password_confirmation' => \Yii::t('user', 'Password confirmation'),
];
}

Expand All @@ -89,6 +95,7 @@ public function rules()
'emailRequired' => ['email', 'required'],
'emailPattern' => ['email', 'email'],
'passwordRequired' => ['password', 'required'],
'newPasswordConfirmation' => ['password_confirmation', 'compare', 'compareAttribute' => 'password'],
'passwordLength' => ['password', 'string', 'max' => 72, 'min' => 6],
];
}
Expand Down
1 change: 1 addition & 0 deletions views/recovery/password_change_success.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?= \Yii::t('user', 'Password has been changed'); ?>
6 changes: 6 additions & 0 deletions views/recovery/recovery_token_invalid.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php use yii\helpers\Html; ?>

<?= \Yii::t('user', 'Invalid or expired link'); ?>

<p> <?= Html::a(Yii::t('user', 'Back to Login'), ['//user/security/login'], ['class' => 'btn btn-primary']); ?> </p>

7 changes: 7 additions & 0 deletions views/recovery/request_sent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php use yii\helpers\Html; ?>

<p> <?= \Yii::t('user', 'An email has been sent with instructions for resetting your password'); ?>. </p>

<p> <?= \Yii::t('user', 'Please follow the instructions to change your password'); ?>. </p>

<p> <?= Html::a(Yii::t('user', 'Back to Login'), ['//user/security/login'], ['class' => 'btn btn-primary']); ?> </p>
1 change: 1 addition & 0 deletions views/registration/register_success.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php echo \Yii::t('user', 'Your account has been created'); ?>.