From 07b47b3f41f405594bf363237b8ff5f1f7bfe671 Mon Sep 17 00:00:00 2001 From: Parpaillax Date: Wed, 24 Apr 2024 10:07:02 +0200 Subject: [PATCH] test --- .../java/fr/eni/enchere/bo/UserProfil.java | 21 ++++++++++++++++++- .../controllers/InscriptionController.java | 4 ++-- .../enchere/controllers/ProfilController.java | 11 ++++++++++ .../enchere/security/WebSecurityConfig.java | 4 ++-- src/main/resources/templates/editProfil.html | 4 ++-- 5 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/main/java/fr/eni/enchere/bo/UserProfil.java b/src/main/java/fr/eni/enchere/bo/UserProfil.java index 9677c64..f0d49b4 100644 --- a/src/main/java/fr/eni/enchere/bo/UserProfil.java +++ b/src/main/java/fr/eni/enchere/bo/UserProfil.java @@ -14,13 +14,15 @@ public class UserProfil { private String ville; private String password; private String confirmPassword; + private String currentPassword; + private String newPassword; private float credit; private boolean isAdmin; //Constructeur public UserProfil(){} - public UserProfil(int id, String pseudo, String nom, String prenom, String email, String telephone, String rue, String code_postal, String ville, String password, String confirmPassword, int credit, boolean isAdmin) { + public UserProfil(int id, String pseudo, String nom, String prenom, String email, String telephone, String rue, String code_postal, String ville, String password, String confirmPassword, String newPassword, String currentPassword, int credit, boolean isAdmin) { setId(id); setPrenom(prenom); setNom(nom); @@ -34,6 +36,8 @@ public class UserProfil { setConfirmPassword(confirmPassword); setCredit(credit); setAdmin(isAdmin); + setCurrentPassword(currentPassword); + setNewPassword(newPassword); } //Méthode getter et setter @@ -141,4 +145,19 @@ public class UserProfil { isAdmin = admin; } + public String getCurrentPassword() { + return currentPassword; + } + + public void setCurrentPassword(String currentPassword) { + this.currentPassword = currentPassword; + } + + public String getNewPassword() { + return newPassword; + } + + public void setNewPassword(String newPassword) { + this.newPassword = newPassword; + } } diff --git a/src/main/java/fr/eni/enchere/controllers/InscriptionController.java b/src/main/java/fr/eni/enchere/controllers/InscriptionController.java index 2e9c9a6..f0c3661 100644 --- a/src/main/java/fr/eni/enchere/controllers/InscriptionController.java +++ b/src/main/java/fr/eni/enchere/controllers/InscriptionController.java @@ -41,13 +41,13 @@ public class InscriptionController { // Utilisez le service approprié pour récupérer les informations de l'utilisateur à partir du nom d'utilisateur UserProfil currentUserProfile = userService.utilisateurByName(username); // Vérifiez si le mot de passe actuel correspond à celui stocké dans la base de données - if (!passwordEncoder.matches(userProfile.getPassword(), currentUserProfile.getPassword())) { + if (!passwordEncoder.matches(userProfile.getNewPassword(), currentUserProfile.getPassword())) { // Mot de passe actuel incorrect, renvoyer une erreur result.rejectValue("currentPassword", "invalid", "Mot de passe actuel incorrect"); return "editProfil"; // Rediriger vers la page de modification du profil avec une erreur } // Vérifiez si le nouveau mot de passe et sa confirmation correspondent - if (!userProfile.getPassword().equals(userProfile.getConfirmPassword())) { + if (!userProfile.getNewPassword().equals(userProfile.getConfirmPassword())) { // Mauvaise correspondance entre le nouveau mot de passe et sa confirmation, renvoyer une erreur result.rejectValue("confirmPassword", "invalid", "La confirmation du mot de passe ne correspond pas au nouveau mot de passe"); return "editProfil"; // Rediriger vers la page de modification du profil avec une erreur diff --git a/src/main/java/fr/eni/enchere/controllers/ProfilController.java b/src/main/java/fr/eni/enchere/controllers/ProfilController.java index ec2be31..fe66b44 100644 --- a/src/main/java/fr/eni/enchere/controllers/ProfilController.java +++ b/src/main/java/fr/eni/enchere/controllers/ProfilController.java @@ -39,6 +39,17 @@ public class ProfilController { } } + @GetMapping("/edit") + public String edit(Model model) { + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + if (!authentication.getName().equals("anonymousUser")) { + String username = authentication.getName(); + UserProfil userProfile = userService.utilisateurByName(username); + model.addAttribute("userProfile", userProfile); + } + return "editProfil"; + } + @PostMapping("/edit") public String editProfile(Model model) { // Obtenez l'authentification actuelle diff --git a/src/main/java/fr/eni/enchere/security/WebSecurityConfig.java b/src/main/java/fr/eni/enchere/security/WebSecurityConfig.java index 076a4fd..ddf85c8 100644 --- a/src/main/java/fr/eni/enchere/security/WebSecurityConfig.java +++ b/src/main/java/fr/eni/enchere/security/WebSecurityConfig.java @@ -17,9 +17,9 @@ public class WebSecurityConfig{ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { http.authorizeHttpRequests((requests) -> requests .requestMatchers("/", "/accueil").permitAll() - .requestMatchers("/accueil", "/login", "/inscription/**", "/searchArticle", "/article/**", "/change-language", "/profile/**").permitAll() + .requestMatchers("/accueil", "/login", "/inscription/**", "/searchArticle", "/article/**", "/change-language").permitAll() .requestMatchers("/css/**", "/images/**", "/assets/**", "/img/**", "/js/**").permitAll() - .requestMatchers("/profile/**").authenticated() + .requestMatchers("/profil/**").authenticated() .requestMatchers("/admin").hasRole("ADMIN") .anyRequest().authenticated()) .formLogin((form) -> form.loginPage("/login").defaultSuccessUrl("/", true)) diff --git a/src/main/resources/templates/editProfil.html b/src/main/resources/templates/editProfil.html index cf3aa04..5e8f9db 100644 --- a/src/main/resources/templates/editProfil.html +++ b/src/main/resources/templates/editProfil.html @@ -110,7 +110,7 @@
- +
    @@ -122,7 +122,7 @@
    - +