sign-in.component.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { Component, OnInit } from '@angular/core';
  2. import { BaseForm } from '../../../core/base/base-form';
  3. import { ComponentBase } from '@core/base/common-base';
  4. import {
  5. FormGroup,
  6. UntypedFormControl,
  7. UntypedFormGroup,
  8. Validators,
  9. } from '@angular/forms';
  10. import { AuthService } from '@core/services/authentication/auth.service';
  11. import { takeUntil } from 'rxjs';
  12. import { Router } from '@angular/router';
  13. import { ToastrService } from 'ngx-toastr';
  14. @Component({
  15. selector: 'app-sign-in',
  16. templateUrl: './sign-in.component.html',
  17. styleUrls: ['./sign-in.component.scss'],
  18. })
  19. export class SignInComponent extends ComponentBase implements BaseForm, OnInit {
  20. hide: boolean = true;
  21. form!: FormGroup;
  22. constructor(
  23. private readonly authService: AuthService,
  24. private readonly router: Router,
  25. private readonly toastr: ToastrService
  26. ) {
  27. super();
  28. }
  29. ngOnInit(): void {
  30. this.initForm();
  31. }
  32. initForm(): void {
  33. this.form = new UntypedFormGroup({
  34. email: new UntypedFormControl(null, [
  35. Validators.email,
  36. Validators.required,
  37. ]),
  38. password: new UntypedFormControl(null, [Validators.required]),
  39. });
  40. }
  41. onSubmit(): void {
  42. if (super.submitValidity(this.form)) {
  43. this.authService
  44. .Login(this.form.value)
  45. .pipe(takeUntil(this.destroy$))
  46. .subscribe((response) => {
  47. console.log(response);
  48. this.router.navigate(['/modules']);
  49. });
  50. }
  51. }
  52. }