Add button Copy JWT token to profile

This commit is contained in:
ArtemDzhereleiko 2021-09-21 18:15:20 +03:00
parent 75817a16f4
commit 06708c4746
5 changed files with 43 additions and 4 deletions

View File

@ -84,6 +84,15 @@
{{'profile.change-password' | translate}}
</button>
</div>
<div fxLayout="row" fxLayoutAlign=" center" style="padding-bottom: 16px;">
<button mat-raised-button ngxClipboard
(cbOnSuccess)="onTokenCopied($event)"
[cbContent]="token">
<mat-icon svgIcon="mdi:clipboard-arrow-left"></mat-icon>
<span>{{ 'profile.copy-jwt-token' | translate }}</span>
</button>
<span style="padding: 10px; opacity: 0.7;">{{getExpirationDate}}</span>
</div>
<div fxLayout="row" class="layout-wrap">
<span fxFlex></span>
<button mat-button mat-raised-button color="primary"

View File

@ -34,6 +34,8 @@ import { AuthService } from '@core/auth/auth.service';
import { ActivatedRoute } from '@angular/router';
import { isDefinedAndNotNull } from '@core/utils';
import { getCurrentAuthUser } from '@core/auth/auth.selectors';
import {ActionNotificationShow} from "@core/notification/notification.actions";
import { DatePipe } from '@angular/common';
@Component({
selector: 'tb-profile',
@ -48,6 +50,15 @@ export class ProfileComponent extends PageComponent implements OnInit, HasConfir
languageList = env.supportedLangs;
private readonly authUser: AuthUser;
get token() {
return `Bearer ${localStorage.getItem('jwt_token')}`;
}
get getExpirationDate() {
const expirationData = this.datePipe.transform(localStorage.getItem('jwt_token_expiration'), 'yyyy-MM-dd HH:mm:ss');
return this.translate.instant('profile.valid-till', {expirationData});
};
constructor(protected store: Store<AppState>,
private route: ActivatedRoute,
private userService: UserService,
@ -55,7 +66,8 @@ export class ProfileComponent extends PageComponent implements OnInit, HasConfir
private translate: TranslateService,
public dialog: MatDialog,
public dialogService: DialogService,
public fb: FormBuilder) {
public fb: FormBuilder,
private datePipe: DatePipe) {
super(store);
this.authUser = getCurrentAuthUser(this.store);
}
@ -141,4 +153,13 @@ export class ProfileComponent extends PageComponent implements OnInit, HasConfir
return this.authUser.authority === Authority.SYS_ADMIN;
}
onTokenCopied($event) {
this.store.dispatch(new ActionNotificationShow({
message: this.translate.instant('profile.tokenCopiedMessage'),
type: 'success',
duration: 750,
verticalPosition: 'bottom',
horizontalPosition: 'right'
}));
}
}

View File

@ -2364,7 +2364,10 @@
"profile": "Profile",
"last-login-time": "Last Login",
"change-password": "Change Password",
"current-password": "Current password"
"current-password": "Current password",
"copy-jwt-token": "Copy JWT token",
"valid-till": "Valid till {{expirationData}}",
"tokenCopiedMessage": "JWT token has been copied to clipboard"
},
"relation": {
"relations": "Relations",

View File

@ -1262,7 +1262,10 @@
"profile": "Профиль",
"last-login-time": "Время последнего входа в систему",
"change-password": "Изменить пароль",
"current-password": "Текущий пароль"
"current-password": "Текущий пароль",
"copy-jwt-token": "Копировать JWT токен",
"valid-till": "Годен до {{expirationData}}",
"tokenCopiedMessage": "JWT токен скопирован в буфер обмена"
},
"relation": {
"relations": "Отношения",

View File

@ -1677,7 +1677,10 @@
"profile": "Профіль",
"last-login-time": "Час останнього входу",
"change-password": "Змінити пароль",
"current-password": "Поточний пароль"
"current-password": "Поточний пароль",
"copy-jwt-token": "Копіювати JWT токен",
"valid-till": "Придатний до {{expirationData}}",
"tokenCopiedMessage": "JWT токен скопійовано в буфер обміну"
},
"relation": {
"relations": "Відношення",