44 lines
1.5 KiB
TypeScript
44 lines
1.5 KiB
TypeScript
import {Component, inject, OnInit} from '@angular/core';
|
|
import {NzColDirective} from "ng-zorro-antd/grid";
|
|
import {NzFormControlComponent, NzFormDirective, NzFormItemComponent, NzFormLabelComponent} from "ng-zorro-antd/form";
|
|
import {NzInputDirective} from "ng-zorro-antd/input";
|
|
import {FormControl, FormGroup, ReactiveFormsModule, Validators} from "@angular/forms";
|
|
import {NzButtonComponent} from "ng-zorro-antd/button";
|
|
import {AuthService} from "../../services/auth.service";
|
|
import {Router} from "@angular/router";
|
|
|
|
@Component({
|
|
selector: 'app-login',
|
|
imports: [
|
|
NzColDirective,
|
|
NzFormControlComponent,
|
|
NzFormDirective,
|
|
NzFormItemComponent,
|
|
NzFormLabelComponent,
|
|
NzInputDirective,
|
|
ReactiveFormsModule,
|
|
NzButtonComponent
|
|
],
|
|
templateUrl: './login.html',
|
|
styleUrl: './login.css',
|
|
})
|
|
export class Login implements OnInit {
|
|
private authService = inject(AuthService);
|
|
private router = inject(Router);
|
|
|
|
ngOnInit() {
|
|
this.authService.logout();
|
|
}
|
|
|
|
loginForm: FormGroup = new FormGroup({
|
|
name: new FormControl<string>(null, [Validators.required]),
|
|
password: new FormControl<string>(null, [Validators.required])
|
|
})
|
|
|
|
async connectUser() {
|
|
if (this.loginForm.invalid) return;
|
|
const ok = await this.authService.connectUser(this.loginForm.value.name, this.loginForm.value.password);
|
|
if (ok) await this.router.navigate(['/dashboard']);
|
|
}
|
|
}
|