2018-06-21 23:14:36 +02:00
|
|
|
import {
|
|
|
|
Component,
|
|
|
|
ComponentFactoryResolver,
|
|
|
|
ViewChild,
|
|
|
|
ViewContainerRef,
|
|
|
|
} from '@angular/core';
|
|
|
|
|
|
|
|
import { ModalComponent } from '../modal.component';
|
2020-11-10 22:13:42 +01:00
|
|
|
import { ApiKeyComponent } from './api-key.component';
|
2018-06-21 23:14:36 +02:00
|
|
|
import { DeauthorizeSessionsComponent } from './deauthorize-sessions.component';
|
2018-06-22 04:40:01 +02:00
|
|
|
import { DeleteAccountComponent } from './delete-account.component';
|
|
|
|
import { PurgeVaultComponent } from './purge-vault.component';
|
2018-06-21 05:35:40 +02:00
|
|
|
|
2020-11-10 22:13:42 +01:00
|
|
|
import { ApiService } from 'jslib/abstractions/api.service';
|
|
|
|
import { UserService } from 'jslib/abstractions/user.service';
|
|
|
|
|
2018-06-21 04:27:37 +02:00
|
|
|
@Component({
|
|
|
|
selector: 'app-account',
|
|
|
|
templateUrl: 'account.component.html',
|
|
|
|
})
|
2018-06-21 21:57:28 +02:00
|
|
|
export class AccountComponent {
|
2020-08-17 16:04:38 +02:00
|
|
|
@ViewChild('deauthorizeSessionsTemplate', { read: ViewContainerRef, static: true }) deauthModalRef: ViewContainerRef;
|
|
|
|
@ViewChild('purgeVaultTemplate', { read: ViewContainerRef, static: true }) purgeModalRef: ViewContainerRef;
|
|
|
|
@ViewChild('deleteAccountTemplate', { read: ViewContainerRef, static: true }) deleteModalRef: ViewContainerRef;
|
2020-11-10 22:13:42 +01:00
|
|
|
@ViewChild('viewUserApiKeyTemplate', { read: ViewContainerRef, static: true }) viewUserApiKeyModalRef: ViewContainerRef;
|
|
|
|
@ViewChild('rotateUserApiKeyTemplate', { read: ViewContainerRef, static: true }) rotateUserApiKeyModalRef: ViewContainerRef;
|
2018-06-21 23:14:36 +02:00
|
|
|
|
|
|
|
private modal: ModalComponent = null;
|
|
|
|
|
2020-11-10 22:13:42 +01:00
|
|
|
constructor(private componentFactoryResolver: ComponentFactoryResolver, private apiService: ApiService,
|
|
|
|
private userService: UserService) { }
|
2018-06-21 23:14:36 +02:00
|
|
|
|
2018-06-21 21:57:28 +02:00
|
|
|
deauthorizeSessions() {
|
2018-06-21 23:14:36 +02:00
|
|
|
if (this.modal != null) {
|
|
|
|
this.modal.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
const factory = this.componentFactoryResolver.resolveComponentFactory(ModalComponent);
|
|
|
|
this.modal = this.deauthModalRef.createComponent(factory).instance;
|
|
|
|
this.modal.show<DeauthorizeSessionsComponent>(DeauthorizeSessionsComponent, this.deauthModalRef);
|
2018-06-21 21:57:28 +02:00
|
|
|
|
2018-06-21 23:14:36 +02:00
|
|
|
this.modal.onClosed.subscribe(async () => {
|
|
|
|
this.modal = null;
|
|
|
|
});
|
2018-06-21 21:57:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
purgeVault() {
|
2018-06-22 04:40:01 +02:00
|
|
|
if (this.modal != null) {
|
|
|
|
this.modal.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
const factory = this.componentFactoryResolver.resolveComponentFactory(ModalComponent);
|
|
|
|
this.modal = this.purgeModalRef.createComponent(factory).instance;
|
|
|
|
this.modal.show<PurgeVaultComponent>(PurgeVaultComponent, this.purgeModalRef);
|
2018-06-21 21:57:28 +02:00
|
|
|
|
2018-06-22 04:40:01 +02:00
|
|
|
this.modal.onClosed.subscribe(async () => {
|
|
|
|
this.modal = null;
|
|
|
|
});
|
2018-06-21 21:57:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
deleteAccount() {
|
2018-06-22 04:40:01 +02:00
|
|
|
if (this.modal != null) {
|
|
|
|
this.modal.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
const factory = this.componentFactoryResolver.resolveComponentFactory(ModalComponent);
|
|
|
|
this.modal = this.deleteModalRef.createComponent(factory).instance;
|
|
|
|
this.modal.show<DeleteAccountComponent>(DeleteAccountComponent, this.deleteModalRef);
|
2018-06-21 21:57:28 +02:00
|
|
|
|
2018-06-22 04:40:01 +02:00
|
|
|
this.modal.onClosed.subscribe(async () => {
|
|
|
|
this.modal = null;
|
|
|
|
});
|
2018-06-21 21:57:28 +02:00
|
|
|
}
|
2020-11-10 22:13:42 +01:00
|
|
|
|
|
|
|
async viewUserApiKey() {
|
|
|
|
if (this.modal != null) {
|
|
|
|
this.modal.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
const factory = this.componentFactoryResolver.resolveComponentFactory(ModalComponent);
|
|
|
|
this.modal = this.viewUserApiKeyModalRef.createComponent(factory).instance;
|
|
|
|
const childComponent = this.modal.show<ApiKeyComponent>(ApiKeyComponent, this.viewUserApiKeyModalRef);
|
|
|
|
childComponent.keyType = 'user';
|
|
|
|
childComponent.entityId = await this.userService.getUserId();
|
|
|
|
childComponent.postKey = this.apiService.postUserApiKey.bind(this.apiService);
|
|
|
|
childComponent.scope = 'api';
|
|
|
|
childComponent.grantType = 'client_credentials';
|
|
|
|
childComponent.apiKeyTitle = 'apiKey';
|
|
|
|
childComponent.apiKeyWarning = 'userApiKeyWarning';
|
|
|
|
childComponent.apiKeyDescription = 'userApiKeyDesc';
|
|
|
|
|
|
|
|
this.modal.onClosed.subscribe(async () => {
|
|
|
|
this.modal = null;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async rotateUserApiKey() {
|
|
|
|
if (this.modal != null) {
|
|
|
|
this.modal.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
const factory = this.componentFactoryResolver.resolveComponentFactory(ModalComponent);
|
|
|
|
this.modal = this.rotateUserApiKeyModalRef.createComponent(factory).instance;
|
|
|
|
const childComponent = this.modal.show<ApiKeyComponent>(ApiKeyComponent, this.rotateUserApiKeyModalRef);
|
|
|
|
childComponent.keyType = 'user';
|
|
|
|
childComponent.isRotation = true;
|
|
|
|
childComponent.entityId = await this.userService.getUserId();
|
|
|
|
childComponent.postKey = this.apiService.postUserRotateApiKey.bind(this.apiService);
|
|
|
|
childComponent.scope = 'api';
|
|
|
|
childComponent.grantType = 'client_credentials';
|
|
|
|
childComponent.apiKeyTitle = 'apiKey';
|
|
|
|
childComponent.apiKeyWarning = 'userApiKeyWarning';
|
|
|
|
childComponent.apiKeyDescription = 'apiKeyRotateDesc';
|
|
|
|
|
|
|
|
this.modal.onClosed.subscribe(async () => {
|
|
|
|
this.modal = null;
|
|
|
|
});
|
|
|
|
}
|
2018-06-21 21:57:28 +02:00
|
|
|
}
|