Commit 06708c4746a800af901b86956c9e89c2db8b19fe

Authored by ArtemDzhereleiko
1 parent 75817a16

Add button Copy JWT token to profile

... ... @@ -84,6 +84,15 @@
84 84 {{'profile.change-password' | translate}}
85 85 </button>
86 86 </div>
  87 + <div fxLayout="row" fxLayoutAlign=" center" style="padding-bottom: 16px;">
  88 + <button mat-raised-button ngxClipboard
  89 + (cbOnSuccess)="onTokenCopied($event)"
  90 + [cbContent]="token">
  91 + <mat-icon svgIcon="mdi:clipboard-arrow-left"></mat-icon>
  92 + <span>{{ 'profile.copy-jwt-token' | translate }}</span>
  93 + </button>
  94 + <span style="padding: 10px; opacity: 0.7;">{{getExpirationDate}}</span>
  95 + </div>
87 96 <div fxLayout="row" class="layout-wrap">
88 97 <span fxFlex></span>
89 98 <button mat-button mat-raised-button color="primary"
... ...
... ... @@ -34,6 +34,8 @@ import { AuthService } from '@core/auth/auth.service';
34 34 import { ActivatedRoute } from '@angular/router';
35 35 import { isDefinedAndNotNull } from '@core/utils';
36 36 import { getCurrentAuthUser } from '@core/auth/auth.selectors';
  37 +import {ActionNotificationShow} from "@core/notification/notification.actions";
  38 +import { DatePipe } from '@angular/common';
37 39
38 40 @Component({
39 41 selector: 'tb-profile',
... ... @@ -48,6 +50,15 @@ export class ProfileComponent extends PageComponent implements OnInit, HasConfir
48 50 languageList = env.supportedLangs;
49 51 private readonly authUser: AuthUser;
50 52
  53 + get token() {
  54 + return `Bearer ${localStorage.getItem('jwt_token')}`;
  55 + }
  56 +
  57 + get getExpirationDate() {
  58 + const expirationData = this.datePipe.transform(localStorage.getItem('jwt_token_expiration'), 'yyyy-MM-dd HH:mm:ss');
  59 + return this.translate.instant('profile.valid-till', {expirationData});
  60 + };
  61 +
51 62 constructor(protected store: Store<AppState>,
52 63 private route: ActivatedRoute,
53 64 private userService: UserService,
... ... @@ -55,7 +66,8 @@ export class ProfileComponent extends PageComponent implements OnInit, HasConfir
55 66 private translate: TranslateService,
56 67 public dialog: MatDialog,
57 68 public dialogService: DialogService,
58   - public fb: FormBuilder) {
  69 + public fb: FormBuilder,
  70 + private datePipe: DatePipe) {
59 71 super(store);
60 72 this.authUser = getCurrentAuthUser(this.store);
61 73 }
... ... @@ -141,4 +153,13 @@ export class ProfileComponent extends PageComponent implements OnInit, HasConfir
141 153 return this.authUser.authority === Authority.SYS_ADMIN;
142 154 }
143 155
  156 + onTokenCopied($event) {
  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 + }));
  164 + }
144 165 }
... ...
... ... @@ -2364,7 +2364,10 @@
2364 2364 "profile": "Profile",
2365 2365 "last-login-time": "Last Login",
2366 2366 "change-password": "Change Password",
2367   - "current-password": "Current password"
  2367 + "current-password": "Current password",
  2368 + "copy-jwt-token": "Copy JWT token",
  2369 + "valid-till": "Valid till {{expirationData}}",
  2370 + "tokenCopiedMessage": "JWT token has been copied to clipboard"
2368 2371 },
2369 2372 "relation": {
2370 2373 "relations": "Relations",
... ...
... ... @@ -1262,7 +1262,10 @@
1262 1262 "profile": "Профиль",
1263 1263 "last-login-time": "Время последнего входа в систему",
1264 1264 "change-password": "Изменить пароль",
1265   - "current-password": "Текущий пароль"
  1265 + "current-password": "Текущий пароль",
  1266 + "copy-jwt-token": "Копировать JWT токен",
  1267 + "valid-till": "Годен до {{expirationData}}",
  1268 + "tokenCopiedMessage": "JWT токен скопирован в буфер обмена"
1266 1269 },
1267 1270 "relation": {
1268 1271 "relations": "Отношения",
... ...
... ... @@ -1677,7 +1677,10 @@
1677 1677 "profile": "Профіль",
1678 1678 "last-login-time": "Час останнього входу",
1679 1679 "change-password": "Змінити пароль",
1680   - "current-password": "Поточний пароль"
  1680 + "current-password": "Поточний пароль",
  1681 + "copy-jwt-token": "Копіювати JWT токен",
  1682 + "valid-till": "Придатний до {{expirationData}}",
  1683 + "tokenCopiedMessage": "JWT токен скопійовано в буфер обміну"
1681 1684 },
1682 1685 "relation": {
1683 1686 "relations": "Відношення",
... ...