Browse Source

Traduction et test du module de récupération de mot de passe

master
keun 8 years ago
parent
commit
9afec92146
8 changed files with 34 additions and 21 deletions
  1. +5
    -2
      common/mail/passwordResetToken-html.php
  2. +5
    -2
      common/mail/passwordResetToken-text.php
  3. +0
    -1
      common/models/User.php
  4. +2
    -2
      frontend/controllers/SiteController.php
  5. +7
    -6
      frontend/models/PasswordResetRequestForm.php
  6. +7
    -0
      frontend/models/ResetPasswordForm.php
  7. +3
    -3
      frontend/views/site/requestPasswordResetToken.php
  8. +5
    -5
      frontend/views/site/resetPassword.php

+ 5
- 2
common/mail/passwordResetToken-html.php View File

@@ -7,9 +7,12 @@ use yii\helpers\Html;
$resetLink = Yii::$app->urlManager->createAbsoluteUrl(['site/reset-password', 'token' => $user->password_reset_token]);
?>
<div class="password-reset">
<p>Hello <?= Html::encode($user->username) ?>,</p>
<p>Bonjour <?= Html::encode($user->prenom) ?>,</p>

<p>Follow the link below to reset your password:</p>
<p>Suivez le lien suivant pour réinitialiser votre mot de passe :</p>

<p><?= Html::a(Html::encode($resetLink), $resetLink) ?></p>
<p>À bientôt,<br />
La boîte à pain</p>
</div>

+ 5
- 2
common/mail/passwordResetToken-text.php View File

@@ -5,8 +5,11 @@

$resetLink = Yii::$app->urlManager->createAbsoluteUrl(['site/reset-password', 'token' => $user->password_reset_token]);
?>
Hello <?= $user->username ?>,
Bonjour <?= $user->prenom ?>,

Follow the link below to reset your password:
Suivez le lien suivant pour réinitialiser votre mot de passe :

<?= $resetLink ?>

À bientôt,
La boîte à pain

+ 0
- 1
common/models/User.php View File

@@ -118,7 +118,6 @@ class User extends ActiveRecord implements IdentityInterface

return static::findOne([
'password_reset_token' => $token,
'status' => self::STATUS_ACTIVE,
]);
}


+ 2
- 2
frontend/controllers/SiteController.php View File

@@ -209,7 +209,7 @@ class SiteController extends Controller
$model = new PasswordResetRequestForm();
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
if ($model->sendEmail()) {
Yii::$app->getSession()->setFlash('success', 'Check your email for further instructions.');
Yii::$app->getSession()->setFlash('success', 'Un lien vous permettant de réinitialiser votre mot de passe vient d\'être envoyé sur votre boîte mail.');

return $this->goHome();
} else {
@@ -231,7 +231,7 @@ class SiteController extends Controller
}

if ($model->load(Yii::$app->request->post()) && $model->validate() && $model->resetPassword()) {
Yii::$app->getSession()->setFlash('success', 'New password was saved.');
Yii::$app->getSession()->setFlash('success', 'Votre nouveau mot de passe vient d\'être sauvegardé.');

return $this->goHome();
}

+ 7
- 6
frontend/models/PasswordResetRequestForm.php View File

@@ -3,6 +3,7 @@ namespace frontend\models;

use common\models\User;
use yii\base\Model;
use yii ;

/**
* Password reset request form
@@ -22,7 +23,6 @@ class PasswordResetRequestForm extends Model
['email', 'email'],
['email', 'exist',
'targetClass' => '\common\models\User',
'filter' => ['status' => User::STATUS_ACTIVE],
'message' => 'There is no user with such email.'
],
];
@@ -37,7 +37,6 @@ class PasswordResetRequestForm extends Model
{
/* @var $user User */
$user = User::findOne([
'status' => User::STATUS_ACTIVE,
'email' => $this->email,
]);

@@ -46,11 +45,13 @@ class PasswordResetRequestForm extends Model
$user->generatePasswordResetToken();
}

if ($user->save()) {
return \Yii::$app->mailer->compose(['html' => 'passwordResetToken-html', 'text' => 'passwordResetToken-text'], ['user' => $user])
->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot'])
if ($user->save())
{
return Yii::$app->mailer->compose(['html' => 'passwordResetToken-html', 'text' => 'passwordResetToken-text'], ['user' => $user])
->setFrom(['contact@laboiteapain.net' => 'La boîte à pain'])
->setTo($this->email)
->setSubject('Password reset for ' . \Yii::$app->name)
->setSubject('[La boîte à pain] Mot de passe oublié')
->send();
}
}

+ 7
- 0
frontend/models/ResetPasswordForm.php View File

@@ -62,4 +62,11 @@ class ResetPasswordForm extends Model

return $user->save();
}
public function attributeLabels()
{
return [
'password' => 'Mot de passe',
];
}
}

+ 3
- 3
frontend/views/site/requestPasswordResetToken.php View File

@@ -6,20 +6,20 @@ use yii\bootstrap\ActiveForm;
/* @var $form yii\bootstrap\ActiveForm */
/* @var $model \frontend\models\PasswordResetRequestForm */

$this->title = 'Request password reset';
$this->title = 'Mot de passe oublié';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="site-request-password-reset">
<h1><?= Html::encode($this->title) ?></h1>

<p>Please fill out your email. A link to reset password will be sent there.</p>
<p>Renseignez votre adresse email. Nous vous transmettrons un lien vous permettant de réinitialiser votre mot de passe.</p>

<div class="row">
<div class="col-lg-5">
<?php $form = ActiveForm::begin(['id' => 'request-password-reset-form']); ?>
<?= $form->field($model, 'email') ?>
<div class="form-group">
<?= Html::submitButton('Send', ['class' => 'btn btn-primary']) ?>
<?= Html::submitButton('Envoyer', ['class' => 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

+ 5
- 5
frontend/views/site/resetPassword.php View File

@@ -6,20 +6,20 @@ use yii\bootstrap\ActiveForm;
/* @var $form yii\bootstrap\ActiveForm */
/* @var $model \frontend\models\ResetPasswordForm */

$this->title = 'Reset password';
$this->title = 'Nouveau mot de passe';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="site-reset-password">
<h1><?= Html::encode($this->title) ?></h1>

<p>Please choose your new password:</p>
<p>Renseignez ci-dessous votre nouveau mot de passe.</p>
<div class="row">
<div class="col-lg-5">
<?php $form = ActiveForm::begin(['id' => 'reset-password-form']); ?>
<?= $form->field($model, 'password')->passwordInput() ?>
<?= $form->field($model, 'password')->passwordInput()->label('Mot de passe') ?>
<div class="form-group">
<?= Html::submitButton('Save', ['class' => 'btn btn-primary']) ?>
<?= Html::submitButton('Valider', ['class' => 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

Loading…
Cancel
Save