1
0
mirror of https://github.com/delight-im/PHP-Auth.git synced 2025-07-10 19:16:22 +02:00

Handle 'SecondFactorRequiredException' in four relevant cases in tests

This commit is contained in:
Marco
2024-03-26 09:15:45 +01:00
parent fc468397e2
commit 3c7e17fca8

View File

@ -88,6 +88,21 @@ function processRequestData(\Delight\Auth\Auth $auth) {
catch (\Delight\Auth\EmailNotVerifiedException $e) { catch (\Delight\Auth\EmailNotVerifiedException $e) {
return 'email address not verified'; return 'email address not verified';
} }
catch (\Delight\Auth\SecondFactorRequiredException $e) {
$secondFactorOptions = [];
if ($e->hasTotpOption()) {
$secondFactorOptions[] = 'TOTP';
}
if ($e->hasSmsOption()) {
$secondFactorOptions[] = 'SMS (' . $e->getSmsRecipient() . ') with ' . $e->getSmsOtpValue();
}
if ($e->hasEmailOption()) {
$secondFactorOptions[] = 'email (' . $e->getEmailRecipient() . ') with ' . $e->getEmailOtpValue();
}
return 'second factor required: ' . \implode(' / ', $secondFactorOptions);
}
catch (\Delight\Auth\TooManyRequestsException $e) { catch (\Delight\Auth\TooManyRequestsException $e) {
return 'too many requests'; return 'too many requests';
} }
@ -167,6 +182,21 @@ function processRequestData(\Delight\Auth\Auth $auth) {
catch (\Delight\Auth\UserAlreadyExistsException $e) { catch (\Delight\Auth\UserAlreadyExistsException $e) {
return 'email address already exists'; return 'email address already exists';
} }
catch (\Delight\Auth\SecondFactorRequiredException $e) {
$secondFactorOptions = [];
if ($e->hasTotpOption()) {
$secondFactorOptions[] = 'TOTP';
}
if ($e->hasSmsOption()) {
$secondFactorOptions[] = 'SMS (' . $e->getSmsRecipient() . ') with ' . $e->getSmsOtpValue();
}
if ($e->hasEmailOption()) {
$secondFactorOptions[] = 'email (' . $e->getEmailRecipient() . ') with ' . $e->getEmailOtpValue();
}
return 'second factor required: ' . \implode(' / ', $secondFactorOptions);
}
catch (\Delight\Auth\TooManyRequestsException $e) { catch (\Delight\Auth\TooManyRequestsException $e) {
return 'too many requests'; return 'too many requests';
} }
@ -282,6 +312,21 @@ function processRequestData(\Delight\Auth\Auth $auth) {
catch (\Delight\Auth\InvalidPasswordException $e) { catch (\Delight\Auth\InvalidPasswordException $e) {
return 'invalid password'; return 'invalid password';
} }
catch (\Delight\Auth\SecondFactorRequiredException $e) {
$secondFactorOptions = [];
if ($e->hasTotpOption()) {
$secondFactorOptions[] = 'TOTP';
}
if ($e->hasSmsOption()) {
$secondFactorOptions[] = 'SMS (' . $e->getSmsRecipient() . ') with ' . $e->getSmsOtpValue();
}
if ($e->hasEmailOption()) {
$secondFactorOptions[] = 'email (' . $e->getEmailRecipient() . ') with ' . $e->getEmailOtpValue();
}
return 'second factor required: ' . \implode(' / ', $secondFactorOptions);
}
catch (\Delight\Auth\TooManyRequestsException $e) { catch (\Delight\Auth\TooManyRequestsException $e) {
return 'too many requests'; return 'too many requests';
} }