From 2529d29d807e2421531f2ab9245a8a9acd7c64fc Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Tue, 14 Aug 2018 22:54:13 +0200 Subject: [PATCH] app/controllers/AuthController.php: in oauthAction() redirect to registration page if no user is found. --- app/controllers/AuthController.php | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/app/controllers/AuthController.php b/app/controllers/AuthController.php index 8537e12..51fe187 100644 --- a/app/controllers/AuthController.php +++ b/app/controllers/AuthController.php @@ -81,17 +81,21 @@ class AuthController extends ControllerBase else { $result = $this->auth->loginOauth($data); - // There was an error when creating the account - if (is_array($result)) { - $msg = ''; - foreach ($result as $message) { - $msg .= '
  • ' . $message->getMessage() . '
  • '; + if ($result === false) { + + if (User::findFirstByUsernameOrEmail($data->getEmail())) { + $this->flash->error('The email address is already in use.'); + $this->response->redirect('/login'); + return; } - $this->flash->message('error', "Failed to create account: "); - $this->response->redirect('/login'); - } else { - $this->response->redirect('/'); + + $this->session->set('auth:register:data', $data); + $this->response->redirect(['for' => 'user-register']); + return; } + + // User is logged in. + $this->response->redirect('/'); } } catch(\Exception $e) { $this->flash->message('error', 'Failed to authenticate.');