mirror of
https://github.com/bitwarden/jslib
synced 2025-12-16 08:13:26 +00:00
move bow-row direct, and selected provider support
This commit is contained in:
@@ -6,6 +6,7 @@ export abstract class AuthService {
|
|||||||
email: string;
|
email: string;
|
||||||
masterPasswordHash: string;
|
masterPasswordHash: string;
|
||||||
twoFactorProviders: Map<TwoFactorProviderType, { [key: string]: string; }>;
|
twoFactorProviders: Map<TwoFactorProviderType, { [key: string]: string; }>;
|
||||||
|
selectedTwoFactorProviderType: TwoFactorProviderType;
|
||||||
|
|
||||||
logIn: (email: string, masterPassword: string) => Promise<AuthResult>;
|
logIn: (email: string, masterPassword: string) => Promise<AuthResult>;
|
||||||
logInTwoFactor: (twoFactorProvider: TwoFactorProviderType, twoFactorToken: string,
|
logInTwoFactor: (twoFactorProvider: TwoFactorProviderType, twoFactorToken: string,
|
||||||
|
|||||||
49
src/angular/directives/box-row.directive.ts
Normal file
49
src/angular/directives/box-row.directive.ts
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -63,6 +63,7 @@ export class AuthService {
|
|||||||
email: string;
|
email: string;
|
||||||
masterPasswordHash: string;
|
masterPasswordHash: string;
|
||||||
twoFactorProviders: Map<TwoFactorProviderType, { [key: string]: string; }>;
|
twoFactorProviders: Map<TwoFactorProviderType, { [key: string]: string; }>;
|
||||||
|
selectedTwoFactorProviderType: TwoFactorProviderType = null;
|
||||||
|
|
||||||
private key: SymmetricCryptoKey;
|
private key: SymmetricCryptoKey;
|
||||||
|
|
||||||
@@ -95,6 +96,7 @@ export class AuthService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async logIn(email: string, masterPassword: string): Promise<AuthResult> {
|
async logIn(email: string, masterPassword: string): Promise<AuthResult> {
|
||||||
|
this.selectedTwoFactorProviderType = null;
|
||||||
email = email.toLowerCase();
|
email = email.toLowerCase();
|
||||||
const key = this.cryptoService.makeKey(masterPassword, email);
|
const key = this.cryptoService.makeKey(masterPassword, email);
|
||||||
const hashedPassword = await this.cryptoService.hashPassword(masterPassword, key);
|
const hashedPassword = await this.cryptoService.hashPassword(masterPassword, key);
|
||||||
@@ -117,6 +119,11 @@ export class AuthService {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.selectedTwoFactorProviderType != null &&
|
||||||
|
this.twoFactorProviders.has(this.selectedTwoFactorProviderType)) {
|
||||||
|
return this.selectedTwoFactorProviderType;
|
||||||
|
}
|
||||||
|
|
||||||
let providerType: TwoFactorProviderType = null;
|
let providerType: TwoFactorProviderType = null;
|
||||||
let providerPriority = -1;
|
let providerPriority = -1;
|
||||||
this.twoFactorProviders.forEach((value, type) => {
|
this.twoFactorProviders.forEach((value, type) => {
|
||||||
@@ -188,5 +195,6 @@ export class AuthService {
|
|||||||
this.email = null;
|
this.email = null;
|
||||||
this.masterPasswordHash = null;
|
this.masterPasswordHash = null;
|
||||||
this.twoFactorProviders = null;
|
this.twoFactorProviders = null;
|
||||||
|
this.selectedTwoFactorProviderType = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user