Commit b57a58712ea5d25ed0fc1d1d15b351112f9c7e6e

Authored by ArtemDzhereleiko
1 parent 942cadfc

Add warning tooltip if token expiration time out

@@ -85,9 +85,9 @@ @@ -85,9 +85,9 @@
85 </button> 85 </button>
86 </div> 86 </div>
87 <div fxLayout="row" fxLayoutAlign=" center" style="padding-bottom: 16px;"> 87 <div fxLayout="row" fxLayoutAlign=" center" style="padding-bottom: 16px;">
88 - <button mat-raised-button ngxClipboard  
89 - (cbOnSuccess)="onTokenCopied()"  
90 - [cbContent]="jwtToken"> 88 + <button mat-raised-button
  89 + type="button"
  90 + (click)="copyToken()">
91 <mat-icon svgIcon="mdi:clipboard-arrow-left"></mat-icon> 91 <mat-icon svgIcon="mdi:clipboard-arrow-left"></mat-icon>
92 <span>{{ 'profile.copy-jwt-token' | translate }}</span> 92 <span>{{ 'profile.copy-jwt-token' | translate }}</span>
93 </button> 93 </button>
@@ -36,6 +36,7 @@ import { isDefinedAndNotNull } from '@core/utils'; @@ -36,6 +36,7 @@ import { isDefinedAndNotNull } from '@core/utils';
36 import { getCurrentAuthUser } from '@core/auth/auth.selectors'; 36 import { getCurrentAuthUser } from '@core/auth/auth.selectors';
37 import { ActionNotificationShow } from '@core/notification/notification.actions'; 37 import { ActionNotificationShow } from '@core/notification/notification.actions';
38 import { DatePipe } from '@angular/common'; 38 import { DatePipe } from '@angular/common';
  39 +import { ClipboardService } from 'ngx-clipboard';
39 40
40 @Component({ 41 @Component({
41 selector: 'tb-profile', 42 selector: 'tb-profile',
@@ -54,8 +55,12 @@ export class ProfileComponent extends PageComponent implements OnInit, HasConfir @@ -54,8 +55,12 @@ export class ProfileComponent extends PageComponent implements OnInit, HasConfir
54 return `Bearer ${localStorage.getItem('jwt_token')}`; 55 return `Bearer ${localStorage.getItem('jwt_token')}`;
55 } 56 }
56 57
  58 + get jwtTokenExpiration(): string {
  59 + return localStorage.getItem('jwt_token_expiration');
  60 + }
  61 +
57 get expirationJwtData(): string { 62 get expirationJwtData(): string {
58 - const expirationData = this.datePipe.transform(localStorage.getItem('jwt_token_expiration'), 'yyyy-MM-dd HH:mm:ss'); 63 + const expirationData = this.datePipe.transform(this.jwtTokenExpiration, 'yyyy-MM-dd HH:mm:ss');
59 return this.translate.instant('profile.valid-till', { expirationData }); 64 return this.translate.instant('profile.valid-till', { expirationData });
60 } 65 }
61 66
@@ -67,7 +72,8 @@ export class ProfileComponent extends PageComponent implements OnInit, HasConfir @@ -67,7 +72,8 @@ export class ProfileComponent extends PageComponent implements OnInit, HasConfir
67 public dialog: MatDialog, 72 public dialog: MatDialog,
68 public dialogService: DialogService, 73 public dialogService: DialogService,
69 public fb: FormBuilder, 74 public fb: FormBuilder,
70 - private datePipe: DatePipe) { 75 + private datePipe: DatePipe,
  76 + private clipboardService: ClipboardService) {
71 super(store); 77 super(store);
72 this.authUser = getCurrentAuthUser(this.store); 78 this.authUser = getCurrentAuthUser(this.store);
73 } 79 }
@@ -153,13 +159,24 @@ export class ProfileComponent extends PageComponent implements OnInit, HasConfir @@ -153,13 +159,24 @@ export class ProfileComponent extends PageComponent implements OnInit, HasConfir
153 return this.authUser.authority === Authority.SYS_ADMIN; 159 return this.authUser.authority === Authority.SYS_ADMIN;
154 } 160 }
155 161
156 - onTokenCopied() {  
157 - this.store.dispatch(new ActionNotificationShow({  
158 - message: this.translate.instant('profile.tokenCopiedMessage'),  
159 - type: 'success',  
160 - duration: 750,  
161 - verticalPosition: 'bottom',  
162 - horizontalPosition: 'right'  
163 - })); 162 + copyToken() {
  163 + if (+this.jwtTokenExpiration < Date.now()) {
  164 + this.store.dispatch(new ActionNotificationShow({
  165 + message: this.translate.instant('profile.tokenCopiedWarnMessage'),
  166 + type: 'warn',
  167 + duration: 1500,
  168 + verticalPosition: 'bottom',
  169 + horizontalPosition: 'right'
  170 + }));
  171 + } else {
  172 + this.clipboardService.copyFromContent(this.jwtToken);
  173 + this.store.dispatch(new ActionNotificationShow({
  174 + message: this.translate.instant('profile.tokenCopiedSuccessMessage'),
  175 + type: 'success',
  176 + duration: 750,
  177 + verticalPosition: 'bottom',
  178 + horizontalPosition: 'right'
  179 + }));
  180 + }
164 } 181 }
165 } 182 }
@@ -2367,7 +2367,8 @@ @@ -2367,7 +2367,8 @@
2367 "current-password": "Current password", 2367 "current-password": "Current password",
2368 "copy-jwt-token": "Copy JWT token", 2368 "copy-jwt-token": "Copy JWT token",
2369 "valid-till": "Valid till {{expirationData}}", 2369 "valid-till": "Valid till {{expirationData}}",
2370 - "tokenCopiedMessage": "JWT token has been copied to clipboard" 2370 + "tokenCopiedSuccessMessage": "JWT token has been copied to clipboard",
  2371 + "tokenCopiedWarnMessage": "JWT token is expired! Please, refresh the page."
2371 }, 2372 },
2372 "relation": { 2373 "relation": {
2373 "relations": "Relations", 2374 "relations": "Relations",
@@ -1265,7 +1265,8 @@ @@ -1265,7 +1265,8 @@
1265 "current-password": "Текущий пароль", 1265 "current-password": "Текущий пароль",
1266 "copy-jwt-token": "Копировать JWT токен", 1266 "copy-jwt-token": "Копировать JWT токен",
1267 "valid-till": "Действителен до {{expirationData}}", 1267 "valid-till": "Действителен до {{expirationData}}",
1268 - "tokenCopiedMessage": "JWT токен скопирован в буфер обмена" 1268 + "tokenCopiedMessage": "JWT токен скопирован в буфер обмена",
  1269 + "tokenCopiedWarnMessage": "JWT токен недействителен! Перезагрузите страницу."
1269 }, 1270 },
1270 "relation": { 1271 "relation": {
1271 "relations": "Отношения", 1272 "relations": "Отношения",
@@ -1680,7 +1680,8 @@ @@ -1680,7 +1680,8 @@
1680 "current-password": "Поточний пароль", 1680 "current-password": "Поточний пароль",
1681 "copy-jwt-token": "Копіювати JWT токен", 1681 "copy-jwt-token": "Копіювати JWT токен",
1682 "valid-till": "Дійсний до {{expirationData}}", 1682 "valid-till": "Дійсний до {{expirationData}}",
1683 - "tokenCopiedMessage": "JWT токен скопійовано в буфер обміну" 1683 + "tokenCopiedMessage": "JWT токен скопійовано в буфер обміну",
  1684 + "tokenCopiedWarnMessage": "JWT токен не є дійсним! Перезавантажте сторінку."
1684 }, 1685 },
1685 "relation": { 1686 "relation": {
1686 "relations": "Відношення", 1687 "relations": "Відношення",