Broker System for Supercredit
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

82 Zeilen
2.4KB

  1. import { Component, OnDestroy, OnInit } from '@angular/core';
  2. import { FormControl, FormGroup, Validators } from '@angular/forms';
  3. import { Router } from '@angular/router';
  4. import { NotificationService } from '@progress/kendo-angular-notification';
  5. import { Subscription } from 'rxjs';
  6. import { AuthService } from '../service/auth.service';
  7. import {apiV1LoginResponse} from '../models/api-v1-login-response';
  8. @Component({
  9. selector: 'app-auth',
  10. templateUrl: './auth.component.html',
  11. styleUrls: ['./auth.component.scss']
  12. })
  13. export class AuthComponent implements OnInit, OnDestroy{
  14. loading: boolean ; // a state that user is currently loading loggin
  15. loginSub: Subscription;
  16. public userForm: FormGroup = new FormGroup({
  17. password: new FormControl('pass', [Validators.minLength(3), Validators.maxLength(20)]),
  18. email: new FormControl('admin@supercredit.com.au', Validators.email)
  19. });
  20. constructor(private authService: AuthService, private router: Router, private notificationService: NotificationService) { }
  21. ngOnInit(): void {
  22. this.authService.logout();
  23. this.loginSub = this.authService.loginSuccess.subscribe(
  24. responseData => {
  25. // console.log(responseData);
  26. this.onLogin(responseData);
  27. }
  28. );
  29. }
  30. ngOnDestroy(): void {
  31. this.loginSub.unsubscribe();
  32. }
  33. // tslint:disable-next-line:typedef
  34. submitForm() {
  35. console.log(this.userForm);
  36. this.loading = true;
  37. this.authService.login(this.userForm.value.email, this.userForm.value.password);
  38. }
  39. public onLogin(rsp: apiV1LoginResponse): void {
  40. this.loading = false;
  41. // console.log ('found login ' , rsp );
  42. if (rsp.login) {
  43. switch ( rsp.role ) {
  44. case 'admin':
  45. this.router.navigate(['/dashboard']);
  46. break;
  47. case 'broker':
  48. this.router.navigate(['/broker-loan-list']);
  49. break;
  50. case 'user':
  51. this.router.navigate(['/client-loan-list']);
  52. break;
  53. default:
  54. this.router.navigate(['/e403']);
  55. break;
  56. }
  57. }
  58. else {
  59. this.show();
  60. }
  61. }
  62. public show(): void {
  63. this.notificationService.show({
  64. content: 'Your loggin is failed, please try again.',
  65. cssClass: 'button-notification',
  66. animation: { type: 'slide', duration: 400 },
  67. position: { horizontal: 'center', vertical: 'top' },
  68. type: { style: 'error', icon: true },
  69. hideAfter : 2000
  70. });
  71. }
  72. }