1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-22 11:13:46 +00:00

added validation to login form

This commit is contained in:
Kyle Spearrin
2018-01-30 23:34:45 -05:00
parent c9f7a781a8
commit b50bf9d5cc
7 changed files with 89 additions and 20 deletions

View File

@@ -8,18 +8,19 @@
<div class="box-content-row" appBoxRow>
<label for="email">{{'emailAddress' | i18n}}</label>
<input id="email" type="text" name="Email" [(ngModel)]="email" required
[appAutofocus]="!email || email === ''">
[appAutofocus]="email === ''">
</div>
<div class="box-content-row" appBoxRow>
<label for="masterPassword">{{'masterPass' | i18n}}</label>
<input id="masterPassword" type="password" name="MasterPassword" [(ngModel)]="masterPassword"
required [appAutofocus]="email && email !== ''">
required [appAutofocus]="email !== ''">
</div>
</div>
</div>
<div class="buttons">
<button type="submit" class="btn primary block">
<i class="fa fa-sign-in"></i> {{'logIn' | i18n}}
<button type="submit" class="btn primary block" [disabled]="loading">
<span [hidden]="loading"><i class="fa fa-sign-in"></i> {{'logIn' | i18n}}</span>
<i class="fa fa-spinner fa-spin" [hidden]="!loading"></i>
</button>
<button type="button" class="btn block">
<i class="fa fa-pencil-square-o"></i> {{'createAccount' | i18n}}

View File

@@ -12,6 +12,8 @@ import { ToasterService } from 'angular2-toaster';
import { AuthService } from 'jslib/abstractions/auth.service';
import { I18nService } from 'jslib/abstractions/i18n.service';
import { ValidationService } from '../services/validation.service';
@Component({
selector: 'app-login',
template: template,
@@ -19,36 +21,45 @@ import { I18nService } from 'jslib/abstractions/i18n.service';
export class LoginComponent {
email: string = '';
masterPassword: string = '';
loading: boolean;
constructor(private authService: AuthService, private router: Router, private analytics: Angulartics2,
private toasterService: ToasterService, private i18nService: I18nService) { }
private toasterService: ToasterService, private i18nService: I18nService,
private validationService: ValidationService) { }
async onSubmit() {
if (this.email == null || this.email === '') {
this.toasterService.popAsync('error', this.i18nService.t('errorsOccurred'),
this.toasterService.popAsync('error', this.i18nService.t('errorOccurred'),
this.i18nService.t('emailRequired'));
return;
}
if (this.email.indexOf('@') === -1) {
this.toasterService.popAsync('error', this.i18nService.t('errorsOccurred'),
this.toasterService.popAsync('error', this.i18nService.t('errorOccurred'),
this.i18nService.t('invalidEmail'));
return;
}
if (this.masterPassword == null || this.masterPassword === '') {
this.toasterService.popAsync('error', this.i18nService.t('errorsOccurred'),
this.toasterService.popAsync('error', this.i18nService.t('errorOccurred'),
this.i18nService.t('masterPassRequired'));
return;
}
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']);
// TODO: sync on load to vault?
this.loading = true;
try {
const response = await this.authService.logIn(this.email, this.masterPassword);
this.loading = false;
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?
}
} catch (e) {
this.loading = false;
this.validationService.showError(e);
}
}
}