Skip to content
Snippets Groups Projects
Verified Commit 2a6dd5fd authored by Alex ORLUC's avatar Alex ORLUC
Browse files

FIX #11312 TIME 1:30 move authenticationInformations in guard

parent eae97192
No related branches found
No related tags found
No related merge requests found
...@@ -30,15 +30,6 @@ export class AppComponent { ...@@ -30,15 +30,6 @@ export class AppComponent {
private localStorage: LocalStorageService) { private localStorage: LocalStorageService) {
iconReg.addSvgIcon('maarchLogo', sanitizer.bypassSecurityTrustResourceUrl('../src/frontend/assets/logo_white.svg')); iconReg.addSvgIcon('maarchLogo', sanitizer.bypassSecurityTrustResourceUrl('../src/frontend/assets/logo_white.svg'));
this.http.get('../rest/authenticationInformations')
.subscribe((data: any) => {
this.authService.authMode = data.connection;
this.authService.changeKey = data.changeKey;
this.localStorage.setAppSession(data.instanceId);
if (this.authService.changeKey) {
this.dialog.open(AlertComponent, { autoFocus: false, disableClose: true, data: { mode: 'warning', title: 'lang.warnPrivateKeyTitle', msg: 'lang.warnPrivateKey' } });
}
});
if (this.cookieService.check('maarchParapheurLang')) { if (this.cookieService.check('maarchParapheurLang')) {
const cookieInfoLang = this.cookieService.get('maarchParapheurLang'); const cookieInfoLang = this.cookieService.get('maarchParapheurLang');
translate.setDefaultLang(cookieInfoLang); translate.setDefaultLang(cookieInfoLang);
......
...@@ -6,17 +6,29 @@ import { HttpClient } from '@angular/common/http'; ...@@ -6,17 +6,29 @@ import { HttpClient } from '@angular/common/http';
import { SignaturesContentService } from './signatures.service'; import { SignaturesContentService } from './signatures.service';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { AuthService } from './auth.service'; import { AuthService } from './auth.service';
import { map } from 'rxjs/operators';
import { Observable } from 'rxjs';
import { LocalStorageService } from './local-storage.service';
import { AlertComponent } from '../plugins/alert.component';
import { MatDialog } from '@angular/material';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
export class AuthGuard implements CanActivate { export class AuthGuard implements CanActivate {
constructor(private translate: TranslateService, public http: HttpClient, private router: Router, public signaturesService: SignaturesContentService, private cookieService: CookieService, public authService: AuthService) { } constructor(private translate: TranslateService,
public http: HttpClient,
private router: Router,
public signaturesService: SignaturesContentService,
private cookieService: CookieService,
public authService: AuthService,
private localStorage: LocalStorageService,
public dialog: MatDialog) { }
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
const tokenInfo = this.authService.getToken(); let tokenInfo = this.authService.getToken();
if (tokenInfo !== null) { if (tokenInfo !== null) {
if (this.authService.user.id === undefined) { if (this.authService.user.id === undefined) {
this.authService.user = JSON.parse(atob(tokenInfo.split('.')[1])).user; this.authService.user = JSON.parse(atob(tokenInfo.split('.')[1])).user;
...@@ -41,8 +53,45 @@ export class AuthGuard implements CanActivate { ...@@ -41,8 +53,45 @@ export class AuthGuard implements CanActivate {
return true; return true;
} else { } else {
this.authService.logout(); return this.http.get('../rest/authenticationInformations')
return false; .pipe(
map((data: any) => {
this.authService.authMode = data.connection;
this.authService.changeKey = data.changeKey;
this.localStorage.setAppSession(data.instanceId);
tokenInfo = this.authService.getToken();
if (tokenInfo !== null) {
this.authService.user = JSON.parse(atob(tokenInfo.split('.')[1])).user;
this.translate.use(this.authService.user.preferences.lang);
this.cookieService.set('maarchParapheurLang', this.authService.user.preferences.lang);
if (this.signaturesService.signaturesList.length === 0) {
this.http.get('../rest/users/' + this.authService.user.id + '/signatures')
.subscribe((dataSign: any) => {
this.signaturesService.signaturesList = dataSign.signatures;
});
}
if (this.authService.user.picture === undefined) {
this.http.get('../rest/users/' + this.authService.user.id + '/picture')
.subscribe((dataPic: any) => {
this.authService.user.picture = dataPic.picture;
});
}
if (this.authService.changeKey) {
this.dialog.open(AlertComponent, { autoFocus: false, disableClose: true, data: { mode: 'warning', title: 'lang.warnPrivateKeyTitle', msg: 'lang.warnPrivateKey' } });
}
return true;
} else {
this.authService.logout();
return false;
}
})
);
} }
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment