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:
27
src/Auth.php
27
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
|
||||
*
|
||||
|
Reference in New Issue
Block a user