Skip to content

Commit d668f81

Browse files
fixed password reset
1 parent f8e56d0 commit d668f81

File tree

6 files changed

+128
-12
lines changed

6 files changed

+128
-12
lines changed

src/controllers/UserController.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
use ZakharovAndrew\user\models\UserSearch;
88
use ZakharovAndrew\user\controllers\ParentController;
99
use yii\web\NotFoundHttpException;
10+
use yii\web\BadRequestHttpException;
11+
use yii\base\InvalidParamException;
1012
use ZakharovAndrew\user\Module;
1113
use ZakharovAndrew\user\models\ResetPasswordForm;
1214
use ZakharovAndrew\user\models\PasswordResetRequestForm;
@@ -19,7 +21,7 @@ class UserController extends ParentController
1921
{
2022
public $controller_id = 1001;
2123

22-
public $full_access_actions = ['login', 'logout'];
24+
public $full_access_actions = ['login', 'logout', 'request-password-reset', 'reset-password'];
2325

2426
/**
2527
* Lists all User models.
@@ -111,8 +113,8 @@ public function actionDelete($id)
111113
*/
112114
public function actionRequestPasswordReset()
113115
{
114-
// guest cannot reset password
115-
if (Yii::$app->user->isGuest) {
116+
// not guest cannot reset password
117+
if (!Yii::$app->user->isGuest) {
116118
return $this->goHome();
117119
}
118120

src/mail/passwordResetToken-html.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
<?php
22

3-
use Yii;
43
use yii\helpers\Html;
54
use ZakharovAndrew\user\Module;
65

76

8-
$reset_link = Yii::$app->urlManager->createAbsoluteUrl(['/user/user/reset-password', 'token' => $user->password_reset_token]);
7+
$reset_link = \Yii::$app->urlManager->createAbsoluteUrl(['/user/user/reset-password', 'token' => $user->password_reset_token]);
98

109
?>
1110

src/messages/ru/user.php

+2
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,6 @@
8181
'Reset password' => 'Сброс пароля',
8282
'Reset password for' => 'Сброс пароля для',
8383
'To reset your password, follow the link' => 'Для сброса своего пароля перейдите по ссылке',
84+
'Please enter your username and email to receive a link to reset your password' => 'Пожалуйста, введите свой логин и Email, что бы получить ссылку для сброса пароля',
85+
'Please enter a new password' => 'Пожалуйста, введите новый пароль',
8486
];

src/views/layouts/login.php

+10-6
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,19 @@
2323
<?php $this->beginBody() ?>
2424

2525
<?php if (Yii::$app->session->hasFlash('success')): ?>
26-
<div class="alert alert-success alert-dismissible" role="alert">
27-
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
28-
<?php echo Yii::$app->session->getFlash('success'); ?>
26+
<div class="container">
27+
<div class="alert alert-success alert-dismissible" role="alert">
28+
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
29+
<?php echo Yii::$app->session->getFlash('success'); ?>
30+
</div>
2931
</div>
3032
<?php endif; ?>
3133
<?php if (Yii::$app->session->hasFlash('error')): ?>
32-
<div class="alert alert-error alert-dismissible" role="alert">
33-
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
34-
<?php echo Yii::$app->session->getFlash('error'); ?>
34+
<div class="container">
35+
<div class="alert alert-error alert-dismissible" role="alert">
36+
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
37+
<?php echo Yii::$app->session->getFlash('error'); ?>
38+
</div>
3539
</div>
3640
<?php endif; ?>
3741

src/views/user/login.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@
9595
h4 {
9696
margin-bottom: 5px;
9797
}
98+
.alert {
99+
max-width: 459px;
100+
margin: 0 auto;
101+
margin-top: 15px;
102+
}
98103
</style>
99104
<div class="content">
100105
<div class="site-login center">
@@ -125,7 +130,7 @@
125130
])->label(Module::t('Remember me')) ?>
126131

127132
<div class="mb-3 row mg10">
128-
<?= $classHtml::a(Module::t('Forgot password?'), ['user/user/request-password-reset']) ?>
133+
<?= $classHtml::a(Module::t('Forgot password?'), ['/user/user/request-password-reset']) ?>
129134
</div>
130135

131136
<div class="form-group">

src/views/user/resetPasswordForm.php

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php
2+
3+
use yii\helpers\Html;
4+
use yii\helpers\Url;
5+
use ZakharovAndrew\user\Module;
6+
7+
$this->title = Module::t('Reset password');
8+
$bootstrapVersion = Yii::$app->getModule('user')->bootstrapVersion;
9+
$classActiveForm = "\\yii\bootstrap".($bootstrapVersion==3 ? '' : $bootstrapVersion)."\\ActiveForm";
10+
$classHtml = "\\yii\bootstrap".($bootstrapVersion==3 ? '' : $bootstrapVersion)."\\Html";
11+
12+
$this->params['breadcrumbs'][] = $this->title;
13+
?>
14+
<style>
15+
.form-login a {
16+
color: #7366ff;text-align: right;
17+
}
18+
h1 {text-align: center;}
19+
.form-login {
20+
width: 450px;
21+
padding: 40px;
22+
border-radius: 10px;
23+
box-shadow: 0 0 37px rgba(8, 21, 66, 0.05);
24+
margin: 0 auto;
25+
background-color: #fff;
26+
}
27+
.form-login-header {
28+
background-color: #03a9f4;
29+
color: #fff;
30+
padding: 13px;
31+
font-size: 18px;
32+
font-family: Verdana;
33+
font-weight: bold;
34+
margin-bottom: 22px;
35+
border-top-right-radius: 3px;
36+
border-top-left-radius: 3px;
37+
}
38+
39+
.site-reset-password .form-control {
40+
background-color: #f3f3ff;
41+
transition: all 0.3s ease;
42+
border-color: #efefef;
43+
font-size: 14px;
44+
color: #898989;
45+
padding: 12px 10px;
46+
-webkit-box-shadow: none;
47+
box-shadow: none;
48+
}
49+
body {
50+
background: #f8f9fe;
51+
background-size: cover;
52+
}
53+
h1 {
54+
margin-bottom: 30px;
55+
}
56+
.field-loginform-rememberme {
57+
float:left;
58+
}
59+
.content {
60+
justify-content: center;
61+
align-items: center;
62+
display: flex;
63+
padding:11%;
64+
}
65+
.btn-primary {
66+
text-transform: uppercase;
67+
background-color: #7366ff;
68+
border-color: #7366ff;
69+
}
70+
.btn-primary:hover {
71+
background-color: #7366ff;
72+
border-color: #7366ff;
73+
}
74+
.form-login .col-form-label {
75+
font-size: 16px !important;
76+
letter-spacing: 0.4px;
77+
78+
padding-top: 1px !important;
79+
padding-bottom: 4px !important;
80+
81+
padding-top: calc(0.375rem + 1px);
82+
padding-bottom: calc(0.375rem + 1px);
83+
margin-bottom: 0;
84+
font-size: inherit;
85+
line-height: 1.5;
86+
}
87+
h2 {
88+
margin-bottom: 20px;
89+
}
90+
</style>
91+
<div class="content">
92+
<div class="site-reset-password center">
93+
<div class="form-login">
94+
<h2><?= Module::t('Please enter a new password') ?></h2>
95+
<?php $form = $classActiveForm::begin(['id' => 'reset-password-form', 'action' => Url::to(['/user/user/reset-password', 'token' => $token]), 'method' => 'POST']); ?>
96+
<?= $form->field($model, 'password')->passwordInput(['autofocus' => true])->label('Пароль') ?>
97+
<div class="form-group">
98+
<?= $classHtml::submitButton(Module::t('Save'), ['class' => 'btn btn-primary']) ?>
99+
</div>
100+
<?php $classActiveForm::end(); ?>
101+
102+
</div>
103+
</div>
104+
</div>

0 commit comments

Comments
 (0)