diff --git a/src/main/java/fr/eni/enchere/controllers/ArticleController.java b/src/main/java/fr/eni/enchere/controllers/ArticleController.java index 4826f1e..9f630ce 100644 --- a/src/main/java/fr/eni/enchere/controllers/ArticleController.java +++ b/src/main/java/fr/eni/enchere/controllers/ArticleController.java @@ -44,9 +44,16 @@ public class ArticleController { //Affichage d'un article @GetMapping("/show") - public String showArticle(@RequestParam(name = "slug")int id, Model model) { - Article article = articleService.findArticleById(id); - return "article"; + public String showArticle(@RequestParam()int id, Model model) { + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + if (!authentication.getName().equals("anonymousUser")) { + Article article = articleService.findArticleById(id); + System.out.println(article); + model.addAttribute("article", article); + return "article"; + } else { + return "redirect:/accueil"; + } } @GetMapping("/{slug}") diff --git a/src/main/java/fr/eni/enchere/dal/ArticleRepositoryImpl.java b/src/main/java/fr/eni/enchere/dal/ArticleRepositoryImpl.java index efb0764..8729afb 100644 --- a/src/main/java/fr/eni/enchere/dal/ArticleRepositoryImpl.java +++ b/src/main/java/fr/eni/enchere/dal/ArticleRepositoryImpl.java @@ -91,7 +91,9 @@ public class ArticleRepositoryImpl implements ArticleRepository { @Override public Article findArticleById(int id) { - return null; + String sql = "SELECT * FROM ARTICLES_VENDUS a WHERE no_article = ?"; + Article article = jdbcTemplate.queryForObject(sql, new ArticleRowMapper(), id); + return article; } @Override diff --git a/src/main/java/fr/eni/enchere/interceptor/UserInterceptor.java b/src/main/java/fr/eni/enchere/interceptor/UserInterceptor.java index a7c2b6e..b58d0ed 100644 --- a/src/main/java/fr/eni/enchere/interceptor/UserInterceptor.java +++ b/src/main/java/fr/eni/enchere/interceptor/UserInterceptor.java @@ -27,7 +27,9 @@ public class UserInterceptor implements HandlerInterceptor { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication != null && authentication.isAuthenticated() && !authentication.getName().equals("anonymousUser")) { UserProfil user = this.userService.utilisateurByName(authentication.getName()); - modelAndView.getModelMap().addAttribute("user", user.getCredit()); + if (modelAndView != null && modelAndView.getViewName() != null && !modelAndView.getViewName().startsWith("redirect:")) { + modelAndView.addObject("user", user.getCredit()); + } } } } diff --git a/src/main/java/fr/eni/enchere/interceptor/UserServiceInterceptorAppConfig.java b/src/main/java/fr/eni/enchere/interceptor/UserServiceInterceptorAppConfig.java deleted file mode 100644 index b6fb169..0000000 --- a/src/main/java/fr/eni/enchere/interceptor/UserServiceInterceptorAppConfig.java +++ /dev/null @@ -1,13 +0,0 @@ -//package fr.eni.enchere.interceptor; -// -//import org.springframework.beans.factory.annotation.Autowired; -//import org.springframework.web.servlet.config.annotation.InterceptorRegistry; -//import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; -// -//public class UserServiceInterceptorAppConfig implements WebMvcConfigurer { -// -// @Override -// public void addInterceptors(InterceptorRegistry registry) { -// registry.addInterceptor(new UserInterceptor()); -// } -//} diff --git a/src/main/resources/templates/accueil.html b/src/main/resources/templates/accueil.html index 6d6f6c4..6aee351 100644 --- a/src/main/resources/templates/accueil.html +++ b/src/main/resources/templates/accueil.html @@ -17,41 +17,64 @@
+
+
+
+
+
+
+
+ + +
+
+
+ + +
+
+
+
+
+
+
-
-
-
- Image de l'article -
- diff --git a/src/main/resources/templates/article.html b/src/main/resources/templates/article.html index 119c949..654c85a 100644 --- a/src/main/resources/templates/article.html +++ b/src/main/resources/templates/article.html @@ -5,7 +5,22 @@
- +
+
+
+
+

Article

+
+
+
    +
  • + +
  • +
+
+
+
+
diff --git a/src/main/resources/templates/security/login.html b/src/main/resources/templates/security/login.html index 9fdbcb1..20b4228 100644 --- a/src/main/resources/templates/security/login.html +++ b/src/main/resources/templates/security/login.html @@ -3,30 +3,40 @@ - -
-

Pour se Connecter :

-
+ +
+
+
+

Pour se Connecter :

-
- - +
+ +
-
- - +
+ + +
+
+ + +
+ +
+ +
-
- -
-
+
Identifiant ou mot de passe incorrect
-
+
Vous avez été déconnecté
-
- +
+
+ \ No newline at end of file