2018-09-25 15:12:24 +02:00
|
|
|
import {
|
|
|
|
Component,
|
|
|
|
Input,
|
|
|
|
} from '@angular/core';
|
2018-06-22 04:40:01 +02:00
|
|
|
import { Router } from '@angular/router';
|
|
|
|
|
|
|
|
import { ToasterService } from 'angular2-toaster';
|
|
|
|
|
2021-06-07 20:13:58 +02:00
|
|
|
import { ApiService } from 'jslib-common/abstractions/api.service';
|
|
|
|
import { CryptoService } from 'jslib-common/abstractions/crypto.service';
|
|
|
|
import { I18nService } from 'jslib-common/abstractions/i18n.service';
|
2021-10-20 18:30:04 +02:00
|
|
|
import { LogService } from 'jslib-common/abstractions/log.service';
|
2018-06-22 04:40:01 +02:00
|
|
|
|
2021-06-07 20:13:58 +02:00
|
|
|
import { PasswordVerificationRequest } from 'jslib-common/models/request/passwordVerificationRequest';
|
2018-06-22 04:40:01 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-purge-vault',
|
|
|
|
templateUrl: 'purge-vault.component.html',
|
|
|
|
})
|
|
|
|
export class PurgeVaultComponent {
|
2018-09-25 15:12:24 +02:00
|
|
|
@Input() organizationId?: string = null;
|
|
|
|
|
2018-06-22 04:40:01 +02:00
|
|
|
masterPassword: string;
|
|
|
|
formPromise: Promise<any>;
|
|
|
|
|
|
|
|
constructor(private apiService: ApiService, private i18nService: I18nService,
|
2021-04-14 23:43:40 +02:00
|
|
|
private toasterService: ToasterService, private cryptoService: CryptoService,
|
2021-10-20 18:30:04 +02:00
|
|
|
private router: Router, private logService: LogService) { }
|
2018-06-22 04:40:01 +02:00
|
|
|
|
|
|
|
async submit() {
|
|
|
|
if (this.masterPassword == null || this.masterPassword === '') {
|
|
|
|
this.toasterService.popAsync('error', this.i18nService.t('errorOccurred'),
|
|
|
|
this.i18nService.t('masterPassRequired'));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const request = new PasswordVerificationRequest();
|
|
|
|
request.masterPasswordHash = await this.cryptoService.hashPassword(this.masterPassword, null);
|
|
|
|
try {
|
2018-09-25 15:12:24 +02:00
|
|
|
this.formPromise = this.apiService.postPurgeCiphers(request, this.organizationId);
|
2018-06-22 04:40:01 +02:00
|
|
|
await this.formPromise;
|
|
|
|
this.toasterService.popAsync('success', null, this.i18nService.t('vaultPurged'));
|
2018-09-25 15:12:24 +02:00
|
|
|
if (this.organizationId != null) {
|
|
|
|
this.router.navigate(['organizations', this.organizationId, 'vault']);
|
|
|
|
} else {
|
|
|
|
this.router.navigate(['vault']);
|
|
|
|
}
|
2021-10-20 18:30:04 +02:00
|
|
|
} catch (e) {
|
|
|
|
this.logService.error(e);
|
|
|
|
}
|
2018-06-22 04:40:01 +02:00
|
|
|
}
|
|
|
|
}
|