2024-09-17 08:14:28 +00:00
|
|
|
import { Component } from '@angular/core';
|
2024-10-16 10:13:13 +00:00
|
|
|
import { Router, RouterModule } from '@angular/router';
|
|
|
|
|
import { AuthService } from '../../cores/services/auth.service';
|
|
|
|
|
import { FormsModule } from '@angular/forms';
|
|
|
|
|
import { LoginData } from '../../cores/interface/auth';
|
|
|
|
|
import { ToastrService } from 'ngx-toastr';
|
2024-09-17 08:14:28 +00:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-auth',
|
|
|
|
|
standalone: true,
|
2024-10-16 10:13:13 +00:00
|
|
|
imports: [FormsModule, RouterModule],
|
2024-09-17 08:14:28 +00:00
|
|
|
templateUrl: './auth.component.html',
|
2024-10-16 10:13:13 +00:00
|
|
|
styleUrls: ['./auth.component.scss']
|
2024-09-17 08:14:28 +00:00
|
|
|
})
|
|
|
|
|
export class AuthComponent {
|
2024-10-16 10:13:13 +00:00
|
|
|
email: string = '';
|
|
|
|
|
password: string = '';
|
|
|
|
|
rememberMe: boolean = false;
|
|
|
|
|
|
|
|
|
|
constructor(private authService: AuthService, private router: Router, private toastr: ToastrService) {}
|
2024-09-17 08:14:28 +00:00
|
|
|
|
2024-10-16 10:13:13 +00:00
|
|
|
onSubmit() {
|
|
|
|
|
const loginData: LoginData = {
|
|
|
|
|
email: this.email,
|
|
|
|
|
password: this.password,
|
|
|
|
|
rememberMe: this.rememberMe
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this.authService.login(loginData).subscribe(
|
|
|
|
|
(response) => {
|
|
|
|
|
this.authService.saveTokens(response.data.token);
|
|
|
|
|
this.router.navigate(['/dashboard']);
|
|
|
|
|
this.toastr.success('Login successful');
|
|
|
|
|
},
|
|
|
|
|
(error) => {
|
|
|
|
|
this.toastr.error(error.error.message);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|