diff --git a/src/frontend/app/app.component.ts b/src/frontend/app/app.component.ts index fe96ea882737e3af5fdcc4ae4f0d3ed69f0d30ac..1b5787cbd80c4ab68fd019607b621ab8b99f7207 100755 --- a/src/frontend/app/app.component.ts +++ b/src/frontend/app/app.component.ts @@ -8,6 +8,7 @@ import { TranslateService } from '@ngx-translate/core'; import { MatDialog, MatIconRegistry } from '@angular/material'; import { AlertComponent } from './plugins/alert.component'; import { AuthService } from './service/auth.service'; +import { LocalStorageService } from './service/local-storage.service'; @Component({ selector: 'app-root', @@ -18,13 +19,22 @@ import { AuthService } from './service/auth.service'; export class AppComponent { - constructor(private translate: TranslateService, public http: HttpClient, public signaturesService: SignaturesContentService, public sanitizer: DomSanitizer, private cookieService: CookieService, public notificationService: NotificationService, public dialog: MatDialog, iconReg: MatIconRegistry, public authService: AuthService) { + constructor(private translate: TranslateService, + public http: HttpClient, + public signaturesService: SignaturesContentService, + public sanitizer: DomSanitizer, + private cookieService: CookieService, + public notificationService: NotificationService, + public dialog: MatDialog, iconReg: MatIconRegistry, + public authService: AuthService, + private localStorage: LocalStorageService) { 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' } }); } diff --git a/src/frontend/app/document/document.component.ts b/src/frontend/app/document/document.component.ts index bef28aa815fe44beed56d0e37a37d5598c6f35e7..9530292ab6cc08ce154047ec8d8d13f4bb0f297a 100755 --- a/src/frontend/app/document/document.component.ts +++ b/src/frontend/app/document/document.component.ts @@ -17,6 +17,7 @@ import { TranslateService } from '@ngx-translate/core'; import { CdkDragEnd, DragRef, CdkDrag } from '@angular/cdk/drag-drop'; import { DocumentListComponent } from './document-list/document-list.component'; import { AuthService } from '../service/auth.service'; +import { LocalStorageService } from '../service/local-storage.service'; @Component({ @@ -139,11 +140,18 @@ export class DocumentComponent implements OnInit { }, 400); } - constructor(private translate: TranslateService, private router: Router, private route: ActivatedRoute, public http: HttpClient, + constructor(private translate: TranslateService, + private router: Router, + private route: ActivatedRoute, + public http: HttpClient, public signaturesService: SignaturesContentService, public notificationService: NotificationService, private cookieService: CookieService, - private sanitizer: DomSanitizer, public dialog: MatDialog, private bottomSheet: MatBottomSheet, public authService: AuthService) { + private sanitizer: DomSanitizer, + public dialog: MatDialog, + private bottomSheet: MatBottomSheet, + public authService: AuthService, + private localStorage: LocalStorageService) { this.draggable = false; } @@ -227,7 +235,8 @@ export class DocumentComponent implements OnInit { this.signaturesService.signaturesContent = []; this.signaturesService.notesContent = []; - const notesContent = localStorage.getItem(this.mainDocument.id.toString()); + const notesContent = this.localStorage.get(this.mainDocument.id.toString()); + if (notesContent) { const storageContent = JSON.parse(notesContent); this.signaturesService.notesContent = storageContent['note']; @@ -371,7 +380,7 @@ export class DocumentComponent implements OnInit { direction: 'ltr' }; this.bottomSheet.open(RejectInfoBottomSheetComponent, config); - localStorage.removeItem(this.mainDocument.id.toString()); + this.localStorage.remove(this.mainDocument.id.toString()); } else if (result === 'annotation') { this.signaturesService.annotationMode = true; this.appDocumentNotePad.initPad(); @@ -392,7 +401,7 @@ export class DocumentComponent implements OnInit { direction: 'ltr' }; this.bottomSheet.open(SuccessInfoValidBottomSheetComponent, config); - localStorage.removeItem(this.mainDocument.id.toString()); + this.localStorage.remove(this.mainDocument.id.toString()); } }); } @@ -422,7 +431,7 @@ export class DocumentComponent implements OnInit { if (result) { this.signaturesService.signaturesContent = []; this.signaturesService.notesContent = []; - localStorage.removeItem(this.mainDocument.id.toString()); + this.localStorage.remove(this.mainDocument.id.toString()); this.notificationService.success('lang.noteAndSignatureDeleted'); } }); @@ -447,7 +456,8 @@ export class DocumentComponent implements OnInit { undoTag() { if (this.signaturesService.notesContent[this.pageNum]) { this.signaturesService.notesContent[this.pageNum].pop(); - localStorage.setItem(this.mainDocument.id.toString(), JSON.stringify({ 'sign': this.signaturesService.signaturesContent, 'note': this.signaturesService.notesContent })); + this.localStorage.remove(this.mainDocument.id.toString()); + this.localStorage.save(this.mainDocument.id.toString(), JSON.stringify({ 'sign': this.signaturesService.signaturesContent, 'note': this.signaturesService.notesContent })); } } diff --git a/src/frontend/app/documentNotePad/document-note-pad.component.ts b/src/frontend/app/documentNotePad/document-note-pad.component.ts index 159a72137df550fb882b186097b6aef9bad567c0..e6249902fbae85d1865c169ac2fbe98749d1d126 100644 --- a/src/frontend/app/documentNotePad/document-note-pad.component.ts +++ b/src/frontend/app/documentNotePad/document-note-pad.component.ts @@ -4,6 +4,7 @@ import { NotificationService } from '../service/notification.service'; import { DomSanitizer } from '@angular/platform-browser'; import { TranslateService } from '@ngx-translate/core'; import { AuthService } from '../service/auth.service'; +import { LocalStorageService } from '../service/local-storage.service'; @Component({ selector: 'app-document-note-pad', @@ -17,7 +18,12 @@ export class DocumentNotePadComponent implements OnInit { @Output() triggerEvent = new EventEmitter<string>(); @ViewChild('canvas') canvas: ElementRef; - constructor(private translate: TranslateService, private sanitizer: DomSanitizer, public signaturesService: SignaturesContentService, public notificationService: NotificationService, public authService: AuthService) { } + constructor(private translate: TranslateService, + private sanitizer: DomSanitizer, + public signaturesService: SignaturesContentService, + public notificationService: NotificationService, + public authService: AuthService, + private localStorage: LocalStorageService) { } ngOnInit(): void { } @@ -64,7 +70,7 @@ export class DocumentNotePadComponent implements OnInit { 'width': this.signaturesService.workingAreaWidth, } ); - localStorage.setItem(this.signaturesService.mainDocumentId.toString(), JSON.stringify({'sign' : this.signaturesService.signaturesContent, 'note' : this.signaturesService.notesContent})); + this.localStorage.save(this.signaturesService.mainDocumentId.toString(), JSON.stringify({'sign' : this.signaturesService.signaturesContent, 'note' : this.signaturesService.notesContent})); this.triggerEvent.emit(); this.signaturesService.x = 0; this.signaturesService.y = 90; diff --git a/src/frontend/app/documentSignList/document-sign-list.component.ts b/src/frontend/app/documentSignList/document-sign-list.component.ts index 407d070d4fe52ed515e4d00b22735f3bf9d34ca1..e34a00e4b0e9c219f58ba69490faeecfd454580e 100644 --- a/src/frontend/app/documentSignList/document-sign-list.component.ts +++ b/src/frontend/app/documentSignList/document-sign-list.component.ts @@ -6,6 +6,7 @@ import { import { NotificationService } from '../service/notification.service'; import { DomSanitizer } from '@angular/platform-browser'; import { TranslateService } from '@ngx-translate/core'; +import { LocalStorageService } from '../service/local-storage.service'; @Component({ @@ -16,7 +17,12 @@ export class DocumentSignListComponent implements OnInit { @ViewChild('menuTrigger') menuSign: MatMenuTrigger; - constructor(private translate: TranslateService, private sanitization: DomSanitizer, public signaturesService: SignaturesContentService, public notificationService: NotificationService) { } + constructor(private translate: TranslateService, + private sanitization: DomSanitizer, + public signaturesService: SignaturesContentService, + public notificationService: NotificationService, + private localStorage: LocalStorageService + ) { } ngOnInit(): void { } @@ -29,7 +35,7 @@ export class DocumentSignListComponent implements OnInit { this.signaturesService.signaturesContent[this.signaturesService.currentPage][i].positionX = percentx; this.signaturesService.signaturesContent[this.signaturesService.currentPage][i].positionY = percenty; - localStorage.setItem(this.signaturesService.mainDocumentId.toString(), JSON.stringify({'sign' : this.signaturesService.signaturesContent, 'note' : this.signaturesService.notesContent})); + this.localStorage.save(this.signaturesService.mainDocumentId.toString(), JSON.stringify({'sign' : this.signaturesService.signaturesContent, 'note' : this.signaturesService.notesContent})); this.signaturesService.documentFreeze = false; } @@ -48,7 +54,7 @@ export class DocumentSignListComponent implements OnInit { this.signaturesService.signaturesContent[index].push(JSON.parse(JSON.stringify(this.signaturesService.signaturesContent[this.signaturesService.currentPage][i]))); } } - localStorage.setItem(this.signaturesService.mainDocumentId.toString(), JSON.stringify({'sign' : this.signaturesService.signaturesContent, 'note' : this.signaturesService.notesContent})); + this.localStorage.save(this.signaturesService.mainDocumentId.toString(), JSON.stringify({'sign' : this.signaturesService.signaturesContent, 'note' : this.signaturesService.notesContent})); } this.menuSign.closeMenu(); } @@ -79,7 +85,7 @@ export class DocumentSignListComponent implements OnInit { } else { this.signaturesService.signaturesContent[this.signaturesService.currentPage].splice(i, 1); } - localStorage.setItem(this.signaturesService.mainDocumentId.toString(), JSON.stringify({'sign' : this.signaturesService.signaturesContent, 'note' : this.signaturesService.notesContent})); + this.localStorage.save(this.signaturesService.mainDocumentId.toString(), JSON.stringify({'sign' : this.signaturesService.signaturesContent, 'note' : this.signaturesService.notesContent})); } // USE TO PREVENT ISSUE IN MOBILE diff --git a/src/frontend/app/pad/pad.component.ts b/src/frontend/app/pad/pad.component.ts index 932c5f7b32f90df653ae2d7312f37904026cb501..74b7db8ee41415dca7fada7d8ce4d89e082ffa4b 100755 --- a/src/frontend/app/pad/pad.component.ts +++ b/src/frontend/app/pad/pad.component.ts @@ -7,6 +7,7 @@ import { NotificationService } from '../service/notification.service'; import { TranslateService } from '@ngx-translate/core'; import { finalize } from 'rxjs/operators'; import { AuthService } from '../service/auth.service'; +import { LocalStorageService } from '../service/local-storage.service'; interface AfterViewInit { ngAfterViewInit(): void; @@ -41,10 +42,15 @@ export class SignaturePadPageComponent implements AfterViewInit { canvasHeight: 315 }; - constructor(private translate: TranslateService, public http: HttpClient, public signaturesService: SignaturesContentService, public notificationService: NotificationService, public authService: AuthService) { } + constructor(private translate: TranslateService, + public http: HttpClient, + public signaturesService: SignaturesContentService, + public notificationService: NotificationService, + public authService: AuthService, + private localStorage: LocalStorageService) { } ngAfterViewInit() { - const signPointsData = localStorage.getItem('signature'); + const signPointsData = this.localStorage.get('signature'); if (signPointsData) { // this.signaturePad.fromData( signPointsData ); } @@ -61,7 +67,7 @@ export class SignaturePadPageComponent implements AfterViewInit { } drawComplete() { - localStorage.setItem('signature', JSON.stringify(this.signaturePad.toData())); + this.localStorage.save('signature', JSON.stringify(this.signaturePad.toData())); this.haveSigned = true; } @@ -79,7 +85,7 @@ export class SignaturePadPageComponent implements AfterViewInit { this.disableState = true; this.haveSigned = true; const newEncodedSign = this.signaturePad.toDataURL('image/png').replace('data:image/png;base64,', ''); - localStorage.setItem('signature', JSON.stringify(newEncodedSign)); + this.localStorage.save('signature', JSON.stringify(newEncodedSign)); // Save signature in BDD const newSign = { @@ -99,13 +105,12 @@ export class SignaturePadPageComponent implements AfterViewInit { this.signaturesService.newSign = newSign; this.closePad(); this.reloaded.emit('reload'); - // this.store.dispatch({ type: HIDE_DRAWER }); this.signaturePad.clear(); this.notificationService.success('lang.signatureRegistered'); }); // BUG IMAGE CROPPED - // localStorage.setItem('signature', JSON.stringify(this.signaturePad.toDataURL('image/svg+xml'))); + // this.localStorage.save('signature', JSON.stringify(this.signaturePad.toDataURL('image/svg+xml'))); } } diff --git a/src/frontend/app/service/auth.service.ts b/src/frontend/app/service/auth.service.ts index bbbb922daee0497f01979a90b5cbe30bd00d9cb6..9f33b41d7ec28cb29d71cf810930079c65ecf65d 100755 --- a/src/frontend/app/service/auth.service.ts +++ b/src/frontend/app/service/auth.service.ts @@ -3,6 +3,7 @@ import { HttpClient } from '@angular/common/http'; import { Router } from '@angular/router'; import { NotificationService } from './notification.service'; import { SignaturesContentService } from './signatures.service'; +import { LocalStorageService } from './local-storage.service'; @Injectable({ providedIn: 'root' @@ -13,27 +14,31 @@ export class AuthService { changeKey: boolean = false; user: any = {}; - constructor(public http: HttpClient, private router: Router, public notificationService: NotificationService, public signaturesService: SignaturesContentService) { } + constructor(public http: HttpClient, + private router: Router, + public notificationService: NotificationService, + public signaturesService: SignaturesContentService, + private localStorage: LocalStorageService) { } getToken() { - return localStorage.getItem('MaarchParapheurToken'); + return this.localStorage.get('MaarchParapheurToken'); } setToken(token: string) { - localStorage.setItem('MaarchParapheurToken', token); + this.localStorage.save('MaarchParapheurToken', token); } getRefreshToken() { - return localStorage.getItem('MaarchParapheurRefreshToken'); + return this.localStorage.get('MaarchParapheurRefreshToken'); } setRefreshToken(refreshToken: string) { - localStorage.setItem('MaarchParapheurRefreshToken', refreshToken); + this.localStorage.save('MaarchParapheurRefreshToken', refreshToken); } clearTokens() { - localStorage.removeItem('MaarchParapheurToken'); - localStorage.removeItem('MaarchParapheurRefreshToken'); + this.localStorage.remove('MaarchParapheurToken'); + this.localStorage.remove('MaarchParapheurRefreshToken'); } logout() { @@ -47,7 +52,7 @@ export class AuthService { } isAuth(): boolean { - return this.getToken() !== null + return this.getToken() !== null; } updateUserInfo(token: string) { diff --git a/src/frontend/app/service/local-storage.service.ts b/src/frontend/app/service/local-storage.service.ts new file mode 100644 index 0000000000000000000000000000000000000000..99cf06c3cadd99b6c0eabce1f39fa72b6bd8adaf --- /dev/null +++ b/src/frontend/app/service/local-storage.service.ts @@ -0,0 +1,30 @@ +import { Injectable } from '@angular/core'; + +@Injectable({ + providedIn: 'root' +}) +export class LocalStorageService { + appSession: any; + + constructor() {} + + setAppSession(id: string) { + this.appSession = id; + } + + getAppSession(): string { + return this.appSession; + } + + save(id: string, content: any) { + localStorage.setItem(id + '_' + this.getAppSession(), content); + } + + get(id: string) { + return localStorage.getItem(id + '_' + this.getAppSession()); + } + + remove(id: string) { + localStorage.removeItem(id + '_' + this.getAppSession()); + } +} diff --git a/src/frontend/app/service/signatures.service.ts b/src/frontend/app/service/signatures.service.ts index 6e2611cedadd12aae1dfb9a7ccd005f81ade5932..71d30a0198dd8ac9d7727889161c8d54189dca71 100755 --- a/src/frontend/app/service/signatures.service.ts +++ b/src/frontend/app/service/signatures.service.ts @@ -37,8 +37,10 @@ export class SignaturesContentService { x = 0; y = 90; mainLoading = true; + appSession: any; constructor() { + console.log(location); if (window.screen.width <= 360) { this.smartphoneMode = true; } else { @@ -104,4 +106,8 @@ export class SignaturesContentService { this.x = 0; this.y = 90; } + + getAppSession() { + this.appSession = 'AD098AD9ADA0D9IAXKJ90AKS099S'; + } } diff --git a/src/frontend/app/signatures/signatures.component.ts b/src/frontend/app/signatures/signatures.component.ts index fce3f739aa026ac7a611cba39cf66b7240c46cfa..79b2dc82222b30514938599cf38a6772492769d6 100755 --- a/src/frontend/app/signatures/signatures.component.ts +++ b/src/frontend/app/signatures/signatures.component.ts @@ -8,6 +8,7 @@ import { trigger, transition, style, animate, stagger, query } from '@angular/an import { NotificationService } from '../service/notification.service'; import { TranslateService } from '@ngx-translate/core'; import { AuthService } from '../service/auth.service'; +import { LocalStorageService } from '../service/local-storage.service'; @Component({ selector: 'app-signatures', @@ -31,8 +32,14 @@ export class SignaturesComponent implements OnInit { inAllPage = false; count = 0; - constructor(private translate: TranslateService, public http: HttpClient, public signaturesService: SignaturesContentService, private bottomSheetRef: MatBottomSheet, - private sanitization: DomSanitizer, public notificationService: NotificationService, public authService: AuthService) { + constructor(private translate: TranslateService, + public http: HttpClient, + public signaturesService: SignaturesContentService, + private bottomSheetRef: MatBottomSheet, + private sanitization: DomSanitizer, + public notificationService: NotificationService, + public authService: AuthService, + private localStorage: LocalStorageService) { } ngOnInit() { @@ -71,7 +78,7 @@ export class SignaturesComponent implements OnInit { this.signaturesService.signaturesContent[this.signaturesService.currentPage] = []; } this.signaturesService.signaturesContent[this.signaturesService.currentPage].push(JSON.parse(JSON.stringify(signature))); - localStorage.setItem(this.signaturesService.mainDocumentId.toString(), JSON.stringify({'sign' : this.signaturesService.signaturesContent, 'note' : this.signaturesService.notesContent})); + this.localStorage.save(this.signaturesService.mainDocumentId.toString(), JSON.stringify({'sign' : this.signaturesService.signaturesContent, 'note' : this.signaturesService.notesContent})); this.bottomSheetRef.dismiss(); } @@ -128,7 +135,7 @@ export class SignaturesComponent implements OnInit { myReader.onloadend = (e) => { const newEncodedSign = myReader.result.toString().replace('data:' + fileToUpload.type + ';base64,', ''); - localStorage.setItem('signature', JSON.stringify(newEncodedSign)); + this.localStorage.save('signature', JSON.stringify(newEncodedSign)); // Save signature in BDD const newSign = {