2021-11-09 17:01:22 +01:00
|
|
|
import {
|
|
|
|
Component,
|
|
|
|
OnInit,
|
|
|
|
} from '@angular/core';
|
|
|
|
import {
|
|
|
|
ControlValueAccessor,
|
|
|
|
FormControl,
|
|
|
|
NG_VALUE_ACCESSOR,
|
|
|
|
} from '@angular/forms';
|
|
|
|
|
|
|
|
import { ApiService } from 'jslib-common/abstractions/api.service';
|
|
|
|
import { KeyConnectorService } from 'jslib-common/abstractions/keyConnector.service';
|
2021-11-15 22:53:57 +01:00
|
|
|
import { UserVerificationService } from 'jslib-common/abstractions/userVerification.service';
|
2021-11-09 17:01:22 +01:00
|
|
|
|
|
|
|
import { VerificationType } from 'jslib-common/enums/verificationType';
|
|
|
|
|
|
|
|
import { Verification } from 'jslib-common/types/verification';
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-verify-master-password',
|
|
|
|
templateUrl: 'verify-master-password.component.html',
|
|
|
|
providers: [
|
|
|
|
{
|
|
|
|
provide: NG_VALUE_ACCESSOR,
|
|
|
|
multi: true,
|
|
|
|
useExisting: VerifyMasterPasswordComponent,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
})
|
|
|
|
export class VerifyMasterPasswordComponent implements ControlValueAccessor, OnInit {
|
|
|
|
usesKeyConnector: boolean = false;
|
|
|
|
disableRequestOTP: boolean = false;
|
|
|
|
|
|
|
|
secret = new FormControl('');
|
|
|
|
|
|
|
|
private onChange: (value: Verification) => void;
|
|
|
|
|
2021-11-15 22:53:57 +01:00
|
|
|
constructor(private keyConnectorService: KeyConnectorService,
|
|
|
|
private userVerificationService: UserVerificationService) { }
|
2021-11-09 17:01:22 +01:00
|
|
|
|
|
|
|
async ngOnInit() {
|
|
|
|
this.usesKeyConnector = await this.keyConnectorService.getUsesKeyConnector();
|
|
|
|
|
|
|
|
this.secret.valueChanges.subscribe(secret => {
|
|
|
|
if (this.onChange == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.onChange({
|
|
|
|
type: this.usesKeyConnector ? VerificationType.OTP : VerificationType.MasterPassword,
|
|
|
|
secret: secret,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async requestOTP() {
|
|
|
|
if (this.usesKeyConnector) {
|
|
|
|
this.disableRequestOTP = true;
|
2021-11-15 22:53:57 +01:00
|
|
|
await this.userVerificationService.requestOTP();
|
2021-11-09 17:01:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
writeValue(obj: any): void {
|
|
|
|
this.secret.setValue(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
registerOnChange(fn: any): void {
|
|
|
|
this.onChange = fn;
|
|
|
|
}
|
|
|
|
|
|
|
|
registerOnTouched(fn: any): void {
|
|
|
|
// Not implemented
|
|
|
|
}
|
|
|
|
|
|
|
|
setDisabledState?(isDisabled: boolean): void {
|
|
|
|
this.disableRequestOTP = isDisabled;
|
|
|
|
if (isDisabled) {
|
|
|
|
this.secret.disable();
|
|
|
|
} else {
|
|
|
|
this.secret.enable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|