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

Change 'getUserIdByEmailAddress' to 'getUserDataByEmailAddress'

This commit is contained in:
Marco
2016-12-12 20:38:49 +01:00
parent 78a16d8f50
commit 6be456a27a

View File

@@ -712,11 +712,14 @@ class Auth {
$maxOpenRequests = (int) $maxOpenRequests; $maxOpenRequests = (int) $maxOpenRequests;
} }
$userId = $this->getUserIdByEmailAddress($email); $userData = $this->getUserDataByEmailAddress(
$openRequests = (int) $this->getOpenPasswordResetRequests($userId); $email,
[ 'id' ]
);
$openRequests = (int) $this->getOpenPasswordResetRequests($userData['id']);
if ($openRequests < $maxOpenRequests) { if ($openRequests < $maxOpenRequests) {
$this->createPasswordResetRequest($userId, $requestExpiresAfter, $callback); $this->createPasswordResetRequest($userData['id'], $requestExpiresAfter, $callback);
} }
else { else {
self::onTooManyRequests($requestExpiresAfter); self::onTooManyRequests($requestExpiresAfter);
@@ -724,17 +727,21 @@ class Auth {
} }
/** /**
* Returns the user ID for the account with the specified email address (if any) * Returns the requested user data for the account with the specified email address (if any)
*
* You must never pass untrusted input to the parameter that takes the column list
* *
* @param string $email the email address to look for * @param string $email the email address to look for
* @return string the user ID (if an account was found) * @param array $requestColumns the columns to request from the user's record
* @return array the user data (if an account was found)
* @throws InvalidEmailException if the email address could not be found * @throws InvalidEmailException if the email address could not be found
* @throws AuthError if an internal problem occurred (do *not* catch) * @throws AuthError if an internal problem occurred (do *not* catch)
*/ */
private function getUserIdByEmailAddress($email) { private function getUserDataByEmailAddress($email, array $requestColumns) {
try { try {
$userId = $this->db->selectValue( $projection = implode(', ', $requestColumns);
'SELECT id FROM users WHERE email = ?', $userData = $this->db->selectRow(
'SELECT ' . $projection . ' FROM users WHERE email = ?',
[ $email ] [ $email ]
); );
} }
@@ -742,8 +749,8 @@ class Auth {
throw new DatabaseError(); throw new DatabaseError();
} }
if (!empty($userId)) { if (!empty($userData)) {
return $userId; return $userData;
} }
else { else {
throw new InvalidEmailException(); throw new InvalidEmailException();