Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { ABaseComponent } from 'projects/gephymat-web/src/app/BaseComponent';
- import { ApplicationService, UserType } from 'gephymat-core';
- import { HttpErrorResponse, HttpStatusCode } from '@angular/common/http';
- import {
- Component,
- OnInit,
- OnDestroy,
- ChangeDetectionStrategy,
- } from '@angular/core';
- import {
- FormBuilder,
- FormControl,
- FormGroup,
- Validators,
- } from '@angular/forms';
- import { ActivatedRoute, Router } from '@angular/router';
- import { AuthService } from '@modules/auth/services/auth.service';
- import { IAuthRequest } from '@modules/auth/models';
- import { AlertComponent } from '@modules/shared/components/alert/alert.component';
- import { MdbNotificationService } from 'mdb-angular-ui-kit/notification';
- import {
- catchError,
- delay,
- finalize,
- first,
- of,
- tap,
- BehaviorSubject,
- } from 'rxjs';
- @Component({
- selector: 'app-login-form',
- templateUrl: './login-form.component.html',
- changeDetection: ChangeDetectionStrategy.OnPush, // doesn't seem to help :(
- })
- export class LoginFormComponent
- extends ABaseComponent
- implements OnInit, OnDestroy
- {
- public loginForm: FormGroup;
- constructor(
- private fb: FormBuilder,
- private notificationService: MdbNotificationService,
- private authService: AuthService,
- private route: ActivatedRoute,
- private router: Router
- ) {
- super();
- this.loginForm = this.fb.group({
- username: this.fb.control(null, [
- Validators.required,
- Validators.minLength(5),
- Validators.maxLength(60),
- ]),
- password: this.fb.control(null, [
- Validators.required,
- Validators.minLength(3),
- Validators.maxLength(30),
- ]),
- });
- }
- public ngOnInit(): void {
- this.stopLoading();
- this.sub(
- this.authService.runAuthenticationCheck().subscribe((result: boolean) => {
- if (result) this.router.navigate(this.returnUrl);
- })
- );
- }
- public ngOnDestroy() {
- super.onDestroy();
- }
- private get returnUrl(): string[] {
- const _returnUrl = this.route.snapshot.queryParams['returnUrl'];
- if (!!_returnUrl) return [`/${_returnUrl}`];
- return [''];
- }
- public submit(): void {
- // removed
- }
- public get username() {
- return this.loginForm.get('username');
- }
- public get isUsernameInvalid() {
- return (
- this.username?.invalid && (this.username?.dirty || this.username?.touched)
- );
- }
- public get password() {
- return this.loginForm.get('password');
- }
- public get isPasswordInvalid() {
- return (
- this.password?.invalid && (this.password?.dirty || this.password?.touched)
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement