1
0
mirror of https://github.com/delight-im/PHP-Auth.git synced 2025-08-03 22:57:27 +02:00

Add tests for method 'Auth#prepareTwoFactorViaEmail'

This commit is contained in:
Marco
2024-04-04 19:52:29 +02:00
parent 804141f1d4
commit 9464d754bd

View File

@@ -401,6 +401,22 @@ function processRequestData(\Delight\Auth\Auth $auth) {
return 'too many requests';
}
}
else if ($_POST['action'] === 'prepareTwoFactorViaEmail') {
try {
$emailAddressAndOtpValue = $auth->prepareTwoFactorViaEmail();
return $emailAddressAndOtpValue[1] . ' -> ' . $emailAddressAndOtpValue[0];
}
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'] === 'enableTwoFactorViaTotp') {
try {
$recoveryCodes = $auth->enableTwoFactorViaTotp($_POST['otpValue']);
@@ -970,6 +986,11 @@ function showAuthenticatedUserForm(\Delight\Auth\Auth $auth) {
echo '<button type="submit">Prepare 2FA via SMS</button>';
echo '</form>';
echo '<form action="" method="post" accept-charset="utf-8">';
echo '<input type="hidden" name="action" value="prepareTwoFactorViaEmail" />';
echo '<button type="submit">Prepare 2FA via email</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" /> ';