[aur-dev] [PATCH 1/2] Remove superfluous function valid_user()
This helper function was almost 100% identical to uid_from_username(). Switch to using uid_from_username(), which has a much better name and implementation, everywhere. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org> --- web/html/addvote.php | 2 +- web/lib/acctfuncs.inc.php | 27 +-------------------------- 2 files changed, 2 insertions(+), 27 deletions(-) diff --git a/web/html/addvote.php b/web/html/addvote.php index 0372518..d152941 100644 --- a/web/html/addvote.php +++ b/web/html/addvote.php @@ -24,7 +24,7 @@ if (has_credential(CRED_TU_ADD_VOTE)) { $error = ""; if (!empty($_POST['user'])) { - if (!valid_user($_POST['user'])) { + if (!uid_from_username($_POST['user'])) { $error.= __("Username does not exist."); } else { diff --git a/web/lib/acctfuncs.inc.php b/web/lib/acctfuncs.inc.php index f718a77..ee8f0e3 100644 --- a/web/lib/acctfuncs.inc.php +++ b/web/lib/acctfuncs.inc.php @@ -479,7 +479,7 @@ function try_login() { } $dbh = DB::connect(); - $userID = valid_user($_REQUEST['user']); + $userID = uid_from_username($_REQUEST['user']); if (user_suspended($userID)) { $login_error = __('Account suspended'); @@ -609,31 +609,6 @@ function valid_username($user) { } /** - * Determine if a username exists in the database - * - * @param string $user Username to check in the database - * - * @return string|void Return user ID if in database, otherwise void - */ -function valid_user($user) { - if (!$user) { - return false; - } - - $dbh = DB::connect(); - - $q = "SELECT ID FROM Users WHERE "; - $q.= "Username = " . $dbh->quote($user); - $result = $dbh->query($q); - if (!$result) { - return null; - } - - $row = $result->fetch(PDO::FETCH_NUM); - return $row[0]; -} - -/** * Determine if a user already has a proposal open about themselves * * @param string $user Username to checkout for open proposal -- 2.5.1
Accept both user names and email addresses in the login prompt. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org> --- web/html/login.php | 2 +- web/lib/acctfuncs.inc.php | 2 +- web/lib/aur.inc.php | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/web/html/login.php b/web/html/login.php index ab7bac9..cef9be4 100644 --- a/web/html/login.php +++ b/web/html/login.php @@ -28,7 +28,7 @@ html_header('AUR ' . __("Login")); <ul class="errorlist"><li><?= $login_error ?></li></ul> <?php endif; ?> <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" /> </p> <p> diff --git a/web/lib/acctfuncs.inc.php b/web/lib/acctfuncs.inc.php index ee8f0e3..756c847 100644 --- a/web/lib/acctfuncs.inc.php +++ b/web/lib/acctfuncs.inc.php @@ -479,7 +479,7 @@ function try_login() { } $dbh = DB::connect(); - $userID = uid_from_username($_REQUEST['user']); + $userID = uid_from_loginname($_REQUEST['user']); if (user_suspended($userID)) { $login_error = __('Account suspended'); diff --git a/web/lib/aur.inc.php b/web/lib/aur.inc.php index 7d65913..9015ae8 100644 --- a/web/lib/aur.inc.php +++ b/web/lib/aur.inc.php @@ -467,6 +467,21 @@ function uid_from_username($username) { } /** + * 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 * * @param string $email An e-mail address in foo@example.com format -- 2.5.1
participants (1)
-
Lukas Fleischer