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 { LoginService } from '../../services/login.service';
|
||||||
import { FormsModule, ReactiveFormsModule, Validators } from '@angular/forms';
|
import { FormsModule, ReactiveFormsModule, Validators } from '@angular/forms';
|
||||||
import { FormBuilder } from '@angular/forms';
|
import { FormBuilder } from '@angular/forms';
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
import { FormGroup } from '@angular/forms';
|
import { FormGroup } from '@angular/forms';
|
||||||
import { User } from '../../model/User';
|
import { User } from '../../model/User';
|
||||||
|
import { LocalStorageService } from '../../services/localstorage.service';
|
||||||
|
import { NgIf } from '@angular/common';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-login-page',
|
selector: 'app-login-page',
|
||||||
imports: [FormsModule, ReactiveFormsModule],
|
imports: [FormsModule, ReactiveFormsModule, NgIf],
|
||||||
templateUrl: './login-page.component.html',
|
templateUrl: './login-page.component.html',
|
||||||
styleUrl: './login-page.component.css'
|
styleUrl: './login-page.component.css'
|
||||||
})
|
})
|
||||||
export class LoginPageComponent {
|
export class LoginPageComponent {
|
||||||
|
|
||||||
userForm: FormGroup;
|
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({
|
this.userForm = this.fb.group({
|
||||||
login: [this.user.login, [Validators.required, Validators.minLength(3)]],
|
login: [this.user.login, [Validators.required, Validators.minLength(3)]],
|
||||||
password: [this.user.password, [Validators.required, Validators.minLength(3)]],
|
password: [this.user.password, [Validators.required, Validators.minLength(3)]],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public login(){
|
public login(){
|
||||||
if (this.userForm.invalid){
|
if (this.userForm.invalid){
|
||||||
|
this.errorMessage = "Veuillez remplir tous les champs";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let login = this.userForm.value.login;
|
this.user.login = this.userForm.value.login;
|
||||||
let password = this.userForm.value.password
|
this.user.password = this.userForm.value.password;
|
||||||
|
|
||||||
this.user.login = login;
|
this.loginService.login(this.user.login, this.user.password).subscribe({
|
||||||
this.user.password = password;
|
next: (response) => {
|
||||||
|
console.log("Connexion OK: ", response);
|
||||||
|
this.localStorageService.setToken(response.access_token);
|
||||||
|
this.closeModal();
|
||||||
|
setTimeout(() => {
|
||||||
|
this.router.navigate(['/map']);
|
||||||
|
}, 500);
|
||||||
|
},
|
||||||
|
|
||||||
|
error: (response) => {
|
||||||
|
console.log("Connexion KO: ", response.error.detail);
|
||||||
|
this.errorMessage = response.error.detail;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
console.log(this.loginService.login(login,password));
|
}
|
||||||
|
|
||||||
|
private closeModal() {
|
||||||
|
const modal = document.getElementById('close-login-modal');
|
||||||
|
if (modal) {
|
||||||
|
modal.click();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in new issue