mirror of
https://github.com/delight-im/PHP-Auth.git
synced 2025-08-07 00:26:28 +02:00
Add tests for method 'Auth#prepareTwoFactorViaSms'
This commit is contained in:
@@ -382,6 +382,25 @@ function processRequestData(\Delight\Auth\Auth $auth) {
|
|||||||
return 'too many requests';
|
return 'too many requests';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if ($_POST['action'] === 'prepareTwoFactorViaSms') {
|
||||||
|
try {
|
||||||
|
$phoneNumberAndOtpValue = $auth->prepareTwoFactorViaSms($_POST['phoneNumber']);
|
||||||
|
|
||||||
|
return $phoneNumberAndOtpValue[1] . ' -> ' . $phoneNumberAndOtpValue[0];
|
||||||
|
}
|
||||||
|
catch (\Delight\Auth\InvalidPhoneNumberException $e) {
|
||||||
|
return 'invalid phone number';
|
||||||
|
}
|
||||||
|
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') {
|
else if ($_POST['action'] === 'enableTwoFactorViaTotp') {
|
||||||
try {
|
try {
|
||||||
$recoveryCodes = $auth->enableTwoFactorViaTotp($_POST['otpValue']);
|
$recoveryCodes = $auth->enableTwoFactorViaTotp($_POST['otpValue']);
|
||||||
@@ -945,6 +964,12 @@ function showAuthenticatedUserForm(\Delight\Auth\Auth $auth) {
|
|||||||
echo '<button type="submit">Prepare 2FA via TOTP</button>';
|
echo '<button type="submit">Prepare 2FA via TOTP</button>';
|
||||||
echo '</form>';
|
echo '</form>';
|
||||||
|
|
||||||
|
echo '<form action="" method="post" accept-charset="utf-8">';
|
||||||
|
echo '<input type="hidden" name="action" value="prepareTwoFactorViaSms" />';
|
||||||
|
echo '<input type="text" name="phoneNumber" placeholder="Phone number" /> ';
|
||||||
|
echo '<button type="submit">Prepare 2FA via SMS</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="enableTwoFactorViaTotp" />';
|
echo '<input type="hidden" name="action" value="enableTwoFactorViaTotp" />';
|
||||||
echo '<input type="text" name="otpValue" placeholder="OTP value" /> ';
|
echo '<input type="text" name="otpValue" placeholder="OTP value" /> ';
|
||||||
|
Reference in New Issue
Block a user