git init v2

This commit is contained in:
2025-03-11 23:13:19 +01:00
parent 4d4c8a362a
commit abae328d8f
62 changed files with 3461 additions and 421 deletions

View File

@@ -0,0 +1,57 @@
import {Component} from '@angular/core';
import {FormControl, FormGroup, ReactiveFormsModule, Validators} from '@angular/forms';
import {Router} from '@angular/router';
import {TuiAppearance, TuiButton, TuiError, TuiTextfield,} from '@taiga-ui/core';
import {TuiCardLarge, TuiForm, TuiHeader} from '@taiga-ui/layout';
import {AuthService} from '../../services/auth.service';
import {UserDto} from '../../models/user-dto';
import {HttpErrorResponse} from '@angular/common/http';
import {TuiValidationError} from '@taiga-ui/cdk';
@Component({
selector: 'app-login',
imports: [
ReactiveFormsModule,
TuiAppearance,
TuiButton,
TuiCardLarge,
TuiForm,
TuiHeader,
TuiTextfield,
TuiError,
],
templateUrl: './login.component.html',
styleUrl: './login.component.scss'
})
export class LoginComponent {
form: FormGroup;
protected enabled = false;
protected error = new TuiValidationError('Ongeldige gebruikersnaam of wachtwoord.');
protected get computedError(): TuiValidationError | null {
return this.enabled ? this.error : null;
}
constructor(private router: Router, private authService: AuthService) {
this.form = new FormGroup({
username: new FormControl('', Validators.required),
password: new FormControl('', Validators.required)
});
}
login() {
this.authService.login(this.form.get('username').value, this.form.get('password').value).subscribe({
next: (user: UserDto) => {
localStorage.setItem('token', user.token);
this.router.navigate(['/home/agenda']);
},
error: (err: HttpErrorResponse) => {
if (err.status === 401) {
this.enabled = true;
}
},
});
}
}