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

@ -7,12 +7,13 @@
<div class="box-content"> <div class="box-content">
<div class="box-content-row" appBoxRow> <div class="box-content-row" appBoxRow>
<label for="email">{{'emailAddress' | i18n}}</label> <label for="email">{{'emailAddress' | i18n}}</label>
<input id="email" type="email" name="Email" [(ngModel)]="email" required appAutofocus> <input id="email" type="text" name="Email" [(ngModel)]="email" required
[appAutofocus]="!email || email === ''">
</div> </div>
<div class="box-content-row" appBoxRow> <div class="box-content-row" appBoxRow>
<label for="masterPassword">{{'masterPass' | i18n}}</label> <label for="masterPassword">{{'masterPass' | i18n}}</label>
<input id="masterPassword" type="password" name="MasterPassword" [(ngModel)]="masterPassword" <input id="masterPassword" type="password" name="MasterPassword" [(ngModel)]="masterPassword"
required> required [appAutofocus]="email && email !== ''">
</div> </div>
</div> </div>
</div> </div>

View File

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

View File

@ -418,5 +418,26 @@
}, },
"getMasterPasswordHint": { "getMasterPasswordHint": {
"message": "Get master password hint" "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."
} }
} }