diff --git a/html/inc/boinc_db.inc b/html/inc/boinc_db.inc index e46a8617cd..d3cd4dd5eb 100644 --- a/html/inc/boinc_db.inc +++ b/html/inc/boinc_db.inc @@ -193,16 +193,12 @@ class BoincUser { $email_addr = BoincDb::escape_string($email_addr); return self::lookup("email_addr='$email_addr'"); } + // name is not necessarily unique + // static function lookup_name($name) { $name = BoincDb::escape_string($name); $users = BoincUser::enum("name='$name'"); - switch (sizeof($users)) { - case 1: - return $users[0]; - case 0: - return null; - } - return -1; + return $users; } static function count($clause) { $db = BoincDb::get(); diff --git a/html/user/pm.php b/html/user/pm.php index 46fae424d3..3e668ed38f 100644 --- a/html/user/pm.php +++ b/html/user/pm.php @@ -210,12 +210,13 @@ function do_send($logged_in_user) { pm_form($replyto, $userid, tra("Could not find user with id %1", $userid)); } } else { - $user = BoincUser::lookup_name($username); - if ($user == null) { + $users = BoincUser::lookup_name($username); + if (count($users) == 0) { pm_form($replyto, $userid, tra("Could not find user with username %1", $username)); - } elseif ($user == -1) { // Non-unique username + } elseif (count($users) > 1) { // Non-unique username pm_form($replyto, $userid, tra("%1 is not a unique username; you will have to use user ID", $username)); } + $user = $users[0]; } BoincForumPrefs::lookup($user); if (is_ignoring($user, $logged_in_user)) {