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

Add tests for method 'Auth#enableTwoFactorViaEmail'

This commit is contained in:
Marco
2024-06-14 13:34:28 +02:00
parent 4dc67aaa30
commit 75c372198d

View File

@@ -461,6 +461,28 @@ function processRequestData(\Delight\Auth\Auth $auth) {
return 'too many requests';
}
}
else if ($_POST['action'] === 'enableTwoFactorViaEmail') {
try {
$recoveryCodes = $auth->enableTwoFactorViaEmail($_POST['otpValue']);
return \implode(' | ', $recoveryCodes);
}
catch (\Delight\Auth\InvalidOneTimePasswordException $e) {
return 'invalid OTP';
}
catch (\Delight\Auth\TwoFactorMechanismNotInitializedException $e) {
return 'not initialized';
}
catch (\Delight\Auth\TwoFactorMechanismAlreadyEnabledException $e) {
return 'already enabled';
}
catch (\Delight\Auth\NotLoggedInException $e) {
return 'not logged in';
}
catch (\Delight\Auth\TooManyRequestsException $e) {
return 'too many requests';
}
}
else if ($_POST['action'] === 'reconfirmPassword') {
try {
return $auth->reconfirmPassword($_POST['password']) ? 'correct' : 'wrong';
@@ -1025,6 +1047,12 @@ function showAuthenticatedUserForm(\Delight\Auth\Auth $auth) {
echo '<button type="submit">Enable 2FA via SMS</button>';
echo '</form>';
echo '<form action="" method="post" accept-charset="utf-8">';
echo '<input type="hidden" name="action" value="enableTwoFactorViaEmail" />';
echo '<input type="text" name="otpValue" placeholder="OTP value" /> ';
echo '<button type="submit">Enable 2FA via email</button>';
echo '</form>';
echo '<form action="" method="post" accept-charset="utf-8">';
echo '<input type="hidden" name="action" value="logOut" />';
echo '<button type="submit">Log out</button>';