From f06af42f8706e49f105af56d3ea94b71de714cf9 Mon Sep 17 00:00:00 2001 From: Marco Date: Sat, 25 Feb 2017 16:18:51 +0100 Subject: [PATCH] Move method 'getUserDataByUsername' from 'Auth' to 'UserManager' --- src/Auth.php | 37 ------------------------------------- src/UserManager.php | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/Auth.php b/src/Auth.php index 2554375..ce84cbf 100644 --- a/src/Auth.php +++ b/src/Auth.php @@ -735,43 +735,6 @@ final class Auth extends UserManager { } } - /** - * Returns the requested user data for the account with the specified username (if any) - * - * You must never pass untrusted input to the parameter that takes the column list - * - * @param string $username the username to look for - * @param array $requestedColumns the columns to request from the user's record - * @return array the user data (if an account was found unambiguously) - * @throws UnknownUsernameException if no user with the specified username has been found - * @throws AmbiguousUsernameException if multiple users with the specified username have been found - * @throws AuthError if an internal problem occurred (do *not* catch) - */ - private function getUserDataByUsername($username, array $requestedColumns) { - try { - $projection = implode(', ', $requestedColumns); - $users = $this->db->select( - 'SELECT ' . $projection . ' FROM users WHERE username = ? LIMIT 0, 2', - [ $username ] - ); - } - catch (Error $e) { - throw new DatabaseError(); - } - - if (empty($users)) { - throw new UnknownUsernameException(); - } - else { - if (count($users) === 1) { - return $users[0]; - } - else { - throw new AmbiguousUsernameException(); - } - } - } - /** * Returns the number of open requests for a password reset by the specified user * diff --git a/src/UserManager.php b/src/UserManager.php index dacbff7..80e7ae7 100644 --- a/src/UserManager.php +++ b/src/UserManager.php @@ -160,6 +160,43 @@ abstract class UserManager { return $newUserId; } + /** + * Returns the requested user data for the account with the specified username (if any) + * + * You must never pass untrusted input to the parameter that takes the column list + * + * @param string $username the username to look for + * @param array $requestedColumns the columns to request from the user's record + * @return array the user data (if an account was found unambiguously) + * @throws UnknownUsernameException if no user with the specified username has been found + * @throws AmbiguousUsernameException if multiple users with the specified username have been found + * @throws AuthError if an internal problem occurred (do *not* catch) + */ + protected function getUserDataByUsername($username, array $requestedColumns) { + try { + $projection = implode(', ', $requestedColumns); + $users = $this->db->select( + 'SELECT ' . $projection . ' FROM users WHERE username = ? LIMIT 0, 2', + [ $username ] + ); + } + catch (Error $e) { + throw new DatabaseError(); + } + + if (empty($users)) { + throw new UnknownUsernameException(); + } + else { + if (count($users) === 1) { + return $users[0]; + } + else { + throw new AmbiguousUsernameException(); + } + } + } + /** * Validates an email address *