login-fixes #5
| @ -121,6 +121,7 @@ class LoginController | |||||||
|         if ($redirectUrl === null) { |         if ($redirectUrl === null) { | ||||||
|             $redirectUrl = \Container::$routeCollection->getRoute('index')->generateLink(); |             $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) { |         if ($this->request->user() !== null) { | ||||||
|             $this->request->session()->delete('redirect_after_login'); |             $this->request->session()->delete('redirect_after_login'); | ||||||
| @ -128,7 +129,7 @@ class LoginController | |||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         if ($this->request->query('state') !== $this->request->session()->get('oauth_state')) { |         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()); |         $oAuth = new GoogleOAuth(new Request()); | ||||||
| @ -138,27 +139,23 @@ class LoginController | |||||||
|         ); |         ); | ||||||
| 
 | 
 | ||||||
|         if (!isset($tokenData['id_token'])) { |         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']); |         $jwtParser = new JwtParser($tokenData['id_token']); | ||||||
|         $idToken = $jwtParser->getPayload(); |         $idToken = $jwtParser->getPayload(); | ||||||
| 
 | 
 | ||||||
|         if ($idToken['nonce'] !== $this->request->session()->get('oauth_nonce')) { |         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']) { |         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']); |         $user = $this->userRepository->getByGoogleSub($idToken['sub']); | ||||||
|         if ($user === null) { |         if ($user === null) { | ||||||
|             return new JsonContent([ |             return new HtmlContent('login/google_login_error', ['error' => 'No user found for this Google account.']); | ||||||
|                 'error' => [ |  | ||||||
|                     'errorText' => 'No user found for this Google account.' |  | ||||||
|                 ] |  | ||||||
|             ]); |  | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         $this->request->setUser($user); |         $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…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user