|
1 |
| -import { Component, Injector, ElementRef, AfterViewInit, ViewChild } from '@angular/core'; |
2 |
| -import { Router } from '@angular/router'; |
3 |
| -import { AccountServiceProxy, RegisterInput, RegisterOutput } from '@shared/service-proxies/service-proxies' |
4 |
| -import { AppComponentBase } from '@shared/app-component-base'; |
5 |
| -import { LoginService } from '../login/login.service'; |
6 |
| -import { accountModuleAnimation } from '@shared/animations/routerTransition'; |
7 |
| -import { finalize } from 'rxjs/operators'; |
| 1 | +import { Component, Injector } from "@angular/core"; |
| 2 | +import { Router } from "@angular/router"; |
| 3 | +import { finalize } from "rxjs/operators"; |
| 4 | +import { AppComponentBase } from "@shared/app-component-base"; |
| 5 | +import { accountModuleAnimation } from "@shared/animations/routerTransition"; |
| 6 | +import { |
| 7 | + AccountServiceProxy, |
| 8 | + RegisterInput, |
| 9 | + RegisterOutput |
| 10 | +} from "@shared/service-proxies/service-proxies"; |
| 11 | +import { LoginService } from "../login/login.service"; |
8 | 12 |
|
9 | 13 | @Component({
|
10 |
| - templateUrl: './register.component.html', |
11 |
| - animations: [accountModuleAnimation()] |
| 14 | + templateUrl: "./register.component.html", |
| 15 | + animations: [accountModuleAnimation()], |
| 16 | + styles: [ |
| 17 | + ` |
| 18 | + mat-form-field { |
| 19 | + width: 100%; |
| 20 | + } |
| 21 | + mat-checkbox { |
| 22 | + padding-bottom: 5px; |
| 23 | + } |
| 24 | + ` |
| 25 | + ] |
12 | 26 | })
|
13 |
| -export class RegisterComponent extends AppComponentBase implements AfterViewInit { |
| 27 | +export class RegisterComponent extends AppComponentBase { |
| 28 | + model: RegisterInput = new RegisterInput(); |
| 29 | + saving: boolean = false; |
14 | 30 |
|
15 |
| - @ViewChild('cardBody') cardBody: ElementRef; |
| 31 | + constructor( |
| 32 | + injector: Injector, |
| 33 | + private _accountService: AccountServiceProxy, |
| 34 | + private _router: Router, |
| 35 | + private _loginService: LoginService |
| 36 | + ) { |
| 37 | + super(injector); |
| 38 | + } |
16 | 39 |
|
17 |
| - model: RegisterInput = new RegisterInput(); |
| 40 | + back(): void { |
| 41 | + this._router.navigate(["/login"]); |
| 42 | + } |
18 | 43 |
|
19 |
| - saving: boolean = false; |
| 44 | + save(): void { |
| 45 | + this.saving = true; |
| 46 | + this._accountService |
| 47 | + .register(this.model) |
| 48 | + .pipe( |
| 49 | + finalize(() => { |
| 50 | + this.saving = false; |
| 51 | + }) |
| 52 | + ) |
| 53 | + .subscribe((result: RegisterOutput) => { |
| 54 | + if (!result.canLogin) { |
| 55 | + this.notify.success(this.l("SuccessfullyRegistered")); |
| 56 | + this._router.navigate(["/login"]); |
| 57 | + return; |
| 58 | + } |
20 | 59 |
|
21 |
| - constructor( |
22 |
| - injector: Injector, |
23 |
| - private _accountService: AccountServiceProxy, |
24 |
| - private _router: Router, |
25 |
| - private readonly _loginService: LoginService |
26 |
| - ) { |
27 |
| - super(injector); |
28 |
| - } |
29 |
| - |
30 |
| - ngAfterViewInit(): void { |
31 |
| - $(this.cardBody.nativeElement).find('input:first').focus(); |
32 |
| - } |
33 |
| - |
34 |
| - back(): void { |
35 |
| - this._router.navigate(['/login']); |
36 |
| - } |
37 |
| - |
38 |
| - save(): void { |
| 60 | + //Autheticate |
39 | 61 | this.saving = true;
|
40 |
| - this._accountService.register(this.model) |
41 |
| - .pipe(finalize(() => { this.saving = false; })) |
42 |
| - .subscribe((result:RegisterOutput) => { |
43 |
| - if (!result.canLogin) { |
44 |
| - this.notify.success(this.l('SuccessfullyRegistered')); |
45 |
| - this._router.navigate(['/login']); |
46 |
| - return; |
47 |
| - } |
48 |
| - |
49 |
| - //Autheticate |
50 |
| - this.saving = true; |
51 |
| - this._loginService.authenticateModel.userNameOrEmailAddress = this.model.userName; |
52 |
| - this._loginService.authenticateModel.password = this.model.password; |
53 |
| - this._loginService.authenticate(() => { this.saving = false; }); |
54 |
| - }); |
55 |
| - } |
| 62 | + this._loginService.authenticateModel.userNameOrEmailAddress = this.model.userName; |
| 63 | + this._loginService.authenticateModel.password = this.model.password; |
| 64 | + this._loginService.authenticate(() => { |
| 65 | + this.saving = false; |
| 66 | + }); |
| 67 | + }); |
| 68 | + } |
56 | 69 | }
|
0 commit comments