diff --git a/src/main/java/fr/eni/enchere/controllers/ProfileController.java b/src/main/java/fr/eni/enchere/controllers/ProfilController.java similarity index 65% rename from src/main/java/fr/eni/enchere/controllers/ProfileController.java rename to src/main/java/fr/eni/enchere/controllers/ProfilController.java index f484fa3..ec2be31 100644 --- a/src/main/java/fr/eni/enchere/controllers/ProfileController.java +++ b/src/main/java/fr/eni/enchere/controllers/ProfilController.java @@ -1,24 +1,22 @@ package fr.eni.enchere.controllers; import fr.eni.enchere.bo.UserProfil; -import fr.eni.enchere.dal.UserRepository; import org.springframework.ui.Model; import fr.eni.enchere.bll.UserService; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; @Controller() -@RequestMapping("/profile") -public class ProfileController { +@RequestMapping("/profil") +public class ProfilController { private final UserService userService; - public ProfileController(UserService userService) { + public ProfilController(UserService userService) { this.userService = userService; } @@ -27,7 +25,7 @@ public class ProfileController { // Obtenez l'authentification actuelle Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); // Vérifiez si l'utilisateur est authentifié - if (!authentication.getName().equals("anonymousUser")) { //Retirer le true pour le bon fonctionnement + if (!authentication.getName().equals("anonymousUser")) { // Obtenez les détails de l'utilisateur authentifié String username = authentication.getName(); // Utilisez le service approprié pour récupérer les informations de l'utilisateur à partir du nom d'utilisateur @@ -35,14 +33,33 @@ public class ProfileController { // Ajoutez les informations du profil à l'objet Model pour les afficher dans la page HTML // model.addAttribute("user", new UserProfil()); model.addAttribute("userProfile", userProfile); - return "profile"; + return "profil"; + }else { + return "accueil"; + } + } + + @PostMapping("/edit") + public String editProfile(Model model) { + // Obtenez l'authentification actuelle + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + // Vérifiez si l'utilisateur est authentifié + if (!authentication.getName().equals("anonymousUser")) { + // Obtenez les détails de l'utilisateur authentifié + String username = authentication.getName(); + // Utilisez le service approprié pour récupérer les informations de l'utilisateur à partir du nom d'utilisateur + UserProfil userProfile = userService.utilisateurByName(username); + // Ajoutez les informations du profil à l'objet Model pour les afficher dans la page HTML +// model.addAttribute("user", new UserProfil()); + model.addAttribute("userProfile", userProfile); + return "editProfil"; }else { return "accueil"; } } @PostMapping("/delete") - public String setUser() { + public String deleteUser() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); // Obtenez les détails de l'utilisateur authentifié String username = authentication.getName(); diff --git a/src/main/java/fr/eni/enchere/security/WebSecurityConfig.java b/src/main/java/fr/eni/enchere/security/WebSecurityConfig.java index 3584d9f..076a4fd 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", "/profile/**", "/change-language").permitAll() + .requestMatchers("/accueil", "/login", "/inscription/**", "/searchArticle", "/article/**", "/change-language", "/profile/**").permitAll() .requestMatchers("/css/**", "/images/**", "/assets/**", "/img/**", "/js/**").permitAll() - .requestMatchers("/article/**").authenticated() + .requestMatchers("/profile/**").authenticated() .requestMatchers("/admin").hasRole("ADMIN") .anyRequest().authenticated()) .formLogin((form) -> form.loginPage("/login").defaultSuccessUrl("/", true)) diff --git a/src/main/resources/templates/profile.html b/src/main/resources/templates/editProfil.html similarity index 87% rename from src/main/resources/templates/profile.html rename to src/main/resources/templates/editProfil.html index 748111a..ca6c711 100644 --- a/src/main/resources/templates/profile.html +++ b/src/main/resources/templates/editProfil.html @@ -1,5 +1,5 @@ - + @@ -107,6 +107,17 @@ +
+ +
+ +
+ + + +
@@ -125,10 +136,11 @@
Crédits:
+ -
+
diff --git a/src/main/resources/templates/inscription.html b/src/main/resources/templates/inscription.html index 33b34c7..9278e53 100644 --- a/src/main/resources/templates/inscription.html +++ b/src/main/resources/templates/inscription.html @@ -125,7 +125,7 @@ -
+
diff --git a/src/main/resources/templates/modele-page.html b/src/main/resources/templates/modele-page.html index 708f1e8..5bbc9d2 100644 --- a/src/main/resources/templates/modele-page.html +++ b/src/main/resources/templates/modele-page.html @@ -25,7 +25,7 @@ Vendre un article