Add warning tooltip if token expiration time out
This commit is contained in:
parent
942cadfc73
commit
b57a58712e
@ -85,9 +85,9 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div fxLayout="row" fxLayoutAlign=" center" style="padding-bottom: 16px;">
|
<div fxLayout="row" fxLayoutAlign=" center" style="padding-bottom: 16px;">
|
||||||
<button mat-raised-button ngxClipboard
|
<button mat-raised-button
|
||||||
(cbOnSuccess)="onTokenCopied()"
|
type="button"
|
||||||
[cbContent]="jwtToken">
|
(click)="copyToken()">
|
||||||
<mat-icon svgIcon="mdi:clipboard-arrow-left"></mat-icon>
|
<mat-icon svgIcon="mdi:clipboard-arrow-left"></mat-icon>
|
||||||
<span>{{ 'profile.copy-jwt-token' | translate }}</span>
|
<span>{{ 'profile.copy-jwt-token' | translate }}</span>
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@ -36,6 +36,7 @@ import { isDefinedAndNotNull } from '@core/utils';
|
|||||||
import { getCurrentAuthUser } from '@core/auth/auth.selectors';
|
import { getCurrentAuthUser } from '@core/auth/auth.selectors';
|
||||||
import { ActionNotificationShow } from '@core/notification/notification.actions';
|
import { ActionNotificationShow } from '@core/notification/notification.actions';
|
||||||
import { DatePipe } from '@angular/common';
|
import { DatePipe } from '@angular/common';
|
||||||
|
import { ClipboardService } from 'ngx-clipboard';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'tb-profile',
|
selector: 'tb-profile',
|
||||||
@ -54,8 +55,12 @@ export class ProfileComponent extends PageComponent implements OnInit, HasConfir
|
|||||||
return `Bearer ${localStorage.getItem('jwt_token')}`;
|
return `Bearer ${localStorage.getItem('jwt_token')}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get jwtTokenExpiration(): string {
|
||||||
|
return localStorage.getItem('jwt_token_expiration');
|
||||||
|
}
|
||||||
|
|
||||||
get expirationJwtData(): string {
|
get expirationJwtData(): string {
|
||||||
const expirationData = this.datePipe.transform(localStorage.getItem('jwt_token_expiration'), 'yyyy-MM-dd HH:mm:ss');
|
const expirationData = this.datePipe.transform(this.jwtTokenExpiration, 'yyyy-MM-dd HH:mm:ss');
|
||||||
return this.translate.instant('profile.valid-till', { expirationData });
|
return this.translate.instant('profile.valid-till', { expirationData });
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,7 +72,8 @@ export class ProfileComponent extends PageComponent implements OnInit, HasConfir
|
|||||||
public dialog: MatDialog,
|
public dialog: MatDialog,
|
||||||
public dialogService: DialogService,
|
public dialogService: DialogService,
|
||||||
public fb: FormBuilder,
|
public fb: FormBuilder,
|
||||||
private datePipe: DatePipe) {
|
private datePipe: DatePipe,
|
||||||
|
private clipboardService: ClipboardService) {
|
||||||
super(store);
|
super(store);
|
||||||
this.authUser = getCurrentAuthUser(this.store);
|
this.authUser = getCurrentAuthUser(this.store);
|
||||||
}
|
}
|
||||||
@ -153,9 +159,19 @@ export class ProfileComponent extends PageComponent implements OnInit, HasConfir
|
|||||||
return this.authUser.authority === Authority.SYS_ADMIN;
|
return this.authUser.authority === Authority.SYS_ADMIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
onTokenCopied() {
|
copyToken() {
|
||||||
|
if (+this.jwtTokenExpiration < Date.now()) {
|
||||||
this.store.dispatch(new ActionNotificationShow({
|
this.store.dispatch(new ActionNotificationShow({
|
||||||
message: this.translate.instant('profile.tokenCopiedMessage'),
|
message: this.translate.instant('profile.tokenCopiedWarnMessage'),
|
||||||
|
type: 'warn',
|
||||||
|
duration: 1500,
|
||||||
|
verticalPosition: 'bottom',
|
||||||
|
horizontalPosition: 'right'
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
this.clipboardService.copyFromContent(this.jwtToken);
|
||||||
|
this.store.dispatch(new ActionNotificationShow({
|
||||||
|
message: this.translate.instant('profile.tokenCopiedSuccessMessage'),
|
||||||
type: 'success',
|
type: 'success',
|
||||||
duration: 750,
|
duration: 750,
|
||||||
verticalPosition: 'bottom',
|
verticalPosition: 'bottom',
|
||||||
@ -163,3 +179,4 @@ export class ProfileComponent extends PageComponent implements OnInit, HasConfir
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -2367,7 +2367,8 @@
|
|||||||
"current-password": "Current password",
|
"current-password": "Current password",
|
||||||
"copy-jwt-token": "Copy JWT token",
|
"copy-jwt-token": "Copy JWT token",
|
||||||
"valid-till": "Valid till {{expirationData}}",
|
"valid-till": "Valid till {{expirationData}}",
|
||||||
"tokenCopiedMessage": "JWT token has been copied to clipboard"
|
"tokenCopiedSuccessMessage": "JWT token has been copied to clipboard",
|
||||||
|
"tokenCopiedWarnMessage": "JWT token is expired! Please, refresh the page."
|
||||||
},
|
},
|
||||||
"relation": {
|
"relation": {
|
||||||
"relations": "Relations",
|
"relations": "Relations",
|
||||||
|
|||||||
@ -1265,7 +1265,8 @@
|
|||||||
"current-password": "Текущий пароль",
|
"current-password": "Текущий пароль",
|
||||||
"copy-jwt-token": "Копировать JWT токен",
|
"copy-jwt-token": "Копировать JWT токен",
|
||||||
"valid-till": "Действителен до {{expirationData}}",
|
"valid-till": "Действителен до {{expirationData}}",
|
||||||
"tokenCopiedMessage": "JWT токен скопирован в буфер обмена"
|
"tokenCopiedMessage": "JWT токен скопирован в буфер обмена",
|
||||||
|
"tokenCopiedWarnMessage": "JWT токен недействителен! Перезагрузите страницу."
|
||||||
},
|
},
|
||||||
"relation": {
|
"relation": {
|
||||||
"relations": "Отношения",
|
"relations": "Отношения",
|
||||||
|
|||||||
@ -1680,7 +1680,8 @@
|
|||||||
"current-password": "Поточний пароль",
|
"current-password": "Поточний пароль",
|
||||||
"copy-jwt-token": "Копіювати JWT токен",
|
"copy-jwt-token": "Копіювати JWT токен",
|
||||||
"valid-till": "Дійсний до {{expirationData}}",
|
"valid-till": "Дійсний до {{expirationData}}",
|
||||||
"tokenCopiedMessage": "JWT токен скопійовано в буфер обміну"
|
"tokenCopiedMessage": "JWT токен скопійовано в буфер обміну",
|
||||||
|
"tokenCopiedWarnMessage": "JWT токен не є дійсним! Перезавантажте сторінку."
|
||||||
},
|
},
|
||||||
"relation": {
|
"relation": {
|
||||||
"relations": "Відношення",
|
"relations": "Відношення",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user