51 lines
1.4 KiB
TypeScript
51 lines
1.4 KiB
TypeScript
import { Component, Inject, Input } from '@angular/core';
|
|
import { AuthenticationService } from '../services/authentication.service';
|
|
import Swal from 'sweetalert2';
|
|
import { MAT_DIALOG_DATA } from '@angular/material/dialog';
|
|
import { CommonModule } from '@angular/common';
|
|
import { FormsModule } from '@angular/forms';
|
|
|
|
@Component({
|
|
standalone: true,
|
|
imports: [CommonModule, FormsModule],
|
|
selector: 'app-login',
|
|
templateUrl: './login.component.html',
|
|
styleUrl: './login.component.css'
|
|
})
|
|
export class LoginComponent {
|
|
|
|
username: string = '';
|
|
password: string = '';
|
|
|
|
waitRes: boolean = false;
|
|
|
|
IsPwdHidden: boolean = true;
|
|
|
|
constructor(private authService: AuthenticationService, @Inject(MAT_DIALOG_DATA) public data: any) {
|
|
//localStorage.getItem('theme') === 'dark'
|
|
if (typeof (this.afterLogin) == typeof (data.afterLogin))
|
|
this.afterLogin = data.afterLogin;
|
|
}
|
|
|
|
@Input() afterLogin: () => void = () => { }
|
|
|
|
login(): void {
|
|
this.waitRes = true;
|
|
this.authService.login(this.username, this.password).subscribe({
|
|
next: () => this.afterLogin(),
|
|
error: (err) => {
|
|
this.waitRes = false;
|
|
Swal.fire({
|
|
icon: "error",
|
|
title: "Oops...",
|
|
text: err.error.messages.join("\n"),
|
|
});
|
|
},
|
|
complete: () => this.waitRes = false
|
|
})
|
|
}
|
|
onPasswordEyeClicked() {
|
|
this.IsPwdHidden = !this.IsPwdHidden;
|
|
}
|
|
}
|