debug logout + affichage du prénom dans la page de l'application
This commit is contained in:
@@ -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";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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";
|
||||
|
||||
@@ -1,9 +1,18 @@
|
||||
<!doctype html>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
<head><meta charset="utf-8"/><title>Accueil</title></head>
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<title>Accueil</title></head>
|
||||
<body>
|
||||
<h1>Bienvenue sur FotoSharing</h1>
|
||||
<h1>Bienvenue sur FotoSharing<span th:if="${prenom}" th:text="' : ' + ${prenom}"></span></h1>
|
||||
<p><a th:href="@{/upload}">Uploader une photo</a></p>
|
||||
<p><a th:href="@{/logout}">Se déconnecter</a></p>
|
||||
<p>
|
||||
<form th:action="@{/logout}" method="post" style="display: inline;">
|
||||
<button type="submit"
|
||||
style="background: none; border: none; color: blue; text-decoration: underline; cursor: pointer;">
|
||||
Se déconnecter
|
||||
</button>
|
||||
</form>
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -1,9 +1,18 @@
|
||||
<!doctype html>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
<head><meta charset="utf-8"/><title>Accueil</title></head>
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<title>Accueil</title></head>
|
||||
<body>
|
||||
<h1>Bienvenue sur FotoSharing</h1>
|
||||
<h1>Bienvenue sur FotoSharing<span th:if="${prenom}" th:text="' : ' + ${prenom}"></span></h1>
|
||||
<p><a th:href="@{/upload}">Uploader une photo</a></p>
|
||||
<p><a th:href="@{/logout}">Se déconnecter</a></p>
|
||||
<p>
|
||||
<form th:action="@{/logout}" method="post" style="display: inline;">
|
||||
<button type="submit"
|
||||
style="background: none; border: none; color: blue; text-decoration: underline; cursor: pointer;">
|
||||
Se déconnecter
|
||||
</button>
|
||||
</form>
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user