Commit e9553b627bf7adc4c2d1d204eef0eff3710f3d8e

Authored by Igor Kulikov
1 parent 0ce52220

Introduce OAuth failure handling

... ... @@ -43,6 +43,8 @@ import { DashboardInfo } from '@shared/models/dashboard.models';
43 43 import { PageData } from '@app/shared/models/page/page-data';
44 44 import { AdminService } from '@core/http/admin.service';
45 45 import { ActionNotificationShow } from '@core/notification/notification.actions';
  46 +import { MatDialog, MatDialogConfig } from '@angular/material/dialog';
  47 +import { AlertDialogComponent } from '@shared/components/dialog/alert-dialog.component';
46 48
47 49 @Injectable({
48 50 providedIn: 'root'
... ... @@ -60,7 +62,8 @@ export class AuthService {
60 62 private utils: UtilsService,
61 63 private dashboardService: DashboardService,
62 64 private adminService: AdminService,
63   - private translate: TranslateService
  65 + private translate: TranslateService,
  66 + private dialog: MatDialog
64 67 ) {
65 68 }
66 69
... ... @@ -273,6 +276,7 @@ export class AuthService {
273 276 const refreshToken = this.utils.getQueryParam('refreshToken');
274 277 const username = this.utils.getQueryParam('username');
275 278 const password = this.utils.getQueryParam('password');
  279 + const loginError = this.utils.getQueryParam('loginError');
276 280 if (publicId) {
277 281 return this.publicLogin(publicId).pipe(
278 282 mergeMap((response) => {
... ... @@ -317,6 +321,10 @@ export class AuthService {
317 321 }
318 322 )
319 323 );
  324 + } else if (loginError) {
  325 + this.showLoginErrorDialog(loginError);
  326 + this.utils.updateQueryParam('loginError', null);
  327 + return throwError(Error());
320 328 }
321 329 return this.procceedJwtTokenValidate(doTokenRefresh);
322 330 } else {
... ... @@ -324,6 +332,22 @@ export class AuthService {
324 332 }
325 333 }
326 334
  335 + private showLoginErrorDialog(loginError: string) {
  336 + this.translate.get(['login.error', 'action.close']).subscribe(
  337 + (translations) => {
  338 + const dialogConfig: MatDialogConfig = {
  339 + disableClose: true,
  340 + data: {
  341 + title: translations['login.error'],
  342 + message: loginError,
  343 + ok: translations['action.close']
  344 + }
  345 + };
  346 + this.dialog.open(AlertDialogComponent, dialogConfig);
  347 + }
  348 + );
  349 + }
  350 +
327 351 private procceedJwtTokenValidate(doTokenRefresh?: boolean): Observable<AuthPayload> {
328 352 const loadUserSubject = new ReplaySubject<AuthPayload>();
329 353 this.validateJwtToken(doTokenRefresh).subscribe(
... ...
... ... @@ -1355,7 +1355,8 @@
1355 1355 "password-link-sent-message": "Password reset link was successfully sent!",
1356 1356 "email": "Email",
1357 1357 "login-with": "Login with {{name}}",
1358   - "or": "or"
  1358 + "or": "or",
  1359 + "error": "Login error"
1359 1360 },
1360 1361 "position": {
1361 1362 "top": "Top",
... ...