Skip to content

Commit 4a9c489

Browse files
fix translations and added password reset
1 parent 60017f0 commit 4a9c489

File tree

3 files changed

+37
-7
lines changed

3 files changed

+37
-7
lines changed

src/controllers/UserController.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,36 @@ public function actionDelete($id)
114114
return $this->redirect(['index']);
115115
}
116116

117+
/**
118+
* Requests password reset.
119+
*
120+
* @return mixed
121+
*/
122+
public function actionRequestPasswordReset()
123+
{
124+
// guest cannot reset password
125+
if (Yii::$app->user->isGuest) {
126+
return $this->goHome();
127+
}
128+
129+
$model = new PasswordResetRequestForm();
130+
131+
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
132+
if ($model->sendEmail()) {
133+
Yii::$app->session->setFlash('success', Module::t('Check your email for further action'));
134+
return $this->goHome();
135+
} else {
136+
Yii::$app->session->setFlash('error', Module::t('An error occurred while resetting your password. Contact the site administrator'));
137+
}
138+
}
139+
140+
$this->layout = "login";
141+
142+
return $this->render('passwordResetRequestForm', [
143+
'model' => $model,
144+
]);
145+
}
146+
117147
/**
118148
* Login action.
119149
*

src/messages/ru/user.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,7 @@
6161
'We recommend changing your password' => 'Рекомендуем сменить пароль',
6262

6363
'Registration in' => 'Регистрация в',
64-
'Password reset' => 'Сброс пароля'
64+
'Password reset' => 'Сброс пароля',
65+
'Check your email for further action' => 'Проверьте свою электронную почту для дальнейших действий',
66+
'An error occurred while resetting your password. Contact the site administrator' => 'Произошла ошибка при сбросе пароля. Обратитесь к администратору сайта',
6567
];

src/views/user/login.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
<?php
22

33
/* @var $this yii\web\View */
4-
/* @var $form yii\bootstrap\ActiveForm */
5-
/* @var $model app\models\LoginForm */
4+
/* @var $model ZakharovAndrew\user\models\LoginForm */
65

7-
use yii\bootstrap5\ActiveForm;
8-
use yii\bootstrap5\Html;
96
use ZakharovAndrew\user\Module;
107

118
$this->title = Module::t('Sign in');
129
$bootstrapVersion = Yii::$app->getModule('user')->bootstrapVersion;
1310
$classActiveForm = "\\yii\bootstrap".($bootstrapVersion==3 ? '' : $bootstrapVersion)."\\ActiveForm";
11+
$classHtml = "\\yii\bootstrap".($bootstrapVersion==3 ? '' : $bootstrapVersion)."\\Html";
1412

1513
$this->params['breadcrumbs'][] = $this->title;
1614
?>
@@ -127,12 +125,12 @@
127125
])->label(Module::t('Remember me')) ?>
128126

129127
<div class="mb-3 row mg10">
130-
<?= Html::a(Module::t('Forgot password?'), ['site/request-password-reset']) ?>
128+
<?= $classHtml::a(Module::t('Forgot password?'), ['user/user/request-password-reset']) ?>
131129
</div>
132130

133131
<div class="form-group">
134132
<div class="col-lg-12">
135-
<?= Html::submitButton(Module::t('Sign in'), ['class' => 'btn btn-primary col-md-12', 'name' => 'login-button']) ?>
133+
<?= $classHtml::submitButton(Module::t('Sign in'), ['class' => 'btn btn-primary col-md-12', 'name' => 'login-button']) ?>
136134
</div>
137135
</div>
138136

0 commit comments

Comments
 (0)