diff --git a/src/main/java/local/epul4a/fotosharing/controller/AuthController.java b/src/main/java/local/epul4a/fotosharing/controller/AuthController.java index 00052f1..97e58ac 100644 --- a/src/main/java/local/epul4a/fotosharing/controller/AuthController.java +++ b/src/main/java/local/epul4a/fotosharing/controller/AuthController.java @@ -6,6 +6,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; +import org.springframework.security.core.Authentication; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.*; @@ -55,4 +56,18 @@ public class AuthController { return "redirect:/login?registered"; } + + @GetMapping("/") + public String home(Model model, Authentication authentication) { + if (authentication != null && authentication.isAuthenticated()) { + String email = authentication.getName(); + Utilisateur utilisateur = utilisateurRepository.findByEmail(email) + .orElse(null); + if (utilisateur != null) { + model.addAttribute("prenom", utilisateur.getPrenom()); + } + } + return "home"; + } + } \ No newline at end of file diff --git a/src/main/java/local/epul4a/fotosharing/controller/PhotoController.java b/src/main/java/local/epul4a/fotosharing/controller/PhotoController.java index 44902e5..0c45042 100644 --- a/src/main/java/local/epul4a/fotosharing/controller/PhotoController.java +++ b/src/main/java/local/epul4a/fotosharing/controller/PhotoController.java @@ -1,6 +1,7 @@ package local.epul4a.fotosharing.controller; import local.epul4a.fotosharing.model.Photo; +import local.epul4a.fotosharing.model.Utilisateur; import local.epul4a.fotosharing.security.CustomUserDetails; import local.epul4a.fotosharing.service.PhotoService; import org.springframework.core.io.Resource; @@ -8,6 +9,7 @@ import org.springframework.core.io.PathResource; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.security.core.Authentication; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; @@ -25,11 +27,6 @@ public class PhotoController { this.photoService = photoService; } - @GetMapping("/") - public String home() { - return "home"; // créer une page home.html simple - } - @GetMapping("/upload") public String uploadForm() { return "upload"; diff --git a/src/main/resources/templates/home.html b/src/main/resources/templates/home.html index 576f6b6..7bfb3e0 100644 --- a/src/main/resources/templates/home.html +++ b/src/main/resources/templates/home.html @@ -1,9 +1,18 @@ -
+
+ diff --git a/target/classes/local/epul4a/fotosharing/controller/AuthController.class b/target/classes/local/epul4a/fotosharing/controller/AuthController.class index c59934b..41155fc 100644 Binary files a/target/classes/local/epul4a/fotosharing/controller/AuthController.class and b/target/classes/local/epul4a/fotosharing/controller/AuthController.class differ diff --git a/target/classes/local/epul4a/fotosharing/controller/PhotoController.class b/target/classes/local/epul4a/fotosharing/controller/PhotoController.class index ab0a469..48272dc 100644 Binary files a/target/classes/local/epul4a/fotosharing/controller/PhotoController.class and b/target/classes/local/epul4a/fotosharing/controller/PhotoController.class differ diff --git a/target/classes/templates/home.html b/target/classes/templates/home.html index 576f6b6..7bfb3e0 100644 --- a/target/classes/templates/home.html +++ b/target/classes/templates/home.html @@ -1,9 +1,18 @@ -+
+