Skip to content
Snippets Groups Projects
Select Git revision
  • b421df52ed0406c5b0b90c22320cb1550b0b70b6
  • main default protected
  • documentation
  • admin_rights_refactor
4 results

login.component.ts

  • Forked from an inaccessible project.
    login.component.ts 966 B
    import { Component, OnInit } from '@angular/core';
    import { FormControl, FormGroup, Validators } from '@angular/forms';
    import { Router } from '@angular/router';
    import { AuthenticationService } from '../services/authentication.service';
    
    @Component({
      selector: 'app-login',
      templateUrl: './login.component.html',
      styleUrls: ['./login.component.css']
    })
    
    export class LoginComponent implements OnInit {
    
      loginForm = new FormGroup({
        username: new FormControl('', Validators.required),
        password: new FormControl('', Validators.required)
      });
    
      constructor(
        private router: Router,
        private auth: AuthenticationService) { }
    
      ngOnInit(): void {
        if (this.auth.isLoggedIn())
          this.router.navigateByUrl("/");
      }
    
      onSubmit():void {
        const username = this.loginForm.get('username')!.value;
        const password = this.loginForm.get('password')!.value;
    
        this.auth.login(username, password);
        this.router.navigateByUrl("/");
      }
    }