Skip to content

Commit 79c5027

Browse files
committed
Revert back to using emails for login form
1 parent 0dfe6d0 commit 79c5027

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

src/controllers/User/Login.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ protected function tryLogin(Router &$router, UserLoginModel &$model) {
4747
$csrf_id = (isset($data["csrf_id" ]) ? $data["csrf_id" ] : null);
4848
$csrf_token = (isset($data["csrf_token"]) ? $data["csrf_token"] : null);
4949
$csrf_valid = CSRF::validate($csrf_id, $csrf_token);
50-
$username = (isset($data["username" ]) ? $data["username" ] : null);
50+
$email = (isset($data["email" ]) ? $data["email" ] : null);
5151
$password = (isset($data["password" ]) ? $data["password" ] : null);
5252

53-
$model->username = $username;
53+
$model->email = $email;
5454

5555
if (!$csrf_valid) {
5656
$model->error = "INVALID_CSRF";
@@ -60,16 +60,16 @@ protected function tryLogin(Router &$router, UserLoginModel &$model) {
6060

6161
if ( isset( Authentication::$user )) {
6262
$model->error = "ALREADY_LOGGED_IN";
63-
} else if (empty($username)) {
64-
$model->error = "EMPTY_USERNAME";
63+
} else if (empty($email)) {
64+
$model->error = "EMPTY_EMAIL";
6565
} else if (Common::$config->bnetdocs->user_login_disabled) {
6666
$model->error = "LOGIN_DISABLED";
6767
}
6868

6969
if ($model->error) return;
7070

7171
try {
72-
$user = new User(User::findIdByUsername($username));
72+
$user = new User(User::findIdByEmail($email));
7373
} catch (UserNotFoundException $e) {
7474
$user = null;
7575
}
@@ -95,7 +95,7 @@ protected function tryLogin(Router &$router, UserLoginModel &$model) {
9595
getenv("REMOTE_ADDR"),
9696
json_encode([
9797
"error" => $model->error,
98-
"username" => $username,
98+
"email" => $model->email,
9999
])
100100
);
101101
}

src/models/User/Login.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Login extends Model {
88

99
public $csrf_id;
1010
public $csrf_token;
11+
public $email;
1112
public $error;
12-
public $username;
1313

1414
}

src/templates/User/Login.phtml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ switch ($this->getContext()->error) {
1616
case "ALREADY_LOGGED_IN":
1717
$message = "You are already logged in, you must log out first.";
1818
break;
19-
case "EMPTY_USERNAME":
20-
$message = "The username was left blank.";
19+
case "EMPTY_EMAIL":
20+
$message = "The email address was left blank.";
2121
break;
2222
case "USER_NOT_FOUND":
2323
case "PASSWORD_INCORRECT":
24-
$message = "Incorrect username or password.";
24+
$message = "Incorrect email address or password.";
2525
break;
2626
case "USER_DISABLED":
2727
$message = "The account has been administratively disabled.";
@@ -56,15 +56,15 @@ require("./header.inc.phtml");
5656
<tbody>
5757
<tr>
5858
<td>
59-
<label for="username">Username:</label><br/>
59+
<label for="email">Email address:</label><br/>
6060
<input
61-
type="text"
62-
name="username"
63-
id="username"
64-
value="<?=filter_var($this->getContext()->username, FILTER_SANITIZE_FULL_SPECIAL_CHARS)?>"
61+
type="email"
62+
name="email"
63+
id="email"
64+
value="<?=filter_var($this->getContext()->email, FILTER_SANITIZE_FULL_SPECIAL_CHARS)?>"
6565
tabindex="1"
6666
required
67-
autocomplete="username"
67+
autocomplete="email"
6868
autofocus="autofocus"
6969
/>
7070
</td><td>

0 commit comments

Comments
 (0)