1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-22 11:45:59 +01:00

move bow-row direct, and selected provider support

This commit is contained in:
Kyle Spearrin 2018-04-04 14:18:42 -04:00
parent f855a8272c
commit f673bd62d7
3 changed files with 58 additions and 0 deletions

View File

@ -6,6 +6,7 @@ export abstract class AuthService {
email: string;
masterPasswordHash: string;
twoFactorProviders: Map<TwoFactorProviderType, { [key: string]: string; }>;
selectedTwoFactorProviderType: TwoFactorProviderType;
logIn: (email: string, masterPassword: string) => Promise<AuthResult>;
logInTwoFactor: (twoFactorProvider: TwoFactorProviderType, twoFactorToken: string,

View File

@ -0,0 +1,49 @@
import {
Directive,
ElementRef,
HostListener,
OnInit,
} from '@angular/core';
@Directive({
selector: '[appBoxRow]',
})
export class BoxRowDirective implements OnInit {
el: HTMLElement = null;
formEls: NodeListOf<Element>;
constructor(private elRef: ElementRef) {
this.el = elRef.nativeElement;
}
ngOnInit(): void {
this.formEls = this.el.querySelectorAll('input:not([type="hidden"]), select, textarea');
this.formEls.forEach((formEl) => {
formEl.addEventListener('focus', (event: Event) => {
this.el.classList.add('active');
}, false);
formEl.addEventListener('blur', (event: Event) => {
this.el.classList.remove('active');
}, false);
});
}
@HostListener('click', ['$event']) onClick(event: Event) {
if (event.target !== this.el) {
return;
}
if (this.formEls.length > 0) {
const formEl = (this.formEls[0] as HTMLElement);
if (formEl.tagName.toLowerCase() === 'input') {
const inputEl = (formEl as HTMLInputElement);
if (inputEl.type != null && inputEl.type.toLowerCase() === 'checkbox') {
inputEl.click();
return;
}
}
formEl.focus();
}
}
}

View File

@ -63,6 +63,7 @@ export class AuthService {
email: string;
masterPasswordHash: string;
twoFactorProviders: Map<TwoFactorProviderType, { [key: string]: string; }>;
selectedTwoFactorProviderType: TwoFactorProviderType = null;
private key: SymmetricCryptoKey;
@ -95,6 +96,7 @@ export class AuthService {
}
async logIn(email: string, masterPassword: string): Promise<AuthResult> {
this.selectedTwoFactorProviderType = null;
email = email.toLowerCase();
const key = this.cryptoService.makeKey(masterPassword, email);
const hashedPassword = await this.cryptoService.hashPassword(masterPassword, key);
@ -117,6 +119,11 @@ export class AuthService {
return null;
}
if (this.selectedTwoFactorProviderType != null &&
this.twoFactorProviders.has(this.selectedTwoFactorProviderType)) {
return this.selectedTwoFactorProviderType;
}
let providerType: TwoFactorProviderType = null;
let providerPriority = -1;
this.twoFactorProviders.forEach((value, type) => {
@ -188,5 +195,6 @@ export class AuthService {
this.email = null;
this.masterPasswordHash = null;
this.twoFactorProviders = null;
this.selectedTwoFactorProviderType = null;
}
}