Implement authentication feature with role-based access control and login dialog

This commit is contained in:
2025-11-07 17:53:11 +01:00
parent 87a1ab06d9
commit b4f0b7256a
11 changed files with 224 additions and 7 deletions

View File

@@ -0,0 +1,40 @@
import { Component, Inject, inject } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { FormControl, Validators } from '@angular/forms';
import { AuthService, User } from '../auth.service';
@Component({
selector: 'app-login',
standalone: false,
templateUrl: './login.dialog.html',
styleUrls: ['./login.dialog.css'],
})
export class LoginDialog {
auth = inject(AuthService);
passwordControl = new FormControl('', Validators.required);
constructor(
private dialogRef: MatDialogRef<LoginDialog>,
@Inject(MAT_DIALOG_DATA) public data: { user: User }
) {}
submit(): void {
const role = this.data.user.role;
if (!this.passwordControl.value) {
this.passwordControl.setErrors({ required: true });
this.passwordControl.markAsTouched();
return;
}
if (!this.auth.login(role, this.passwordControl.value)) {
this.passwordControl.setErrors({ wrongPassword: true });
this.passwordControl.markAsTouched();
return;
}
this.dialogRef.close(true);
}
cancel(): void {
this.dialogRef.close(false);
}
}