diff --git a/src/Controller/LoginController.php b/src/Controller/LoginController.php index 13c90c4..762491e 100644 --- a/src/Controller/LoginController.php +++ b/src/Controller/LoginController.php @@ -121,6 +121,7 @@ class LoginController if ($redirectUrl === null) { $redirectUrl = \Container::$routeCollection->getRoute('index')->generateLink(); } + $defaultError = 'Authentication with Google failed. Please try again!'; if ($this->request->user() !== null) { $this->request->session()->delete('redirect_after_login'); @@ -128,7 +129,7 @@ class LoginController } if ($this->request->query('state') !== $this->request->session()->get('oauth_state')) { - return new HtmlContent('login/google_login'); + return new HtmlContent('login/google_login_error', ['error' => $defaultError]); } $oAuth = new GoogleOAuth(new Request()); @@ -138,27 +139,23 @@ class LoginController ); if (!isset($tokenData['id_token'])) { - return new HtmlContent('login/google_login'); + return new HtmlContent('login/google_login_error', ['error' => $defaultError]); } $jwtParser = new JwtParser($tokenData['id_token']); $idToken = $jwtParser->getPayload(); if ($idToken['nonce'] !== $this->request->session()->get('oauth_nonce')) { - return new HtmlContent('login/google_login'); + return new HtmlContent('login/google_login_error', ['error' => $defaultError]); } if (!$idToken['email_verified']) { - return new HtmlContent('login/google_login'); + return new HtmlContent('login/google_login_error', ['error' => $defaultError]); } $user = $this->userRepository->getByGoogleSub($idToken['sub']); if ($user === null) { - return new JsonContent([ - 'error' => [ - 'errorText' => 'No user found for this Google account.' - ] - ]); + return new HtmlContent('login/google_login_error', ['error' => 'No user found for this Google account.']); } $this->request->setUser($user); diff --git a/views/login/google_login.php b/views/login/google_login.php deleted file mode 100644 index c438c42..0000000 --- a/views/login/google_login.php +++ /dev/null @@ -1,8 +0,0 @@ -@extends(templates/layout_normal) - -@section(main) -

Login up with Google

-
-

Authentication with Google failed. Please try again!

-
-@endsection diff --git a/views/login/google_login_error.php b/views/login/google_login_error.php new file mode 100644 index 0000000..9f6bf73 --- /dev/null +++ b/views/login/google_login_error.php @@ -0,0 +1,8 @@ +@extends(templates/layout_normal) + +@section(main) +

Login up with Google

+
+

+
+@endsection