Advertisement
Guest User

Untitled

a guest
Aug 31st, 2022
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. import { ABaseComponent } from 'projects/gephymat-web/src/app/BaseComponent';
  2. import { ApplicationService, UserType } from 'gephymat-core';
  3. import { HttpErrorResponse, HttpStatusCode } from '@angular/common/http';
  4. import {
  5. Component,
  6. OnInit,
  7. OnDestroy,
  8. ChangeDetectionStrategy,
  9. } from '@angular/core';
  10. import {
  11. FormBuilder,
  12. FormControl,
  13. FormGroup,
  14. Validators,
  15. } from '@angular/forms';
  16. import { ActivatedRoute, Router } from '@angular/router';
  17. import { AuthService } from '@modules/auth/services/auth.service';
  18. import { IAuthRequest } from '@modules/auth/models';
  19. import { AlertComponent } from '@modules/shared/components/alert/alert.component';
  20. import { MdbNotificationService } from 'mdb-angular-ui-kit/notification';
  21. import {
  22. catchError,
  23. delay,
  24. finalize,
  25. first,
  26. of,
  27. tap,
  28. BehaviorSubject,
  29. } from 'rxjs';
  30.  
  31. @Component({
  32. selector: 'app-login-form',
  33. templateUrl: './login-form.component.html',
  34. changeDetection: ChangeDetectionStrategy.OnPush, // doesn't seem to help :(
  35. })
  36. export class LoginFormComponent
  37. extends ABaseComponent
  38. implements OnInit, OnDestroy
  39. {
  40. public loginForm: FormGroup;
  41.  
  42. constructor(
  43. private fb: FormBuilder,
  44. private notificationService: MdbNotificationService,
  45. private authService: AuthService,
  46. private route: ActivatedRoute,
  47. private router: Router
  48. ) {
  49. super();
  50. this.loginForm = this.fb.group({
  51. username: this.fb.control(null, [
  52. Validators.required,
  53. Validators.minLength(5),
  54. Validators.maxLength(60),
  55. ]),
  56. password: this.fb.control(null, [
  57. Validators.required,
  58. Validators.minLength(3),
  59. Validators.maxLength(30),
  60. ]),
  61. });
  62. }
  63.  
  64. public ngOnInit(): void {
  65. this.stopLoading();
  66.  
  67. this.sub(
  68. this.authService.runAuthenticationCheck().subscribe((result: boolean) => {
  69. if (result) this.router.navigate(this.returnUrl);
  70. })
  71. );
  72. }
  73.  
  74. public ngOnDestroy() {
  75. super.onDestroy();
  76. }
  77.  
  78. private get returnUrl(): string[] {
  79. const _returnUrl = this.route.snapshot.queryParams['returnUrl'];
  80. if (!!_returnUrl) return [`/${_returnUrl}`];
  81. return [''];
  82. }
  83.  
  84. public submit(): void {
  85. // removed
  86. }
  87.  
  88. public get username() {
  89. return this.loginForm.get('username');
  90. }
  91.  
  92. public get isUsernameInvalid() {
  93. return (
  94. this.username?.invalid && (this.username?.dirty || this.username?.touched)
  95. );
  96. }
  97.  
  98. public get password() {
  99. return this.loginForm.get('password');
  100. }
  101.  
  102. public get isPasswordInvalid() {
  103. return (
  104. this.password?.invalid && (this.password?.dirty || this.password?.touched)
  105. );
  106. }
  107. }
  108.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement