Ajout galerie publique pour tous les users / anonymes

This commit is contained in:
2025-12-01 21:18:47 +01:00
parent e2c714185b
commit ca3e693969
22 changed files with 60 additions and 2 deletions

View File

@@ -85,6 +85,12 @@ public class PhotoController {
return "mes-photos"; return "mes-photos";
} }
@GetMapping("/galerie")
public String galerie(Model model) {
model.addAttribute("photos", photoService.listPublicPhotos());
return "galerie";
}
} }

View File

@@ -5,6 +5,6 @@ import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List; import java.util.List;
public interface PhotoRepository extends JpaRepository<Photo, Long> { public interface PhotoRepository extends JpaRepository<Photo, Long> {
List<Photo> findByProprietaire_Email(String email); List<Photo> findByProprietaire_Email(String email);
List<Photo> findByVisibilite(Photo.Visibilite visibilite);
} }

View File

@@ -39,7 +39,7 @@ public class SecurityConfig {
http http
.userDetailsService(customUserDetailsService) // Utiliser directement le UserDetailsService .userDetailsService(customUserDetailsService) // Utiliser directement le UserDetailsService
.authorizeHttpRequests(auth -> auth .authorizeHttpRequests(auth -> auth
.requestMatchers("/register", "/login", "/css/**", "/js/**").permitAll() .requestMatchers("/register", "/login", "/css/**", "/js/**", "/photo/*/raw", "/galerie").permitAll()
.anyRequest().authenticated() .anyRequest().authenticated()
) )
.formLogin(form -> form .formLogin(form -> form

View File

@@ -10,5 +10,6 @@ public interface PhotoService {
Photo store(MultipartFile file, String visibilite, String ownerEmail) throws IOException; Photo store(MultipartFile file, String visibilite, String ownerEmail) throws IOException;
Path loadAsPath(String uuidFile); Path loadAsPath(String uuidFile);
List<Photo> listByOwner(String email); List<Photo> listByOwner(String email);
List<Photo> listPublicPhotos();
} }

View File

@@ -64,4 +64,9 @@ public class PhotoServiceImpl implements PhotoService {
public List<Photo> listByOwner(String email) { public List<Photo> listByOwner(String email) {
return photoRepository.findByProprietaire_Email(email); return photoRepository.findByProprietaire_Email(email);
} }
@Override
public List<Photo> listPublicPhotos() {
return photoRepository.findByVisibilite(Photo.Visibilite.PUBLIC);
}
} }

View File

@@ -0,0 +1,17 @@
<!doctype html>
<html xmlns:th="http://www.thymeleaf.org">
<head><meta charset="utf-8"><title>Galerie</title></head>
<body>
<h1>Galerie publique</h1>
<p><a th:href="@{/}">Accueil</a></p>
<ul>
<li th:each="p : ${photos}">
<span th:text="${p.nomFichierOriginal}">nom</span>
<a th:href="@{'/photo/' + ${p.id} + '/raw'}" target="_blank">Voir</a>
</li>
</ul>
</body>
</html>

View File

@@ -7,6 +7,7 @@
<h1>Bienvenue sur FotoSharing<span th:if="${prenom}" th:text="' : ' + ${prenom}"></span></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="@{/upload}">Uploader une photo</a></p>
<p><a th:href="@{/mes-photos}">Voir mes photos</a></p> <p><a th:href="@{/mes-photos}">Voir mes photos</a></p>
<p><a th:href="@{/galerie}">Voir la galerie publique</a></p>
<p> <p>
<form th:action="@{/logout}" method="post" style="display: inline;"> <form th:action="@{/logout}" method="post" style="display: inline;">
<button type="submit" <button type="submit"

View File

@@ -19,5 +19,6 @@
Erreur d'authentification. Erreur d'authentification.
</div> </div>
<p><a th:href="@{/register}">Créer un compte</a></p> <p><a th:href="@{/register}">Créer un compte</a></p>
<p><a th:href="@{/galerie}">Galerie publique</a></p>
</body> </body>
</html> </html>

View File

@@ -22,5 +22,7 @@
</li> </li>
</ul> </ul>
<p><a th:href="@{/galerie}">Galerie publique</a></p>
</body> </body>
</html> </html>

View File

@@ -13,5 +13,6 @@
<label>Mot de passe: <input th:field="*{motDePasse}" type="password"/></label><br/> <label>Mot de passe: <input th:field="*{motDePasse}" type="password"/></label><br/>
<button type="submit">Créer</button> <button type="submit">Créer</button>
</form> </form>
<p><a th:href="@{/galerie}">Galerie publique</a></p>
</body> </body>
</html> </html>

View File

@@ -17,6 +17,7 @@
</label><br/> </label><br/>
<button type="submit">Envoyer</button> <button type="submit">Envoyer</button>
</form> </form>
<p><a th:href="@{/galerie}">Galerie publique</a></p>
<div th:if="${error}" th:text="${error}"></div> <div th:if="${error}" th:text="${error}"></div>
<div th:if="${message}" th:text="${message}"></div> <div th:if="${message}" th:text="${message}"></div>
</body> </body>

View File

@@ -0,0 +1,17 @@
<!doctype html>
<html xmlns:th="http://www.thymeleaf.org">
<head><meta charset="utf-8"><title>Galerie</title></head>
<body>
<h1>Galerie publique</h1>
<p><a th:href="@{/}">Accueil</a></p>
<ul>
<li th:each="p : ${photos}">
<span th:text="${p.nomFichierOriginal}">nom</span>
<a th:href="@{'/photo/' + ${p.id} + '/raw'}" target="_blank">Voir</a>
</li>
</ul>
</body>
</html>

View File

@@ -7,6 +7,7 @@
<h1>Bienvenue sur FotoSharing<span th:if="${prenom}" th:text="' : ' + ${prenom}"></span></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="@{/upload}">Uploader une photo</a></p>
<p><a th:href="@{/mes-photos}">Voir mes photos</a></p> <p><a th:href="@{/mes-photos}">Voir mes photos</a></p>
<p><a th:href="@{/galerie}">Voir la galerie publique</a></p>
<p> <p>
<form th:action="@{/logout}" method="post" style="display: inline;"> <form th:action="@{/logout}" method="post" style="display: inline;">
<button type="submit" <button type="submit"

View File

@@ -19,5 +19,6 @@
Erreur d'authentification. Erreur d'authentification.
</div> </div>
<p><a th:href="@{/register}">Créer un compte</a></p> <p><a th:href="@{/register}">Créer un compte</a></p>
<p><a th:href="@{/galerie}">Galerie publique</a></p>
</body> </body>
</html> </html>

View File

@@ -22,5 +22,7 @@
</li> </li>
</ul> </ul>
<p><a th:href="@{/galerie}">Galerie publique</a></p>
</body> </body>
</html> </html>

View File

@@ -13,5 +13,6 @@
<label>Mot de passe: <input th:field="*{motDePasse}" type="password"/></label><br/> <label>Mot de passe: <input th:field="*{motDePasse}" type="password"/></label><br/>
<button type="submit">Créer</button> <button type="submit">Créer</button>
</form> </form>
<p><a th:href="@{/galerie}">Galerie publique</a></p>
</body> </body>
</html> </html>

View File

@@ -17,6 +17,7 @@
</label><br/> </label><br/>
<button type="submit">Envoyer</button> <button type="submit">Envoyer</button>
</form> </form>
<p><a th:href="@{/galerie}">Galerie publique</a></p>
<div th:if="${error}" th:text="${error}"></div> <div th:if="${error}" th:text="${error}"></div>
<div th:if="${message}" th:text="${message}"></div> <div th:if="${message}" th:text="${message}"></div>
</body> </body>