mirror of
https://github.com/bitwarden/browser.git
synced 2024-12-28 17:27:50 +01:00
api form directive
This commit is contained in:
parent
b50bf9d5cc
commit
619d3fd075
@ -1,5 +1,5 @@
|
|||||||
<div id="login">
|
<div id="login">
|
||||||
<form (ngSubmit)="onSubmit()">
|
<form #form (ngSubmit)="onSubmit()" [appApiForm]="formPromise">
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<img src="../../images/logo@2x.png" alt="bitwarden">
|
<img src="../../images/logo@2x.png" alt="bitwarden">
|
||||||
<p>{{'loginOrCreateNewAccount' | i18n}}</p>
|
<p>{{'loginOrCreateNewAccount' | i18n}}</p>
|
||||||
@ -18,9 +18,9 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
<button type="submit" class="btn primary block" [disabled]="loading">
|
<button type="submit" class="btn primary block" [disabled]="form.loading">
|
||||||
<span [hidden]="loading"><i class="fa fa-sign-in"></i> {{'logIn' | i18n}}</span>
|
<span [hidden]="form.loading"><i class="fa fa-sign-in"></i> {{'logIn' | i18n}}</span>
|
||||||
<i class="fa fa-spinner fa-spin" [hidden]="!loading"></i>
|
<i class="fa fa-spinner fa-spin" [hidden]="!form.loading"></i>
|
||||||
</button>
|
</button>
|
||||||
<button type="button" class="btn block">
|
<button type="button" class="btn block">
|
||||||
<i class="fa fa-pencil-square-o"></i> {{'createAccount' | i18n}}
|
<i class="fa fa-pencil-square-o"></i> {{'createAccount' | i18n}}
|
||||||
|
@ -12,8 +12,6 @@ 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';
|
import { I18nService } from 'jslib/abstractions/i18n.service';
|
||||||
|
|
||||||
import { ValidationService } from '../services/validation.service';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-login',
|
selector: 'app-login',
|
||||||
template: template,
|
template: template,
|
||||||
@ -21,11 +19,10 @@ import { ValidationService } from '../services/validation.service';
|
|||||||
export class LoginComponent {
|
export class LoginComponent {
|
||||||
email: string = '';
|
email: string = '';
|
||||||
masterPassword: string = '';
|
masterPassword: string = '';
|
||||||
loading: boolean;
|
formPromise: Promise<any>;
|
||||||
|
|
||||||
constructor(private authService: AuthService, private router: Router, private analytics: Angulartics2,
|
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() {
|
async onSubmit() {
|
||||||
if (this.email == null || this.email === '') {
|
if (this.email == null || this.email === '') {
|
||||||
@ -44,10 +41,9 @@ export class LoginComponent {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.loading = true;
|
|
||||||
try {
|
try {
|
||||||
const response = await this.authService.logIn(this.email, this.masterPassword);
|
this.formPromise = this.authService.logIn(this.email, this.masterPassword);
|
||||||
this.loading = false;
|
const response = await this.formPromise;
|
||||||
if (response.twoFactor) {
|
if (response.twoFactor) {
|
||||||
this.analytics.eventTrack.next({ action: 'Logged In To Two-step' });
|
this.analytics.eventTrack.next({ action: 'Logged In To Two-step' });
|
||||||
this.router.navigate(['twoFactor']);
|
this.router.navigate(['twoFactor']);
|
||||||
@ -57,9 +53,6 @@ export class LoginComponent {
|
|||||||
this.router.navigate(['vault']);
|
this.router.navigate(['vault']);
|
||||||
// TODO: sync on load to vault?
|
// TODO: sync on load to vault?
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch { }
|
||||||
this.loading = false;
|
|
||||||
this.validationService.showError(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ import { ServicesModule } from './services/services.module';
|
|||||||
import { ToasterModule } from 'angular2-toaster';
|
import { ToasterModule } from 'angular2-toaster';
|
||||||
|
|
||||||
import { AddEditComponent } from './vault/add-edit.component';
|
import { AddEditComponent } from './vault/add-edit.component';
|
||||||
|
import { ApiFormDirective } from './directives/api-form.directive';
|
||||||
import { AppComponent } from './app.component';
|
import { AppComponent } from './app.component';
|
||||||
import { AttachmentsComponent } from './vault/attachments.component';
|
import { AttachmentsComponent } from './vault/attachments.component';
|
||||||
import { AutofocusDirective } from './directives/autofocus.directive';
|
import { AutofocusDirective } from './directives/autofocus.directive';
|
||||||
@ -46,6 +47,7 @@ import { ViewComponent } from './vault/view.component';
|
|||||||
],
|
],
|
||||||
declarations: [
|
declarations: [
|
||||||
AddEditComponent,
|
AddEditComponent,
|
||||||
|
ApiFormDirective,
|
||||||
AppComponent,
|
AppComponent,
|
||||||
AttachmentsComponent,
|
AttachmentsComponent,
|
||||||
AutofocusDirective,
|
AutofocusDirective,
|
||||||
|
32
src/app/directives/api-form.directive.ts
Normal file
32
src/app/directives/api-form.directive.ts
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import {
|
||||||
|
Directive,
|
||||||
|
ElementRef,
|
||||||
|
Input,
|
||||||
|
OnChanges,
|
||||||
|
} from '@angular/core';
|
||||||
|
|
||||||
|
import { ValidationService } from '../services/validation.service';
|
||||||
|
|
||||||
|
@Directive({
|
||||||
|
selector: '[appApiForm]',
|
||||||
|
})
|
||||||
|
export class ApiFormDirective implements OnChanges {
|
||||||
|
@Input() appApiForm: Promise<any>;
|
||||||
|
|
||||||
|
constructor(private el: ElementRef, private validationService: ValidationService) { }
|
||||||
|
|
||||||
|
ngOnChanges(changes: any) {
|
||||||
|
if (this.appApiForm == null || this.appApiForm.then == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.el.nativeElement.loading = true;
|
||||||
|
|
||||||
|
this.appApiForm.then((response: any) => {
|
||||||
|
this.el.nativeElement.loading = false;
|
||||||
|
}, (e: any) => {
|
||||||
|
this.el.nativeElement.loading = false;
|
||||||
|
this.validationService.showError(e);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user