diff --git a/mydnshost-php-api b/mydnshost-php-api index 69f8584..78faf32 160000 --- a/mydnshost-php-api +++ b/mydnshost-php-api @@ -1 +1 @@ -Subproject commit 69f8584a0f13052b833ff87a19998bb1b447dbba +Subproject commit 78faf324ad6fd046e151c750944022c9ff882f70 diff --git a/public/index.php b/public/index.php index 3ca5743..56f1678 100644 --- a/public/index.php +++ b/public/index.php @@ -84,7 +84,7 @@ } } else { $hadLoginDetails = session::exists('logindata'); - session::clear(['DisplayEngine::Flash', 'wantedPage', 'lastlogin']); + session::clear(['DisplayEngine::Flash', 'wantedPage', 'lastlogin', '2fa_push']); if ($hadLoginDetails) { setWantedPage($displayEngine, $_SERVER['REQUEST_URI']); diff --git a/src/routes/NotAuthedRoutes.php b/src/routes/NotAuthedRoutes.php index 88d1614..fda5af5 100644 --- a/src/routes/NotAuthedRoutes.php +++ b/src/routes/NotAuthedRoutes.php @@ -20,9 +20,32 @@ public function addRoutes($router, $displayEngine, $api) { } } + if (session::exists('2fa_push')) { + $displayEngine->setVar('twofactor_push', session::get('2fa_push')); + } + $displayEngine->display('2fa.tpl'); }); + $router->get('/2fa_push.json', function() use ($displayEngine, $api) { + if (session::exists('lastlogin')) { + $lastAttempt = session::get('lastlogin'); + + $user = $lastAttempt['user']; + $pass = $lastAttempt['pass']; + + $result = $api->doAuth2FAPush($user, $pass); + + if (isset($result['pushcode'])) { + header('Content-Type: application/json'); + echo json_encode(['pushcode' => $result['pushcode']]); + return TRUE; + } + } + + return FALSE; + }); + $router->post('/login', function() use ($displayEngine, $api) { $lastAttempt = session::exists('lastlogin') ? session::get('lastlogin') : []; session::remove('lastlogin'); @@ -83,6 +106,12 @@ public function addRoutes($router, $displayEngine, $api) { session::setCurrentUser(null); if (isset($lr['login_error']) && $lr['login_error'] == '2fa_required' && isset($_POST['user']) && isset($_POST['pass'])) { + if (isset($lr['2fa_push'])) { + session::set('2fa_push', true); + } else { + session::remove('2fa_push'); + } + session::set('lastlogin', $_POST); header('Location: ' . $displayEngine->getURL('/2fa')); } else { diff --git a/src/routes/UserRoutes.php b/src/routes/UserRoutes.php index bf51134..1d4142a 100644 --- a/src/routes/UserRoutes.php +++ b/src/routes/UserRoutes.php @@ -325,6 +325,8 @@ public function addRoutes($router, $displayEngine, $api) { if (array_key_exists('error', $apiresult)) { $result = ['error', 'There was an error verifying the key: ' . $apiresult['error']]; + } else if (array_key_exists('info', $apiresult)) { + $result = ['info', $apiresult['info']]; } else { $result = ['success', 'Key verified.']; } diff --git a/templates/default/2fa.tpl b/templates/default/2fa.tpl index 00a448d..c622377 100644 --- a/templates/default/2fa.tpl +++ b/templates/default/2fa.tpl @@ -2,8 +2,18 @@ {% block contenttop %}{% endblock %}

2FA Required

+ + {% if twofactor_push %} +
+ Waiting for 2FA Push... +

+ You can manually enter a code instead. +
+ {% endif %} + +