app/controllers/AuthController.php: use Httpcb\Auth\Result to have more detailed reason why an authentication failed.
This commit is contained in:
parent
1e9203f35f
commit
ca7a3675f7
1 changed files with 13 additions and 5 deletions
|
|
@ -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');
|
||||
|
|
|
|||
Reference in a new issue