first commit
This commit is contained in:
49
frontend/src/app/features/auth/login-page.component.ts
Normal file
49
frontend/src/app/features/auth/login-page.component.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { Component, inject } from '@angular/core';
|
||||
import { FormBuilder, ReactiveFormsModule, Validators } from '@angular/forms';
|
||||
import { Router, RouterLink } from '@angular/router';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { ButtonModule } from 'primeng/button';
|
||||
import { InputTextModule } from 'primeng/inputtext';
|
||||
|
||||
import { AuthService } from '../../core/services/auth.service';
|
||||
import { UiService } from '../../core/services/ui.service';
|
||||
import { AuthToolbarComponent } from '../../shared/auth/auth-toolbar.component';
|
||||
|
||||
@Component({
|
||||
standalone: true,
|
||||
imports: [CommonModule, ReactiveFormsModule, RouterLink, TranslateModule, ButtonModule, InputTextModule, AuthToolbarComponent],
|
||||
templateUrl: './login-page.component.html'
|
||||
})
|
||||
export class LoginPageComponent {
|
||||
private readonly fb = inject(FormBuilder);
|
||||
private readonly auth = inject(AuthService);
|
||||
private readonly router = inject(Router);
|
||||
private readonly ui = inject(UiService);
|
||||
|
||||
error = '';
|
||||
submitting = false;
|
||||
readonly form = this.fb.nonNullable.group({
|
||||
username: ['', Validators.required],
|
||||
password: ['', Validators.required]
|
||||
});
|
||||
|
||||
submit() {
|
||||
if (this.form.invalid || this.submitting) {
|
||||
return;
|
||||
}
|
||||
this.error = '';
|
||||
this.submitting = true;
|
||||
const { username, password } = this.form.getRawValue();
|
||||
this.auth.login(username, password).subscribe({
|
||||
next: () => this.router.navigate(['/']),
|
||||
error: (err) => {
|
||||
this.error = err?.error?.detail ?? this.ui.instant('auth.loginFailed');
|
||||
this.submitting = false;
|
||||
},
|
||||
complete: () => {
|
||||
this.submitting = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user