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

Support multi-factor authentication via 'onBeforeSuccess' callback

This commit is contained in:
Marco
2017-07-02 23:12:36 +02:00
parent 6aa3f58059
commit 0909291cf1
3 changed files with 56 additions and 19 deletions

View File

@@ -49,12 +49,16 @@ function processRequestData(\Delight\Auth\Auth $auth) {
$rememberDuration = null;
}
$onBeforeSuccess = function ($userId) {
return \mt_rand(1, 100) <= 50;
};
try {
if (isset($_POST['email'])) {
$auth->login($_POST['email'], $_POST['password'], $rememberDuration);
$auth->login($_POST['email'], $_POST['password'], $rememberDuration, $onBeforeSuccess);
}
elseif (isset($_POST['username'])) {
$auth->loginWithUsername($_POST['username'], $_POST['password'], $rememberDuration);
$auth->loginWithUsername($_POST['username'], $_POST['password'], $rememberDuration, $onBeforeSuccess);
}
else {
return 'either email address or username required';
@@ -77,6 +81,9 @@ function processRequestData(\Delight\Auth\Auth $auth) {
catch (\Delight\Auth\EmailNotVerifiedException $e) {
return 'email not verified';
}
catch (\Delight\Auth\AttemptCancelledException $e) {
return 'attempt cancelled';
}
catch (\Delight\Auth\TooManyRequestsException $e) {
return 'too many requests';
}