2018-06-21 23:14:36 +02:00
|
|
|
import { Component, ViewChild, ViewContainerRef } from "@angular/core";
|
|
|
|
|
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
|
|
|
|
2021-06-07 20:13:58 +02:00
|
|
|
import { ApiService } from "jslib-common/abstractions/api.service";
|
2021-11-09 19:24:26 +01:00
|
|
|
import { KeyConnectorService } from "jslib-common/abstractions/keyConnector.service";
|
2021-12-14 17:10:26 +01:00
|
|
|
import { StateService } from "jslib-common/abstractions/state.service";
|
2020-11-10 22:13:42 +01:00
|
|
|
|
2021-08-27 14:50:58 +02:00
|
|
|
import { ModalService } from "jslib-angular/services/modal.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
|
|
|
|
2021-11-09 19:24:26 +01:00
|
|
|
showChangePassword = true;
|
|
|
|
showChangeKdf = true;
|
|
|
|
showChangeEmail = true;
|
|
|
|
|
2021-08-27 14:50:58 +02:00
|
|
|
constructor(
|
|
|
|
private modalService: ModalService,
|
|
|
|
private apiService: ApiService,
|
2021-12-14 17:10:26 +01:00
|
|
|
private keyConnectorService: KeyConnectorService,
|
|
|
|
private stateService: StateService
|
|
|
|
) {}
|
2021-11-09 19:24:26 +01:00
|
|
|
|
|
|
|
async ngOnInit() {
|
|
|
|
this.showChangeEmail =
|
|
|
|
this.showChangeKdf =
|
|
|
|
this.showChangePassword =
|
|
|
|
!(await this.keyConnectorService.getUsesKeyConnector());
|
|
|
|
}
|
2018-06-21 23:14:36 +02:00
|
|
|
|
2021-08-27 14:50:58 +02:00
|
|
|
async deauthorizeSessions() {
|
|
|
|
await this.modalService.openViewRef(DeauthorizeSessionsComponent, this.deauthModalRef);
|
2018-06-21 21:57:28 +02:00
|
|
|
}
|
|
|
|
|
2021-08-27 14:50:58 +02:00
|
|
|
async purgeVault() {
|
|
|
|
await this.modalService.openViewRef(PurgeVaultComponent, this.purgeModalRef);
|
2018-06-21 21:57:28 +02:00
|
|
|
}
|
|
|
|
|
2021-08-27 14:50:58 +02:00
|
|
|
async deleteAccount() {
|
|
|
|
await this.modalService.openViewRef(DeleteAccountComponent, this.deleteModalRef);
|
2018-06-21 21:57:28 +02:00
|
|
|
}
|
2020-11-10 22:13:42 +01:00
|
|
|
|
|
|
|
async viewUserApiKey() {
|
2021-12-14 17:10:26 +01:00
|
|
|
const entityId = await this.stateService.getUserId();
|
2021-08-27 14:50:58 +02:00
|
|
|
await this.modalService.openViewRef(ApiKeyComponent, this.viewUserApiKeyModalRef, (comp) => {
|
|
|
|
comp.keyType = "user";
|
|
|
|
comp.entityId = entityId;
|
|
|
|
comp.postKey = this.apiService.postUserApiKey.bind(this.apiService);
|
|
|
|
comp.scope = "api";
|
|
|
|
comp.grantType = "client_credentials";
|
|
|
|
comp.apiKeyTitle = "apiKey";
|
|
|
|
comp.apiKeyWarning = "userApiKeyWarning";
|
|
|
|
comp.apiKeyDescription = "userApiKeyDesc";
|
2020-11-10 22:13:42 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async rotateUserApiKey() {
|
2021-12-14 17:10:26 +01:00
|
|
|
const entityId = await this.stateService.getUserId();
|
2021-08-27 14:50:58 +02:00
|
|
|
await this.modalService.openViewRef(ApiKeyComponent, this.rotateUserApiKeyModalRef, (comp) => {
|
|
|
|
comp.keyType = "user";
|
|
|
|
comp.isRotation = true;
|
|
|
|
comp.entityId = entityId;
|
|
|
|
comp.postKey = this.apiService.postUserRotateApiKey.bind(this.apiService);
|
|
|
|
comp.scope = "api";
|
|
|
|
comp.grantType = "client_credentials";
|
|
|
|
comp.apiKeyTitle = "apiKey";
|
|
|
|
comp.apiKeyWarning = "userApiKeyWarning";
|
|
|
|
comp.apiKeyDescription = "apiKeyRotateDesc";
|
2020-11-10 22:13:42 +01:00
|
|
|
});
|
|
|
|
}
|
2018-06-21 21:57:28 +02:00
|
|
|
}
|