1
0
mirror of https://github.com/delight-im/PHP-Auth.git synced 2025-08-02 14:17:26 +02:00

Add tests for 'Auth#enableTwoFactorViaTotp'

This commit is contained in:
Marco
2024-04-01 14:15:11 +02:00
parent 8b0f5f3407
commit e919eec2a9

View File

@@ -366,6 +366,28 @@ function processRequestData(\Delight\Auth\Auth $auth) {
return 'too many requests';
}
}
else if ($_POST['action'] === 'enableTwoFactorViaTotp') {
try {
$recoveryCodes = $auth->enableTwoFactorViaTotp($_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';
@@ -900,6 +922,12 @@ function showAuthenticatedUserForm(\Delight\Auth\Auth $auth) {
echo '<button type="submit">Prepare 2FA via TOTP</button>';
echo '</form>';
echo '<form action="" method="post" accept-charset="utf-8">';
echo '<input type="hidden" name="action" value="enableTwoFactorViaTotp" />';
echo '<input type="text" name="otpValue" placeholder="OTP value" /> ';
echo '<button type="submit">Enable 2FA via TOTP</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>';