Allow for logging in via email address

Accept both user names and email addresses in the login prompt.

Suggested-by: Johannes Löthberg <johannes@kyriasis.com>
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
This commit is contained in:
Lukas Fleischer 2015-09-11 22:01:46 +02:00
parent c5014b0752
commit ee9a8f232b
3 changed files with 17 additions and 2 deletions

View file

@ -28,7 +28,7 @@ html_header('AUR ' . __("Login"));
<ul class="errorlist"><li><?= $login_error ?></li></ul> <ul class="errorlist"><li><?= $login_error ?></li></ul>
<?php endif; ?> <?php endif; ?>
<p> <p>
<label for="id_username"><?= __('Username') . ':'; ?></label> <label for="id_username"><?= __('User name or email address') . ':'; ?></label>
<input id="id_username" type="text" name="user" size="30" maxlength="<?= config_get_int('options', 'username_max_len'); ?>" value="<?php if (isset($_POST['user'])) { print htmlspecialchars($_POST['user'], ENT_QUOTES); } ?>" autofocus="autofocus" /> <input id="id_username" type="text" name="user" size="30" maxlength="<?= config_get_int('options', 'username_max_len'); ?>" value="<?php if (isset($_POST['user'])) { print htmlspecialchars($_POST['user'], ENT_QUOTES); } ?>" autofocus="autofocus" />
</p> </p>
<p> <p>

View file

@ -479,7 +479,7 @@ function try_login() {
} }
$dbh = DB::connect(); $dbh = DB::connect();
$userID = uid_from_username($_REQUEST['user']); $userID = uid_from_loginname($_REQUEST['user']);
if (user_suspended($userID)) { if (user_suspended($userID)) {
$login_error = __('Account suspended'); $login_error = __('Account suspended');

View file

@ -466,6 +466,21 @@ function uid_from_username($username) {
return $row[0]; return $row[0];
} }
/**
* Determine the user's ID in the database using a username or email address
*
* @param string $username The username or email address of an account
*
* @return string Return user ID if exists, otherwise null
*/
function uid_from_loginname($loginname) {
$uid = uid_from_username($loginname);
if (!$uid) {
$uid = uid_from_email($loginname);
}
return $uid;
}
/** /**
* Determine the user's ID in the database using an e-mail address * Determine the user's ID in the database using an e-mail address
* *