From 35cc941f20a7139f624b67f1b41bb1208d5a9c9d Mon Sep 17 00:00:00 2001 From: Marco Date: Sat, 20 Aug 2016 18:07:18 +0200 Subject: [PATCH] Add internal method 'Auth#getOpenPasswordResetRequests' --- src/Auth.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/Auth.php b/src/Auth.php index d2d6f59..c2df563 100644 --- a/src/Auth.php +++ b/src/Auth.php @@ -629,6 +629,26 @@ class Auth { } } + /** + * Returns the number of open requests for a password reset by the specified user + * + * @param int $userId the ID of the user to check the requests for + * @return int the number of open requests for a password reset + * @throws AuthError if an internal problem occurred (do *not* catch) + */ + private function getOpenPasswordResetRequests($userId) { + $stmt = $this->db->prepare("SELECT COUNT(*) FROM users_resets WHERE user = :userId AND expires > :expiresAfter"); + $stmt->bindValue(':userId', $userId, \PDO::PARAM_INT); + $stmt->bindValue(':expiresAfter', time(), \PDO::PARAM_INT); + + if ($stmt->execute()) { + return $stmt->fetchColumn(); + } + else { + throw new DatabaseError(); + } + } + /** * Sets whether the user is currently logged in and updates the session *