parent
83423751aa
commit
703d33818b
@ -0,0 +1,9 @@
|
||||
#authentication-modal.show {
|
||||
opacity: 1;
|
||||
transition: opacity 0.3s ease-in-out;
|
||||
}
|
||||
|
||||
#authentication-modal.hidden {
|
||||
opacity: 0;
|
||||
transition: opacity 0.3s ease-in-out;
|
||||
}
|
@ -1,41 +1,63 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { Component, Renderer2 } from '@angular/core';
|
||||
import { LoginService } from '../../services/login.service';
|
||||
import { FormsModule, ReactiveFormsModule, Validators } from '@angular/forms';
|
||||
import { FormBuilder } from '@angular/forms';
|
||||
import { Router } from '@angular/router';
|
||||
import { FormGroup } from '@angular/forms';
|
||||
import { User } from '../../model/User';
|
||||
import { LocalStorageService } from '../../services/localstorage.service';
|
||||
import { NgIf } from '@angular/common';
|
||||
|
||||
@Component({
|
||||
selector: 'app-login-page',
|
||||
imports: [FormsModule, ReactiveFormsModule],
|
||||
imports: [FormsModule, ReactiveFormsModule, NgIf],
|
||||
templateUrl: './login-page.component.html',
|
||||
styleUrl: './login-page.component.css'
|
||||
})
|
||||
export class LoginPageComponent {
|
||||
|
||||
userForm: FormGroup;
|
||||
user: User = {login: '', password: ''}
|
||||
user: User = {login: '', password: ''};
|
||||
errorMessage: string = '';
|
||||
|
||||
constructor(private loginService: LoginService, private fb: FormBuilder, private router: Router) {
|
||||
constructor(private loginService: LoginService, private fb: FormBuilder, private router: Router, private localStorageService: LocalStorageService, private renderer: Renderer2) {
|
||||
this.userForm = this.fb.group({
|
||||
login: [this.user.login, [Validators.required, Validators.minLength(3)]],
|
||||
password: [this.user.password, [Validators.required, Validators.minLength(3)]],
|
||||
});
|
||||
}
|
||||
|
||||
public login(){
|
||||
public login(){
|
||||
if (this.userForm.invalid){
|
||||
this.errorMessage = "Veuillez remplir tous les champs";
|
||||
return;
|
||||
}
|
||||
|
||||
let login = this.userForm.value.login;
|
||||
let password = this.userForm.value.password
|
||||
this.user.login = this.userForm.value.login;
|
||||
this.user.password = this.userForm.value.password;
|
||||
|
||||
this.user.login = login;
|
||||
this.user.password = password;
|
||||
this.loginService.login(this.user.login, this.user.password).subscribe({
|
||||
next: (response) => {
|
||||
console.log("Connexion OK: ", response);
|
||||
this.localStorageService.setToken(response.access_token);
|
||||
this.closeModal();
|
||||
setTimeout(() => {
|
||||
this.router.navigate(['/map']);
|
||||
}, 500);
|
||||
},
|
||||
|
||||
console.log(this.loginService.login(login,password));
|
||||
error: (response) => {
|
||||
console.log("Connexion KO: ", response.error.detail);
|
||||
this.errorMessage = response.error.detail;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private closeModal() {
|
||||
const modal = document.getElementById('close-login-modal');
|
||||
if (modal) {
|
||||
modal.click();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in new issue