Commit 06708c4746a800af901b86956c9e89c2db8b19fe
1 parent
75817a16
Add button Copy JWT token to profile
Showing
5 changed files
with
43 additions
and
4 deletions
@@ -84,6 +84,15 @@ | @@ -84,6 +84,15 @@ | ||
84 | {{'profile.change-password' | translate}} | 84 | {{'profile.change-password' | translate}} |
85 | </button> | 85 | </button> |
86 | </div> | 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 | <div fxLayout="row" class="layout-wrap"> | 96 | <div fxLayout="row" class="layout-wrap"> |
88 | <span fxFlex></span> | 97 | <span fxFlex></span> |
89 | <button mat-button mat-raised-button color="primary" | 98 | <button mat-button mat-raised-button color="primary" |
@@ -34,6 +34,8 @@ import { AuthService } from '@core/auth/auth.service'; | @@ -34,6 +34,8 @@ import { AuthService } from '@core/auth/auth.service'; | ||
34 | import { ActivatedRoute } from '@angular/router'; | 34 | import { ActivatedRoute } from '@angular/router'; |
35 | import { isDefinedAndNotNull } from '@core/utils'; | 35 | 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"; | ||
38 | +import { DatePipe } from '@angular/common'; | ||
37 | 39 | ||
38 | @Component({ | 40 | @Component({ |
39 | selector: 'tb-profile', | 41 | selector: 'tb-profile', |
@@ -48,6 +50,15 @@ export class ProfileComponent extends PageComponent implements OnInit, HasConfir | @@ -48,6 +50,15 @@ export class ProfileComponent extends PageComponent implements OnInit, HasConfir | ||
48 | languageList = env.supportedLangs; | 50 | languageList = env.supportedLangs; |
49 | private readonly authUser: AuthUser; | 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 | constructor(protected store: Store<AppState>, | 62 | constructor(protected store: Store<AppState>, |
52 | private route: ActivatedRoute, | 63 | private route: ActivatedRoute, |
53 | private userService: UserService, | 64 | private userService: UserService, |
@@ -55,7 +66,8 @@ export class ProfileComponent extends PageComponent implements OnInit, HasConfir | @@ -55,7 +66,8 @@ export class ProfileComponent extends PageComponent implements OnInit, HasConfir | ||
55 | private translate: TranslateService, | 66 | private translate: TranslateService, |
56 | public dialog: MatDialog, | 67 | public dialog: MatDialog, |
57 | public dialogService: DialogService, | 68 | public dialogService: DialogService, |
58 | - public fb: FormBuilder) { | 69 | + public fb: FormBuilder, |
70 | + private datePipe: DatePipe) { | ||
59 | super(store); | 71 | super(store); |
60 | this.authUser = getCurrentAuthUser(this.store); | 72 | this.authUser = getCurrentAuthUser(this.store); |
61 | } | 73 | } |
@@ -141,4 +153,13 @@ export class ProfileComponent extends PageComponent implements OnInit, HasConfir | @@ -141,4 +153,13 @@ export class ProfileComponent extends PageComponent implements OnInit, HasConfir | ||
141 | return this.authUser.authority === Authority.SYS_ADMIN; | 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,7 +2364,10 @@ | ||
2364 | "profile": "Profile", | 2364 | "profile": "Profile", |
2365 | "last-login-time": "Last Login", | 2365 | "last-login-time": "Last Login", |
2366 | "change-password": "Change Password", | 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 | "relation": { | 2372 | "relation": { |
2370 | "relations": "Relations", | 2373 | "relations": "Relations", |
@@ -1262,7 +1262,10 @@ | @@ -1262,7 +1262,10 @@ | ||
1262 | "profile": "Профиль", | 1262 | "profile": "Профиль", |
1263 | "last-login-time": "Время последнего входа в систему", | 1263 | "last-login-time": "Время последнего входа в систему", |
1264 | "change-password": "Изменить пароль", | 1264 | "change-password": "Изменить пароль", |
1265 | - "current-password": "Текущий пароль" | 1265 | + "current-password": "Текущий пароль", |
1266 | + "copy-jwt-token": "Копировать JWT токен", | ||
1267 | + "valid-till": "Годен до {{expirationData}}", | ||
1268 | + "tokenCopiedMessage": "JWT токен скопирован в буфер обмена" | ||
1266 | }, | 1269 | }, |
1267 | "relation": { | 1270 | "relation": { |
1268 | "relations": "Отношения", | 1271 | "relations": "Отношения", |
@@ -1677,7 +1677,10 @@ | @@ -1677,7 +1677,10 @@ | ||
1677 | "profile": "Профіль", | 1677 | "profile": "Профіль", |
1678 | "last-login-time": "Час останнього входу", | 1678 | "last-login-time": "Час останнього входу", |
1679 | "change-password": "Змінити пароль", | 1679 | "change-password": "Змінити пароль", |
1680 | - "current-password": "Поточний пароль" | 1680 | + "current-password": "Поточний пароль", |
1681 | + "copy-jwt-token": "Копіювати JWT токен", | ||
1682 | + "valid-till": "Придатний до {{expirationData}}", | ||
1683 | + "tokenCopiedMessage": "JWT токен скопійовано в буфер обміну" | ||
1681 | }, | 1684 | }, |
1682 | "relation": { | 1685 | "relation": { |
1683 | "relations": "Відношення", | 1686 | "relations": "Відношення", |