From f4b464a6f8b8ec9f4600e3922a6ec1125868327c Mon Sep 17 00:00:00 2001 From: Marco Date: Sat, 20 Aug 2016 18:06:36 +0200 Subject: [PATCH] Add internal method 'Auth#getUserIdByEmailAddress' --- src/Auth.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/Auth.php b/src/Auth.php index 52cbd28..d2d6f59 100644 --- a/src/Auth.php +++ b/src/Auth.php @@ -602,6 +602,33 @@ class Auth { $stmt->execute(); } + /** + * Returns the user ID for the account with the specified email address (if any) + * + * @param string $email the email address to look for + * @return string the user ID (if an account was found) + * @throws InvalidEmailException if the email address could not be found + * @throws AuthError if an internal problem occurred (do *not* catch) + */ + private function getUserIdByEmailAddress($email) { + $stmt = $this->db->prepare("SELECT id FROM users WHERE email = :email"); + $stmt->bindValue(':email', $email, \PDO::PARAM_STR); + + if ($stmt->execute()) { + $userId = $stmt->fetchColumn(); + + if ($userId !== false) { + return $userId; + } + else { + throw new InvalidEmailException(); + } + } + else { + throw new DatabaseError(); + } + } + /** * Sets whether the user is currently logged in and updates the session *