Ajout galerie publique pour tous les users / anonymes
This commit is contained in:
@@ -85,6 +85,12 @@ public class PhotoController {
|
||||
return "mes-photos";
|
||||
}
|
||||
|
||||
@GetMapping("/galerie")
|
||||
public String galerie(Model model) {
|
||||
model.addAttribute("photos", photoService.listPublicPhotos());
|
||||
return "galerie";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,6 @@ import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import java.util.List;
|
||||
|
||||
public interface PhotoRepository extends JpaRepository<Photo, Long> {
|
||||
|
||||
List<Photo> findByProprietaire_Email(String email);
|
||||
List<Photo> findByVisibilite(Photo.Visibilite visibilite);
|
||||
}
|
||||
@@ -39,7 +39,7 @@ public class SecurityConfig {
|
||||
http
|
||||
.userDetailsService(customUserDetailsService) // Utiliser directement le UserDetailsService
|
||||
.authorizeHttpRequests(auth -> auth
|
||||
.requestMatchers("/register", "/login", "/css/**", "/js/**").permitAll()
|
||||
.requestMatchers("/register", "/login", "/css/**", "/js/**", "/photo/*/raw", "/galerie").permitAll()
|
||||
.anyRequest().authenticated()
|
||||
)
|
||||
.formLogin(form -> form
|
||||
|
||||
@@ -10,5 +10,6 @@ public interface PhotoService {
|
||||
Photo store(MultipartFile file, String visibilite, String ownerEmail) throws IOException;
|
||||
Path loadAsPath(String uuidFile);
|
||||
List<Photo> listByOwner(String email);
|
||||
List<Photo> listPublicPhotos();
|
||||
|
||||
}
|
||||
|
||||
@@ -64,4 +64,9 @@ public class PhotoServiceImpl implements PhotoService {
|
||||
public List<Photo> listByOwner(String email) {
|
||||
return photoRepository.findByProprietaire_Email(email);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Photo> listPublicPhotos() {
|
||||
return photoRepository.findByVisibilite(Photo.Visibilite.PUBLIC);
|
||||
}
|
||||
}
|
||||
|
||||
17
src/main/resources/templates/galerie.html
Normal file
17
src/main/resources/templates/galerie.html
Normal 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>
|
||||
@@ -7,6 +7,7 @@
|
||||
<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="@{/mes-photos}">Voir mes photos</a></p>
|
||||
<p><a th:href="@{/galerie}">Voir la galerie publique</a></p>
|
||||
<p>
|
||||
<form th:action="@{/logout}" method="post" style="display: inline;">
|
||||
<button type="submit"
|
||||
|
||||
@@ -19,5 +19,6 @@
|
||||
Erreur d'authentification.
|
||||
</div>
|
||||
<p><a th:href="@{/register}">Créer un compte</a></p>
|
||||
<p><a th:href="@{/galerie}">Galerie publique</a></p>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -22,5 +22,7 @@
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<p><a th:href="@{/galerie}">Galerie publique</a></p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -13,5 +13,6 @@
|
||||
<label>Mot de passe: <input th:field="*{motDePasse}" type="password"/></label><br/>
|
||||
<button type="submit">Créer</button>
|
||||
</form>
|
||||
<p><a th:href="@{/galerie}">Galerie publique</a></p>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
</label><br/>
|
||||
<button type="submit">Envoyer</button>
|
||||
</form>
|
||||
<p><a th:href="@{/galerie}">Galerie publique</a></p>
|
||||
<div th:if="${error}" th:text="${error}"></div>
|
||||
<div th:if="${message}" th:text="${message}"></div>
|
||||
</body>
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
17
target/classes/templates/galerie.html
Normal file
17
target/classes/templates/galerie.html
Normal 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>
|
||||
@@ -7,6 +7,7 @@
|
||||
<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="@{/mes-photos}">Voir mes photos</a></p>
|
||||
<p><a th:href="@{/galerie}">Voir la galerie publique</a></p>
|
||||
<p>
|
||||
<form th:action="@{/logout}" method="post" style="display: inline;">
|
||||
<button type="submit"
|
||||
|
||||
@@ -19,5 +19,6 @@
|
||||
Erreur d'authentification.
|
||||
</div>
|
||||
<p><a th:href="@{/register}">Créer un compte</a></p>
|
||||
<p><a th:href="@{/galerie}">Galerie publique</a></p>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -22,5 +22,7 @@
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<p><a th:href="@{/galerie}">Galerie publique</a></p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -13,5 +13,6 @@
|
||||
<label>Mot de passe: <input th:field="*{motDePasse}" type="password"/></label><br/>
|
||||
<button type="submit">Créer</button>
|
||||
</form>
|
||||
<p><a th:href="@{/galerie}">Galerie publique</a></p>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
</label><br/>
|
||||
<button type="submit">Envoyer</button>
|
||||
</form>
|
||||
<p><a th:href="@{/galerie}">Galerie publique</a></p>
|
||||
<div th:if="${error}" th:text="${error}"></div>
|
||||
<div th:if="${message}" th:text="${message}"></div>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user