1
0
mirror of https://github.com/delight-im/PHP-Auth.git synced 2025-07-31 13:20:11 +02:00

Add tests for 'Auth#provideOneTimePasswordAsSecondFactor'

This commit is contained in:
Marco
2024-04-02 14:39:23 +02:00
parent 561d6cd450
commit 9cab58ecb4

View File

@@ -107,6 +107,22 @@ function processRequestData(\Delight\Auth\Auth $auth) {
return 'too many requests'; return 'too many requests';
} }
} }
else if ($_POST['action'] === 'provideOneTimePasswordAsSecondFactor') {
try {
$auth->provideOneTimePasswordAsSecondFactor($_POST['otpValue']);
return 'ok';
}
catch (\Delight\Auth\InvalidOneTimePasswordException $e) {
return 'invalid OTP';
}
catch (\Delight\Auth\NotLoggedInException $e) {
return 'first factor not completed';
}
catch (\Delight\Auth\TooManyRequestsException $e) {
return 'too many requests';
}
}
else if ($_POST['action'] === 'register') { else if ($_POST['action'] === 'register') {
try { try {
if ($_POST['require_verification'] == 1) { if ($_POST['require_verification'] == 1) {
@@ -978,6 +994,12 @@ function showGuestUserForm() {
echo '<button type="submit">Log in with username</button>'; echo '<button type="submit">Log in with username</button>';
echo '</form>'; echo '</form>';
echo '<form action="" method="post" accept-charset="utf-8">';
echo '<input type="hidden" name="action" value="provideOneTimePasswordAsSecondFactor" />';
echo '<input type="text" name="otpValue" placeholder="OTP value" /> ';
echo '<button type="submit">Provide OTP</button>';
echo '</form>';
echo '<form action="" method="post" accept-charset="utf-8">'; echo '<form action="" method="post" accept-charset="utf-8">';
echo '<input type="hidden" name="action" value="register" />'; echo '<input type="hidden" name="action" value="register" />';
echo '<input type="text" name="email" placeholder="Email address" /> '; echo '<input type="text" name="email" placeholder="Email address" /> ';