show correct error message if google login fails
This commit is contained in:
parent
862daea29c
commit
d45b790122
@ -121,6 +121,7 @@ class LoginController
|
||||
if ($redirectUrl === null) {
|
||||
$redirectUrl = \Container::$routeCollection->getRoute('index')->generateLink();
|
||||
}
|
||||
$defaultError = 'Authentication with Google failed. Please <a href="/login/google" title="Login with Google">try again</a>!';
|
||||
|
||||
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);
|
||||
|
@ -1,8 +0,0 @@
|
||||
@extends(templates/layout_normal)
|
||||
|
||||
@section(main)
|
||||
<h2>Login up with Google</h2>
|
||||
<div class="box">
|
||||
<p class="error justify">Authentication with Google failed. Please <a href="/login/google" title="Login with Google">try again</a>!</p>
|
||||
</div>
|
||||
@endsection
|
8
views/login/google_login_error.php
Normal file
8
views/login/google_login_error.php
Normal file
@ -0,0 +1,8 @@
|
||||
@extends(templates/layout_normal)
|
||||
|
||||
@section(main)
|
||||
<h2>Login up with Google</h2>
|
||||
<div class="box">
|
||||
<p class="error justify"><?= $error ?></p>
|
||||
</div>
|
||||
@endsection
|
Loading…
Reference in New Issue
Block a user