Select Git revision
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("/");
}
}