From 257eddf12699346dae0b7c64884f743e0209fe9d Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 30 Jan 2018 17:52:56 -0500 Subject: [PATCH] more login page work --- src/app/accounts/login.component.html | 5 ++-- src/app/accounts/login.component.ts | 41 +++++++++++++++++++++------ src/locales/en/messages.json | 21 ++++++++++++++ 3 files changed, 56 insertions(+), 11 deletions(-) diff --git a/src/app/accounts/login.component.html b/src/app/accounts/login.component.html index 81805db3..a7a6c6f1 100644 --- a/src/app/accounts/login.component.html +++ b/src/app/accounts/login.component.html @@ -7,12 +7,13 @@
- +
+ required [appAutofocus]="email && email !== ''">
diff --git a/src/app/accounts/login.component.ts b/src/app/accounts/login.component.ts index 26db456c..70432329 100644 --- a/src/app/accounts/login.component.ts +++ b/src/app/accounts/login.component.ts @@ -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? + } } } diff --git a/src/locales/en/messages.json b/src/locales/en/messages.json index b4305309..5be7e5cb 100644 --- a/src/locales/en/messages.json +++ b/src/locales/en/messages.json @@ -418,5 +418,26 @@ }, "getMasterPasswordHint": { "message": "Get master password hint" + }, + "emailRequired": { + "message": "Email address is required." + }, + "invalidEmail": { + "message": "Invalid email address." + }, + "masterPassRequired": { + "message": "Master password is required." + }, + "masterPassLength": { + "message": "Master password must be at least 8 characters long." + }, + "masterPassDoesntMatch": { + "message": "Master password confirmation does not match." + }, + "newAccountCreated": { + "message": "Your new account has been created! You may now log in." + }, + "masterPassSent": { + "message": "We've sent you an email with your master password hint." } }