bitwarden-estensione-browser/src/app/settings/two-factor-duo.component.ts

71 lines
2.6 KiB
TypeScript
Raw Normal View History

import { Component } from '@angular/core';
2018-06-27 21:27:59 +02:00
import { ToasterService } from 'angular2-toaster';
import { ApiService } from 'jslib-common/abstractions/api.service';
import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { LogService } from 'jslib-common/abstractions/log.service';
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
import { UserVerificationService } from 'jslib-common/abstractions/userVerification.service';
2018-06-27 21:27:59 +02:00
import { TwoFactorProviderType } from 'jslib-common/enums/twoFactorProviderType';
import { UpdateTwoFactorDuoRequest } from 'jslib-common/models/request/updateTwoFactorDuoRequest';
import { TwoFactorDuoResponse } from 'jslib-common/models/response/twoFactorDuoResponse';
2018-06-27 21:27:59 +02:00
import { TwoFactorBaseComponent } from './two-factor-base.component';
2018-06-27 21:27:59 +02:00
@Component({
selector: 'app-two-factor-duo',
templateUrl: 'two-factor-duo.component.html',
})
export class TwoFactorDuoComponent extends TwoFactorBaseComponent {
2018-07-18 23:10:26 +02:00
type = TwoFactorProviderType.Duo;
2018-06-27 21:27:59 +02:00
ikey: string;
skey: string;
host: string;
formPromise: Promise<any>;
constructor(apiService: ApiService, i18nService: I18nService,
toasterService: ToasterService, platformUtilsService: PlatformUtilsService,
logService: LogService, userVerificationService: UserVerificationService) {
super(apiService, i18nService, toasterService, platformUtilsService, logService, userVerificationService);
}
2018-06-27 21:27:59 +02:00
auth(authResponse: any) {
super.auth(authResponse);
this.processResponse(authResponse.response);
2018-06-27 21:27:59 +02:00
}
submit() {
2018-06-27 21:27:59 +02:00
if (this.enabled) {
return super.disable(this.formPromise);
2018-06-27 21:27:59 +02:00
} else {
return this.enable();
2018-06-27 21:27:59 +02:00
}
}
protected async enable() {
const request = await this.buildRequestModel(UpdateTwoFactorDuoRequest);
2018-06-27 21:27:59 +02:00
request.integrationKey = this.ikey;
request.secretKey = this.skey;
request.host = this.host;
return super.enable(async () => {
2018-07-18 23:10:26 +02:00
if (this.organizationId != null) {
this.formPromise = this.apiService.putTwoFactorOrganizationDuo(this.organizationId, request);
} else {
this.formPromise = this.apiService.putTwoFactorDuo(request);
}
2018-06-27 21:27:59 +02:00
const response = await this.formPromise;
await this.processResponse(response);
});
2018-06-27 21:27:59 +02:00
}
private processResponse(response: TwoFactorDuoResponse) {
2018-06-27 21:27:59 +02:00
this.ikey = response.integrationKey;
this.skey = response.secretKey;
this.host = response.host;
this.enabled = response.enabled;
}
}