1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-10-29 07:59:42 +01:00
bitwarden-browser/src/app/accounts/login.component.ts

55 lines
1.9 KiB
TypeScript
Raw Normal View History

2018-01-16 21:58:17 +01:00
import * as template from './login.component.html';
import {
Component,
} from '@angular/core';
import { Router } from '@angular/router';
2018-01-30 23:52:56 +01:00
import { Angulartics2 } from 'angulartics2';
import { ToasterService } from 'angular2-toaster';
2018-01-23 05:37:36 +01:00
import { AuthService } from 'jslib/abstractions/auth.service';
2018-01-30 23:52:56 +01:00
import { I18nService } from 'jslib/abstractions/i18n.service';
2018-01-23 05:37:36 +01:00
2018-01-16 21:58:17 +01:00
@Component({
selector: 'app-login',
2018-01-24 15:26:59 +01:00
template: template,
2018-01-16 21:58:17 +01:00
})
2018-01-30 23:52:56 +01:00
export class LoginComponent {
email: string = '';
masterPassword: string = '';
2018-01-30 23:52:56 +01:00
constructor(private authService: AuthService, private router: Router, private analytics: Angulartics2,
private toasterService: ToasterService, private i18nService: I18nService) { }
async onSubmit() {
2018-01-30 23:52:56 +01:00
if (this.email == null || this.email === '') {
this.toasterService.popAsync('error', this.i18nService.t('errorsOccurred'),
this.i18nService.t('emailRequired'));
return;
}
if (this.email.indexOf('@') === -1) {
this.toasterService.popAsync('error', this.i18nService.t('errorsOccurred'),
this.i18nService.t('invalidEmail'));
return;
}
if (this.masterPassword == null || this.masterPassword === '') {
this.toasterService.popAsync('error', this.i18nService.t('errorsOccurred'),
this.i18nService.t('masterPassRequired'));
return;
}
const response = await this.authService.logIn(this.email, this.masterPassword);
2018-01-30 23:52:56 +01:00
if (response.twoFactor) {
this.analytics.eventTrack.next({ action: 'Logged In To Two-step' });
this.router.navigate(['twoFactor']);
// TODO: pass 2fa info
} else {
this.analytics.eventTrack.next({ action: 'Logged In' });
this.router.navigate(['vault']);
// TODO: sync on load to vault?
}
}
2018-01-16 21:58:17 +01:00
}