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>
This commit is contained in:
Lukas Fleischer 2015-09-11 21:56:51 +02:00
parent 396e50bdc8
commit c5014b0752
2 changed files with 2 additions and 27 deletions

View file

@ -24,7 +24,7 @@ if (has_credential(CRED_TU_ADD_VOTE)) {
$error = ""; $error = "";
if (!empty($_POST['user'])) { if (!empty($_POST['user'])) {
if (!valid_user($_POST['user'])) { if (!uid_from_username($_POST['user'])) {
$error.= __("Username does not exist."); $error.= __("Username does not exist.");
} else { } else {

View file

@ -479,7 +479,7 @@ function try_login() {
} }
$dbh = DB::connect(); $dbh = DB::connect();
$userID = valid_user($_REQUEST['user']); $userID = uid_from_username($_REQUEST['user']);
if (user_suspended($userID)) { if (user_suspended($userID)) {
$login_error = __('Account suspended'); $login_error = __('Account suspended');
@ -608,31 +608,6 @@ function valid_username($user) {
return true; return true;
} }
/**
* 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 * Determine if a user already has a proposal open about themselves
* *