1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-18 17:23:37 +00:00

more login page work

This commit is contained in:
Kyle Spearrin
2018-01-30 17:52:56 -05:00
parent 6040e12e97
commit 257eddf126
3 changed files with 56 additions and 11 deletions

View File

@@ -2,30 +2,53 @@ import * as template from './login.component.html';
import {
Component,
OnInit,
} from '@angular/core';
import { Router } from '@angular/router';
import { Angulartics2 } from 'angulartics2';
import { ToasterService } from 'angular2-toaster';
import { AuthService } from 'jslib/abstractions/auth.service';
import { I18nService } from 'jslib/abstractions/i18n.service';
@Component({
selector: 'app-login',
template: template,
})
export class LoginComponent implements OnInit {
export class LoginComponent {
email: string = '';
masterPassword: string = '';
constructor(private authService: AuthService, private router: Router) {
}
ngOnInit() {
// TODO?
}
constructor(private authService: AuthService, private router: Router, private analytics: Angulartics2,
private toasterService: ToasterService, private i18nService: I18nService) { }
async onSubmit() {
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);
this.router.navigate(['vault']);
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?
}
}
}