mirror of
https://github.com/delight-im/PHP-Auth.git
synced 2025-08-01 13:50:13 +02:00
Add tests for method 'Auth#enableTwoFactorViaEmail'
This commit is contained in:
@@ -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>';
|
||||
|
Reference in New Issue
Block a user