diff --git a/src/app/accounts/login.component.html b/src/app/accounts/login.component.html
index 81805db33e6..a7a6c6f17d8 100644
--- a/src/app/accounts/login.component.html
+++ b/src/app/accounts/login.component.html
@@ -7,12 +7,13 @@
diff --git a/src/app/accounts/login.component.ts b/src/app/accounts/login.component.ts
index 26db456cde1..70432329b97 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 b4305309cb2..5be7e5cb05c 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."
}
}