1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-19 17:53:39 +00:00

share login component with jslib

This commit is contained in:
Kyle Spearrin
2018-04-04 09:19:28 -04:00
parent 5fd400bf9d
commit 4f4ef82049
3 changed files with 15 additions and 53 deletions

2
jslib

Submodule jslib updated: 579f970323...7b4d0a71de

View File

@@ -1,70 +1,29 @@
import * as template from './login.component.html'; import * as template from './login.component.html';
import { import { Component } from '@angular/core';
Component,
ComponentFactoryResolver,
ViewChild,
ViewContainerRef,
} from '@angular/core';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { ToasterService } from 'angular2-toaster'; import { ToasterService } from 'angular2-toaster';
import { Angulartics2 } from 'angulartics2'; import { Angulartics2 } from 'angulartics2';
import { AuthResult } from 'jslib/models/domain/authResult';
import { AuthService } from 'jslib/abstractions/auth.service'; import { AuthService } from 'jslib/abstractions/auth.service';
import { I18nService } from 'jslib/abstractions/i18n.service'; import { I18nService } from 'jslib/abstractions/i18n.service';
import { SyncService } from 'jslib/abstractions/sync.service'; import { SyncService } from 'jslib/abstractions/sync.service';
import { LoginComponent as BaseLoginComponent } from 'jslib/angular/components/login.component';
@Component({ @Component({
selector: 'app-login', selector: 'app-login',
template: template, template: template,
}) })
export class LoginComponent { export class LoginComponent extends BaseLoginComponent {
email: string = ''; constructor(authService: AuthService, router: Router,
masterPassword: string = ''; analytics: Angulartics2, toasterService: ToasterService,
showPassword: boolean = false; i18nService: I18nService, syncService: SyncService) {
formPromise: Promise<AuthResult>; super(authService, router, analytics, toasterService, i18nService, syncService);
constructor(private authService: AuthService, private router: Router,
private analytics: Angulartics2, private toasterService: ToasterService,
private i18nService: I18nService, private syncService: SyncService) { }
async submit() {
if (this.email == null || this.email === '') {
this.toasterService.popAsync('error', this.i18nService.t('errorOccurred'),
this.i18nService.t('emailRequired'));
return;
}
if (this.email.indexOf('@') === -1) {
this.toasterService.popAsync('error', this.i18nService.t('errorOccurred'),
this.i18nService.t('invalidEmail'));
return;
}
if (this.masterPassword == null || this.masterPassword === '') {
this.toasterService.popAsync('error', this.i18nService.t('errorOccurred'),
this.i18nService.t('masterPassRequired'));
return;
}
try {
this.formPromise = this.authService.logIn(this.email, this.masterPassword);
const response = await this.formPromise;
if (response.twoFactor) {
this.analytics.eventTrack.next({ action: 'Logged In To Two-step' });
this.router.navigate(['2fa']);
} else {
this.syncService.fullSync(true);
this.analytics.eventTrack.next({ action: 'Logged In' });
this.router.navigate(['vault']);
}
} catch { }
} }
togglePassword() { settings() {
this.analytics.eventTrack.next({ action: 'Toggled Master Password on Login' }); // TODO: navigate to settings
this.showPassword = !this.showPassword;
document.getElementById('masterPassword').focus();
} }
} }

View File

@@ -13,7 +13,10 @@
], ],
"baseUrl": ".", "baseUrl": ".",
"paths": { "paths": {
"jslib/*": [ "jslib/src/*" ] "jslib/*": [ "jslib/src/*" ],
"@angular/*": [ "node_modules/@angular/*" ],
"angular2-toaster": [ "node_modules/angular2-toaster" ],
"angulartics2": [ "node_modules/angulartics2" ]
} }
}, },
"exclude": [ "exclude": [