Broker System for Supercredit
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

62 lines
1.8KB

  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. @Component({
  8. selector: 'app-auth',
  9. templateUrl: './auth.component.html',
  10. styleUrls: ['./auth.component.scss']
  11. })
  12. export class AuthComponent implements OnInit, OnDestroy{
  13. loading : boolean ; // a state that user is currently loading loggin
  14. loginSub: Subscription;
  15. public userForm: FormGroup = new FormGroup({
  16. password: new FormControl('password', [Validators.minLength(3), Validators.maxLength(20)]),
  17. email: new FormControl('email@email.com', Validators.email)
  18. });
  19. constructor(private authService: AuthService, private rounter: Router, private notificationService: NotificationService) { }
  20. ngOnInit(): void {
  21. this.loginSub = this.authService.loginSuccess.subscribe(
  22. (ok:boolean) =>{this.onLogin(ok)}
  23. );
  24. }
  25. ngOnDestroy(): void {
  26. this.loginSub.unsubscribe();
  27. }
  28. submitForm() {
  29. console.log(this.userForm);
  30. this.loading = true;
  31. this.authService.login(this.userForm.value.email, this.userForm.value.password);
  32. }
  33. public onLogin(ok:boolean) {
  34. this.loading = false
  35. console.log (" found login success " + ok );
  36. if (ok)
  37. this.rounter.navigate(["/dashboard"]);
  38. else
  39. this.show();
  40. }
  41. public show(): void {
  42. this.notificationService.show({
  43. content: 'Your loggin is failed, please try again.',
  44. cssClass: 'button-notification',
  45. animation: { type: 'slide', duration: 400 },
  46. position: { horizontal: 'center', vertical: 'top' },
  47. type: { style: 'error', icon: true },
  48. hideAfter : 2000
  49. });
  50. }
  51. }