Commit b57a58712ea5d25ed0fc1d1d15b351112f9c7e6e

Authored by ArtemDzhereleiko
1 parent 942cadfc

Add warning tooltip if token expiration time out

... ... @@ -85,9 +85,9 @@
85 85 </button>
86 86 </div>
87 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 91 <mat-icon svgIcon="mdi:clipboard-arrow-left"></mat-icon>
92 92 <span>{{ 'profile.copy-jwt-token' | translate }}</span>
93 93 </button>
... ...
... ... @@ -36,6 +36,7 @@ import { isDefinedAndNotNull } from '@core/utils';
36 36 import { getCurrentAuthUser } from '@core/auth/auth.selectors';
37 37 import { ActionNotificationShow } from '@core/notification/notification.actions';
38 38 import { DatePipe } from '@angular/common';
  39 +import { ClipboardService } from 'ngx-clipboard';
39 40
40 41 @Component({
41 42 selector: 'tb-profile',
... ... @@ -54,8 +55,12 @@ export class ProfileComponent extends PageComponent implements OnInit, HasConfir
54 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 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 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 72 public dialog: MatDialog,
68 73 public dialogService: DialogService,
69 74 public fb: FormBuilder,
70   - private datePipe: DatePipe) {
  75 + private datePipe: DatePipe,
  76 + private clipboardService: ClipboardService) {
71 77 super(store);
72 78 this.authUser = getCurrentAuthUser(this.store);
73 79 }
... ... @@ -153,13 +159,24 @@ export class ProfileComponent extends PageComponent implements OnInit, HasConfir
153 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 2367 "current-password": "Current password",
2368 2368 "copy-jwt-token": "Copy JWT token",
2369 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 2373 "relation": {
2373 2374 "relations": "Relations",
... ...
... ... @@ -1265,7 +1265,8 @@
1265 1265 "current-password": "Текущий пароль",
1266 1266 "copy-jwt-token": "Копировать JWT токен",
1267 1267 "valid-till": "Действителен до {{expirationData}}",
1268   - "tokenCopiedMessage": "JWT токен скопирован в буфер обмена"
  1268 + "tokenCopiedMessage": "JWT токен скопирован в буфер обмена",
  1269 + "tokenCopiedWarnMessage": "JWT токен недействителен! Перезагрузите страницу."
1269 1270 },
1270 1271 "relation": {
1271 1272 "relations": "Отношения",
... ...
... ... @@ -1680,7 +1680,8 @@
1680 1680 "current-password": "Поточний пароль",
1681 1681 "copy-jwt-token": "Копіювати JWT токен",
1682 1682 "valid-till": "Дійсний до {{expirationData}}",
1683   - "tokenCopiedMessage": "JWT токен скопійовано в буфер обміну"
  1683 + "tokenCopiedMessage": "JWT токен скопійовано в буфер обміну",
  1684 + "tokenCopiedWarnMessage": "JWT токен не є дійсним! Перезавантажте сторінку."
1684 1685 },
1685 1686 "relation": {
1686 1687 "relations": "Відношення",
... ...