Skip to content

Commit 910a25d

Browse files
committed
Use email address for reset password form
1 parent ef57326 commit 910a25d

File tree

5 files changed

+20
-20
lines changed

5 files changed

+20
-20
lines changed

src/controllers/User/ResetPassword.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ public function &run( Router &$router, View &$view, array &$args ) {
4040
$model->error = null;
4141
$model->csrf_id = mt_rand();
4242
$model->csrf_token = CSRF::generate( $model->csrf_id );
43+
$model->email = isset( $data[ 'email' ]) ? $data[ 'email' ] : null;
4344
$model->pw1 = isset( $data[ 'pw1' ]) ? $data[ 'pw1' ] : null;
4445
$model->pw2 = isset( $data[ 'pw2' ]) ? $data[ 'pw2' ] : null;
4546
$model->token = isset( $data[ 't' ]) ? $data[ 't' ] : null;
4647
$model->user = null;
47-
$model->username = isset( $data[ 'username' ]) ? $data[ 'username' ] : null;
4848

4949
if ( $router->getRequestMethod() == 'POST' ) {
5050
$ret = $this->doPasswordReset( $model, $data );
@@ -55,8 +55,8 @@ public function &run( Router &$router, View &$view, array &$args ) {
5555
getenv( 'REMOTE_ADDR' ),
5656
json_encode([
5757
'error' => $model->error,
58+
'email' => $model->email,
5859
'user' => ( $model->user ? true : false ),
59-
'username' => $model->username,
6060
])
6161
);
6262
}
@@ -87,13 +87,13 @@ protected function doPasswordReset( UserResetPasswordModel &$model, &$data ) {
8787
}
8888
CSRF::invalidate( $csrf_id );
8989

90-
if ( empty( $model->username )) {
91-
$model->error = 'EMPTY_USERNAME';
90+
if ( empty( $model->email )) {
91+
$model->error = 'EMPTY_EMAIL';
9292
return self::RET_FAILURE;
9393
}
9494

9595
try {
96-
$model->user = new User( User::findIdByUsername( $model->username ));
96+
$model->user = new User( User::findIdByEmail( $model->email ));
9797
} catch ( UserNotFoundException $e ) {
9898
$model->user = null;
9999
} catch ( InvalidArgumentException $e ) {

src/models/User/ResetPassword.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ class ResetPassword extends Model {
88

99
public $csrf_id;
1010
public $csrf_token;
11+
public $email;
1112
public $error;
1213
public $token;
1314
public $user;
14-
public $username;
1515

1616
}

src/templates/Email/User/ResetPassword.plain.phtml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Hello <?=$this->getContext()->user->getName()?>,
88
Someone requested your password to be reset on BNETDocs. If this was you, click
99
or copy and paste the link below into your web browser to reset your password.
1010

11-
<?=Common::relativeUrlToAbsolute('/user/resetpassword?username=' . rawurlencode($this->getContext()->user->getUsername()) . '&t=' . rawurlencode($this->getContext()->token))?>
11+
<?=Common::relativeUrlToAbsolute('/user/resetpassword?email=' . rawurlencode($this->getContext()->user->getEmail()) . '&t=' . rawurlencode($this->getContext()->token))?>
1212

1313

1414
**Note:** This link will only be available for 24 hours.

src/templates/Email/User/ResetPassword.rich.phtml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace BNETDocs\Templates\Email\User;
44
use \CarlBennett\MVC\Libraries\Common;
55

66
$name = filter_var($this->getContext()->user->getName(), FILTER_SANITIZE_FULL_SPECIAL_CHARS);
7-
$url = Common::relativeUrlToAbsolute('/user/resetpassword?username=' . rawurlencode($this->getContext()->user->getUsername()) . '&t=' . rawurlencode($this->getContext()->token));
7+
$url = Common::relativeUrlToAbsolute('/user/resetpassword?email=' . rawurlencode($this->getContext()->user->getEmail()) . '&t=' . rawurlencode($this->getContext()->token));
88

99
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional //EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
1010

src/templates/User/ResetPassword.phtml

+12-12
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ switch ($this->getContext()->error) {
1515
. 'reset password form expired, or this may have been a malicious'
1616
. 'attempt to reset your password.';
1717
break;
18-
case 'EMPTY_USERNAME':
19-
$message = 'The username was left blank.';
18+
case 'EMPTY_EMAIL':
19+
$message = 'The email address was left blank.';
2020
break;
2121
case 'USER_NOT_FOUND':
22-
$message = 'The username was not found in our system.';
22+
$message = 'The email address was not found in our system.';
2323
break;
2424
case 'EMAIL_FAILURE':
2525
$message = 'The server failed to queue the password reset email.';
@@ -66,15 +66,15 @@ require('./header.inc.phtml');
6666
<input type="hidden" name="csrf_token" value="<?=filter_var($this->getContext()->csrf_token, FILTER_SANITIZE_FULL_SPECIAL_CHARS)?>"/>
6767
<?php if (empty($this->getContext()->token)) { ?>
6868
<section>
69-
<label for="username">Username:</label><br/>
69+
<label for="email">Email address:</label><br/>
7070
<input
71-
type="text"
72-
name="username"
73-
id="username"
74-
value="<?=filter_var($this->getContext()->username, FILTER_SANITIZE_FULL_SPECIAL_CHARS)?>"
71+
type="email"
72+
name="email"
73+
id="email"
74+
value="<?=filter_var($this->getContext()->email, FILTER_SANITIZE_FULL_SPECIAL_CHARS)?>"
7575
tabindex="1"
7676
required
77-
autocomplete="username"
77+
autocomplete="email"
7878
autofocus="autofocus"
7979
/>
8080
</section>
@@ -86,11 +86,11 @@ require('./header.inc.phtml');
8686
/>
8787
</section>
8888
<?php } else { ?>
89-
<input type="hidden" name="username" value="<?=filter_var($this->getContext()->username, FILTER_SANITIZE_FULL_SPECIAL_CHARS)?>"/>
89+
<input type="hidden" name="email" value="<?=filter_var($this->getContext()->email, FILTER_SANITIZE_FULL_SPECIAL_CHARS)?>"/>
9090
<input type="hidden" name="t" value="<?=filter_var($this->getContext()->token, FILTER_SANITIZE_FULL_SPECIAL_CHARS)?>"/>
9191
<section>
92-
<label for="username">Username:</label><br/>
93-
<input type="text" id="username" readonly disabled tabindex="1" value="<?=filter_var($this->getContext()->username, FILTER_SANITIZE_FULL_SPECIAL_CHARS)?>"/>
92+
<label for="email">Email address:</label><br/>
93+
<input type="email" id="email" readonly disabled tabindex="1" value="<?=filter_var($this->getContext()->email, FILTER_SANITIZE_FULL_SPECIAL_CHARS)?>"/>
9494
</section>
9595
<section>
9696
<label for="pw1">New Password:</label><br/>

0 commit comments

Comments
 (0)