1
0
mirror of https://github.com/delight-im/PHP-Auth.git synced 2025-08-02 22:27:30 +02:00

Add internal method 'Auth#getUserIdByEmailAddress'

This commit is contained in:
Marco
2016-08-20 18:06:36 +02:00
parent bfa5b5e6b1
commit f4b464a6f8

View File

@@ -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
*