mirror of
https://github.com/delight-im/PHP-Auth.git
synced 2025-08-05 07:37:25 +02:00
Prevent usage of password reset if email has not been verified yet
This commit is contained in:
@@ -173,6 +173,9 @@ try {
|
|||||||
catch (\Delight\Auth\InvalidEmailException $e) {
|
catch (\Delight\Auth\InvalidEmailException $e) {
|
||||||
// invalid email address
|
// invalid email address
|
||||||
}
|
}
|
||||||
|
catch (\Delight\Auth\EmailNotVerifiedException $e) {
|
||||||
|
// email not verified
|
||||||
|
}
|
||||||
catch (\Delight\Auth\TooManyRequestsException $e) {
|
catch (\Delight\Auth\TooManyRequestsException $e) {
|
||||||
// too many requests
|
// too many requests
|
||||||
}
|
}
|
||||||
|
@@ -690,6 +690,7 @@ class Auth {
|
|||||||
* @param int|null $requestExpiresAfter (optional) the interval in seconds after which the request should expire
|
* @param int|null $requestExpiresAfter (optional) the interval in seconds after which the request should expire
|
||||||
* @param int|null $maxOpenRequests (optional) the maximum number of unexpired and unused requests per user
|
* @param int|null $maxOpenRequests (optional) the maximum number of unexpired and unused requests per user
|
||||||
* @throws InvalidEmailException if the email address was invalid or could not be found
|
* @throws InvalidEmailException if the email address was invalid or could not be found
|
||||||
|
* @throws EmailNotVerifiedException if the email address has not been verified yet via confirmation email
|
||||||
* @throws TooManyRequestsException if the number of allowed attempts/requests has been exceeded
|
* @throws TooManyRequestsException if the number of allowed attempts/requests has been exceeded
|
||||||
* @throws AuthError if an internal problem occurred (do *not* catch)
|
* @throws AuthError if an internal problem occurred (do *not* catch)
|
||||||
*/
|
*/
|
||||||
@@ -714,8 +715,14 @@ class Auth {
|
|||||||
|
|
||||||
$userData = $this->getUserDataByEmailAddress(
|
$userData = $this->getUserDataByEmailAddress(
|
||||||
$email,
|
$email,
|
||||||
[ 'id' ]
|
[ 'id', 'verified' ]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// ensure that the account has been verified before initiating a password reset
|
||||||
|
if ($userData['verified'] !== 1) {
|
||||||
|
throw new EmailNotVerifiedException();
|
||||||
|
}
|
||||||
|
|
||||||
$openRequests = (int) $this->getOpenPasswordResetRequests($userData['id']);
|
$openRequests = (int) $this->getOpenPasswordResetRequests($userData['id']);
|
||||||
|
|
||||||
if ($openRequests < $maxOpenRequests) {
|
if ($openRequests < $maxOpenRequests) {
|
||||||
|
@@ -138,6 +138,9 @@ function processRequestData(\Delight\Auth\Auth $auth) {
|
|||||||
catch (\Delight\Auth\InvalidEmailException $e) {
|
catch (\Delight\Auth\InvalidEmailException $e) {
|
||||||
return 'invalid email address';
|
return 'invalid email address';
|
||||||
}
|
}
|
||||||
|
catch (\Delight\Auth\EmailNotVerifiedException $e) {
|
||||||
|
return 'email not verified';
|
||||||
|
}
|
||||||
catch (\Delight\Auth\TooManyRequestsException $e) {
|
catch (\Delight\Auth\TooManyRequestsException $e) {
|
||||||
return 'too many requests';
|
return 'too many requests';
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user