[ADF-4183] improved auth redirection (#4399)

* base auth guard implementation

* remove code duplication

* unit test fixes
This commit is contained in:
Denys Vuika
2019-03-06 13:14:23 +00:00
committed by Eugenio Romano
parent bf331f1145
commit f6341e31a0
9 changed files with 216 additions and 173 deletions

View File

@@ -20,8 +20,8 @@ import {
Input, OnInit, Output, TemplateRef, ViewEncapsulation
} from '@angular/core';
import { AbstractControl, FormBuilder, FormGroup, Validators } from '@angular/forms';
import { Router } from '@angular/router';
import { Router, ActivatedRoute, Params } from '@angular/router';
import { Location } from '@angular/common';
import { AuthenticationService } from '../../services/authentication.service';
import { LogService } from '../../services/log.service';
import { TranslationService } from '../../services/translation.service';
@@ -140,7 +140,9 @@ export class LoginComponent implements OnInit {
private logService: LogService,
private router: Router,
private appConfig: AppConfigService,
private userPreferences: UserPreferencesService
private userPreferences: UserPreferencesService,
private location: Location,
private route: ActivatedRoute
) {
this.initFormError();
this.initFormFieldsMessages();
@@ -154,6 +156,17 @@ export class LoginComponent implements OnInit {
}
}
if (this.authService.isEcmLoggedIn() || this.authService.isBpmLoggedIn()) {
this.location.forward();
} else {
this.route.queryParams.subscribe((params: Params) => {
const url = params['redirectUrl'];
const provider = this.appConfig.get<string>(AppConfigValues.PROVIDERS);
this.authService.setRedirect({ provider, url });
});
}
if (this.hasCustomFieldsValidation()) {
this.form = this._fb.group(this.fieldsValidation);
} else {