|
|
@ -1,5 +1,8 @@ |
|
|
|
import { CreateAccessDto } from '@ghostfolio/api/app/access/create-access.dto'; |
|
|
|
import { ConfirmationDialogType } from '@ghostfolio/client/core/notification/confirmation-dialog/confirmation-dialog.type'; |
|
|
|
import { NotificationService } from '@ghostfolio/client/core/notification/notification.service'; |
|
|
|
import { DataService } from '@ghostfolio/client/services/data.service'; |
|
|
|
import { TokenStorageService } from '@ghostfolio/client/services/token-storage.service'; |
|
|
|
import { UserService } from '@ghostfolio/client/services/user/user.service'; |
|
|
|
import { Access, User } from '@ghostfolio/common/interfaces'; |
|
|
|
import { hasPermission, permissions } from '@ghostfolio/common/permissions'; |
|
|
@ -11,11 +14,12 @@ import { |
|
|
|
OnDestroy, |
|
|
|
OnInit |
|
|
|
} from '@angular/core'; |
|
|
|
import { FormBuilder, Validators } from '@angular/forms'; |
|
|
|
import { MatDialog } from '@angular/material/dialog'; |
|
|
|
import { ActivatedRoute, Router } from '@angular/router'; |
|
|
|
import { DeviceDetectorService } from 'ngx-device-detector'; |
|
|
|
import { Subject } from 'rxjs'; |
|
|
|
import { takeUntil } from 'rxjs/operators'; |
|
|
|
import { EMPTY, Subject } from 'rxjs'; |
|
|
|
import { catchError, takeUntil } from 'rxjs/operators'; |
|
|
|
|
|
|
|
import { CreateOrUpdateAccessDialog } from './create-or-update-access-dialog/create-or-update-access-dialog.component'; |
|
|
|
|
|
|
@ -33,6 +37,11 @@ export class UserAccountAccessComponent implements OnDestroy, OnInit { |
|
|
|
public deviceType: string; |
|
|
|
public hasPermissionToCreateAccess: boolean; |
|
|
|
public hasPermissionToDeleteAccess: boolean; |
|
|
|
public hasPermissionToUpdateOwnAccessToken: boolean; |
|
|
|
public isAccessTokenHidden = true; |
|
|
|
public updateOwnAccessTokenForm = this.formBuilder.group({ |
|
|
|
accessToken: ['', Validators.required] |
|
|
|
}); |
|
|
|
public user: User; |
|
|
|
|
|
|
|
private unsubscribeSubject = new Subject<void>(); |
|
|
@ -42,8 +51,11 @@ export class UserAccountAccessComponent implements OnDestroy, OnInit { |
|
|
|
private dataService: DataService, |
|
|
|
private deviceService: DeviceDetectorService, |
|
|
|
private dialog: MatDialog, |
|
|
|
private formBuilder: FormBuilder, |
|
|
|
private notificationService: NotificationService, |
|
|
|
private route: ActivatedRoute, |
|
|
|
private router: Router, |
|
|
|
private tokenStorageService: TokenStorageService, |
|
|
|
private userService: UserService |
|
|
|
) { |
|
|
|
const { globalPermissions } = this.dataService.fetchInfo(); |
|
|
@ -69,6 +81,11 @@ export class UserAccountAccessComponent implements OnDestroy, OnInit { |
|
|
|
permissions.deleteAccess |
|
|
|
); |
|
|
|
|
|
|
|
this.hasPermissionToUpdateOwnAccessToken = hasPermission( |
|
|
|
this.user.permissions, |
|
|
|
permissions.updateOwnAccessToken |
|
|
|
); |
|
|
|
|
|
|
|
this.changeDetectorRef.markForCheck(); |
|
|
|
} |
|
|
|
}); |
|
|
@ -99,6 +116,41 @@ export class UserAccountAccessComponent implements OnDestroy, OnInit { |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
public onGenerateAccessToken() { |
|
|
|
this.notificationService.confirm({ |
|
|
|
confirmFn: () => { |
|
|
|
this.dataService |
|
|
|
.updateOwnAccessToken({ |
|
|
|
accessToken: this.updateOwnAccessTokenForm.get('accessToken').value |
|
|
|
}) |
|
|
|
.pipe( |
|
|
|
catchError(() => { |
|
|
|
this.notificationService.alert({ |
|
|
|
title: $localize`Oops! Incorrect Security Token.` |
|
|
|
}); |
|
|
|
|
|
|
|
return EMPTY; |
|
|
|
}), |
|
|
|
takeUntil(this.unsubscribeSubject) |
|
|
|
) |
|
|
|
.subscribe(({ accessToken }) => { |
|
|
|
this.notificationService.alert({ |
|
|
|
discardFn: () => { |
|
|
|
this.tokenStorageService.signOut(); |
|
|
|
this.userService.remove(); |
|
|
|
|
|
|
|
document.location.href = `/${document.documentElement.lang}`; |
|
|
|
}, |
|
|
|
message: accessToken, |
|
|
|
title: $localize`Security token` |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, |
|
|
|
confirmType: ConfirmationDialogType.Warn, |
|
|
|
title: $localize`Do you really want to generate a new security token?` |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
public ngOnDestroy() { |
|
|
|
this.unsubscribeSubject.next(); |
|
|
|
this.unsubscribeSubject.complete(); |
|
|
|