From ca7a3675f7b236604aacf21ab1b6d2f3798306f3 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Fri, 17 Aug 2018 16:54:38 +0200 Subject: [PATCH] app/controllers/AuthController.php: use Httpcb\Auth\Result to have more detailed reason why an authentication failed. --- app/controllers/AuthController.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/app/controllers/AuthController.php b/app/controllers/AuthController.php index 012185b..83c5531 100644 --- a/app/controllers/AuthController.php +++ b/app/controllers/AuthController.php @@ -5,9 +5,9 @@ namespace App\Controller; use App\Controller\ControllerBase, App\Model\Data\User, App\Form\Login as LoginForm, - App\Form\Registration as RegistrationForm; - -use Httpcb\OAuth\UserData\UserDataInterface; + App\Form\Registration as RegistrationForm, + Httpcb\OAuth\UserData\UserDataInterface, + Httpcb\Auth\Result; class AuthController extends ControllerBase { @@ -30,7 +30,8 @@ class AuthController extends ControllerBase $passwd = $form->getValue('Password'); // Perform login - if ($this->auth->login($email, $passwd)) { + $result = $this->auth->login($email, $passwd); + if ($result->isValid()) { $this->response->redirect('/'); } else { $this->flash->message('error', "Invalid credentials"); @@ -81,7 +82,13 @@ class AuthController extends ControllerBase else { $result = $this->auth->loginOauth($data); - if ($result === false) { + if (!$result->isValid()) { + + if ($result->getCode() == Result::FAILURE_ACCOUNT_SUSPENDED) { + $this->flash->message('error', 'Failed to authenticate.'); + $this->response->redirect('/login'); + return; + } if (User::findFirstByEmail($data->getEmail())) { $this->flash->error('The email address is already in use.'); @@ -98,6 +105,7 @@ class AuthController extends ControllerBase $this->response->redirect('/'); } } catch(\Exception $e) { + throw $e; $this->flash->message('error', 'Failed to authenticate.'); if ($this->auth->getUser()) { $this->response->redirect('/settings');