From 45c05debe687bb1918493eff9677ccaf5de89ef5 Mon Sep 17 00:00:00 2001 From: mepiphana2023 Date: Wed, 24 Apr 2024 13:51:13 +0200 Subject: [PATCH 1/2] fichier langue / bootstrap --- .../controllers/LanguageController.java | 15 ++++--- .../enchere/security/WebSecurityConfig.java | 9 ++-- .../resources/i18n/messages_en.properties | 45 ++++++++++++++++++- src/main/resources/templates/accueil.html | 2 +- src/main/resources/templates/admin.html | 2 +- src/main/resources/templates/article.html | 2 +- src/main/resources/templates/editProfil.html | 2 +- src/main/resources/templates/inscription.html | 2 +- src/main/resources/templates/modele-page.html | 15 ++++--- src/main/resources/templates/profil.html | 2 +- 10 files changed, 74 insertions(+), 22 deletions(-) diff --git a/src/main/java/fr/eni/enchere/controllers/LanguageController.java b/src/main/java/fr/eni/enchere/controllers/LanguageController.java index 7ae9266..713c8e7 100644 --- a/src/main/java/fr/eni/enchere/controllers/LanguageController.java +++ b/src/main/java/fr/eni/enchere/controllers/LanguageController.java @@ -7,19 +7,22 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.servlet.LocaleResolver; +import org.springframework.web.servlet.mvc.support.RedirectAttributes; import org.springframework.web.servlet.support.RequestContextUtils; import java.util.Locale; @Controller public class LanguageController { + private final LocaleResolver localeResolver; + + public LanguageController(LocaleResolver localeResolver) { + this.localeResolver = localeResolver; + } @GetMapping("/change-language") - public String changeLanguage(HttpServletRequest request, HttpServletResponse response, @RequestParam("lang") String lang, @RequestHeader String referer) { - LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(request); - if (localeResolver != null) { - localeResolver.setLocale(request, response, new Locale(lang)); - } - return "redirect:" + referer; + public String changeLanguage(@RequestParam("lang") String lang, HttpServletRequest request, HttpServletResponse response, RedirectAttributes redirectAttributes) { + localeResolver.setLocale(request, response, Locale.forLanguageTag(lang)); + return "redirect:/"; // Redirect to a specific page or the current one } } diff --git a/src/main/java/fr/eni/enchere/security/WebSecurityConfig.java b/src/main/java/fr/eni/enchere/security/WebSecurityConfig.java index 507b63d..d956a97 100644 --- a/src/main/java/fr/eni/enchere/security/WebSecurityConfig.java +++ b/src/main/java/fr/eni/enchere/security/WebSecurityConfig.java @@ -18,12 +18,15 @@ public class WebSecurityConfig{ http.authorizeHttpRequests((requests) -> requests .requestMatchers("/", "/accueil").permitAll() .requestMatchers("/accueil", "/login", "/inscription/**", "/searchArticle", "/article/**", "/change-language").permitAll() - .requestMatchers("/css/**", "/images/**", "/assets/**", "/img/**", "/js/**", "/assets/**").permitAll() + .requestMatchers("/css/**", "/images/**", "/assets/**", "/img/**", "/js/**", "/assets/**", "/i18n/**").permitAll() .requestMatchers("/profil/**", "/article/new/**", "/article/update", "/article/delete").authenticated() .requestMatchers("/admin").hasRole("ADMIN") .anyRequest().authenticated()) - .formLogin((form) -> form.loginPage("/login").defaultSuccessUrl("/", true)) - .logout((logout) -> logout.clearAuthentication(true).invalidateHttpSession(true) + .formLogin((form) -> form + .loginPage("/login") + .defaultSuccessUrl("/", true)) + .logout((logout) -> logout + .clearAuthentication(true).invalidateHttpSession(true) .deleteCookies("JSESSIONID").logoutSuccessUrl("/login?logout") .logoutRequestMatcher(new AntPathRequestMatcher("/logout")).permitAll()); diff --git a/src/main/resources/i18n/messages_en.properties b/src/main/resources/i18n/messages_en.properties index 9de4ea6..e448537 100644 --- a/src/main/resources/i18n/messages_en.properties +++ b/src/main/resources/i18n/messages_en.properties @@ -1 +1,44 @@ -accueil.search.title = Search for an article by name... \ No newline at end of file +home.search.title = Search for an item by name... +home.search.cat = All categories +home.search.button = Search + +profile.title = My Profile +profile.button = Edit +profile.pseudo = Username: +profile.surname = First Name: +profile.name = Last Name: +profile.email = Email: +profile.phone = Phone: +profile.street = Street: +profile.postal = Zip Code: +profile.city = City: +profile.credit = Credits: + +edit.profile.currentpassword = Current Password: +edit.profile.newpassword = New Password: +edit.profile.confirmnewpassword = Confirm New Password: +edit.profile.title = Edit My Profile +edit.profile.button.edit = Save Changes +edit.profile.button.del = Delete My Account + +login.title = To Log In: +login.id = Username: +login.password = Password: +login.save = Remember Me +login.forgotpassword = Forgot Password +login.connection = Login +login.makecompte = Create Account + +register.title = My Profile +register.button = Edit +register.pseudo = Username: +register.surname = First Name: +register.name = Last Name: +register.email = Email: +register.phone = Phone: +register.street = Street: +register.postal = Zip Code: +register.city = City: +register.credit = Credits: +register.make = create +register.cancel = cancel \ No newline at end of file diff --git a/src/main/resources/templates/accueil.html b/src/main/resources/templates/accueil.html index 8b0f2b1..b88f0bf 100644 --- a/src/main/resources/templates/accueil.html +++ b/src/main/resources/templates/accueil.html @@ -1,5 +1,5 @@ - + diff --git a/src/main/resources/templates/admin.html b/src/main/resources/templates/admin.html index 900f3af..be851f1 100644 --- a/src/main/resources/templates/admin.html +++ b/src/main/resources/templates/admin.html @@ -1,5 +1,5 @@ - + diff --git a/src/main/resources/templates/article.html b/src/main/resources/templates/article.html index 663fbfa..119c949 100644 --- a/src/main/resources/templates/article.html +++ b/src/main/resources/templates/article.html @@ -1,5 +1,5 @@ - + diff --git a/src/main/resources/templates/editProfil.html b/src/main/resources/templates/editProfil.html index a6f2ba4..7f0b5dd 100644 --- a/src/main/resources/templates/editProfil.html +++ b/src/main/resources/templates/editProfil.html @@ -1,5 +1,5 @@ - + diff --git a/src/main/resources/templates/inscription.html b/src/main/resources/templates/inscription.html index 9278e53..af30f07 100644 --- a/src/main/resources/templates/inscription.html +++ b/src/main/resources/templates/inscription.html @@ -1,5 +1,5 @@ - + diff --git a/src/main/resources/templates/modele-page.html b/src/main/resources/templates/modele-page.html index 5bcd680..a1241d9 100644 --- a/src/main/resources/templates/modele-page.html +++ b/src/main/resources/templates/modele-page.html @@ -38,12 +38,14 @@ S'inscrire / Se connecter @@ -101,6 +103,7 @@ © 2024 Copyright: + \ No newline at end of file diff --git a/src/main/resources/templates/profil.html b/src/main/resources/templates/profil.html index 1cb40a1..0338c19 100644 --- a/src/main/resources/templates/profil.html +++ b/src/main/resources/templates/profil.html @@ -1,5 +1,5 @@ - + From dbd04fe987e4c27969f5df8f7f84a56004eb0b46 Mon Sep 17 00:00:00 2001 From: mepiphana2023 Date: Wed, 24 Apr 2024 14:55:29 +0200 Subject: [PATCH 2/2] fichier langue / bootstrap / modification sql article --- src/main/java/fr/eni/enchere/bo/Article.java | 26 ++++++++---- .../controllers/LanguageController.java | 9 ++-- .../enchere/dal/ArticleRepositoryImpl.java | 42 +++++++++---------- .../resources/i18n/messages_en.properties | 36 ++++++++-------- .../resources/i18n/messages_fr.properties | 6 +-- src/main/resources/templates/accueil.html | 30 +++++++------ src/main/resources/templates/editProfil.html | 2 +- src/main/resources/templates/inscription.html | 4 +- 8 files changed, 85 insertions(+), 70 deletions(-) diff --git a/src/main/java/fr/eni/enchere/bo/Article.java b/src/main/java/fr/eni/enchere/bo/Article.java index 20ffac3..89b6c77 100644 --- a/src/main/java/fr/eni/enchere/bo/Article.java +++ b/src/main/java/fr/eni/enchere/bo/Article.java @@ -12,13 +12,15 @@ public class Article { Date dateFinEnch; float prixInitial; float prixVente; - UserProfil Utilisateur; + int noUtilisateur; + String pseudoUtilisateur; int numCategorie; + public Article() { } - public Article(int id, String nom, String desc, String photo, Date dateDebutEnch, Date dateFinEnch, float prixInitial, float prixVente, UserProfil Utilisateur, int numCategorie) { + public Article(int id, String nom, String desc, String photo, Date dateDebutEnch, Date dateFinEnch, float prixInitial, float prixVente, int noUtilisateur, String pseudoUtilisateur, int numCategorie) { setId(id); setNom(nom); setDesc(desc); @@ -27,7 +29,8 @@ public class Article { setDateFinEnch(dateFinEnch); setPrixInitial(prixInitial); setPrixVente(prixVente); - setUtilisateur(Utilisateur); + setNoUtilisateur(noUtilisateur); + setPseudoUtilisateur(pseudoUtilisateur); setNumCategorie(numCategorie); } @@ -95,12 +98,21 @@ public class Article { this.prixVente = prixVente; } - public UserProfil getUtilisateur() { - return Utilisateur; + + public String getPseudoUtilisateur() { + return pseudoUtilisateur; } - public void setUtilisateur(UserProfil Utilisateur) { - this.Utilisateur = Utilisateur; + public void setPseudoUtilisateur(String pseudoUtilisateur) { + this.pseudoUtilisateur = pseudoUtilisateur; + } + + public int getNoUtilisateur() { + return noUtilisateur; + } + + public void setNoUtilisateur(int noUtilisateur) { + this.noUtilisateur = noUtilisateur; } public int getNumCategorie() { diff --git a/src/main/java/fr/eni/enchere/controllers/LanguageController.java b/src/main/java/fr/eni/enchere/controllers/LanguageController.java index 713c8e7..eca5ac3 100644 --- a/src/main/java/fr/eni/enchere/controllers/LanguageController.java +++ b/src/main/java/fr/eni/enchere/controllers/LanguageController.java @@ -21,8 +21,11 @@ public class LanguageController { } @GetMapping("/change-language") - public String changeLanguage(@RequestParam("lang") String lang, HttpServletRequest request, HttpServletResponse response, RedirectAttributes redirectAttributes) { - localeResolver.setLocale(request, response, Locale.forLanguageTag(lang)); - return "redirect:/"; // Redirect to a specific page or the current one + public String changeLanguage(HttpServletRequest request, HttpServletResponse response, @RequestParam("lang") String lang) { + LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(request); + if (localeResolver != null) { + localeResolver.setLocale(request, response, Locale.forLanguageTag(lang)); + } + return "redirect:/"; } } diff --git a/src/main/java/fr/eni/enchere/dal/ArticleRepositoryImpl.java b/src/main/java/fr/eni/enchere/dal/ArticleRepositoryImpl.java index c75c4fc..bc68018 100644 --- a/src/main/java/fr/eni/enchere/dal/ArticleRepositoryImpl.java +++ b/src/main/java/fr/eni/enchere/dal/ArticleRepositoryImpl.java @@ -31,22 +31,16 @@ public class ArticleRepositoryImpl implements ArticleRepository { @Override public Article mapRow(ResultSet rs, int rowNum) throws SQLException { Article article = new Article(); - article.setId(rs.getInt("no_article")); - article.setNom(rs.getString("nom_article")); - article.setDesc(rs.getString("description")); - article.setDateDebutEnch(rs.getDate("date_debut_encheres")); - article.setDateFinEnch(rs.getDate("date_fin_encheres")); - article.setPrixInitial(rs.getFloat("prix_initial")); - article.setPrixVente(rs.getFloat("prix_vente")); - - UserProfil user = userService.utilisateurById(rs.getInt("no_utilisateur")); - if (user != null) { - article.setUtilisateur(user); - } else { - logger.error("erreur de l'utilisateur"); - } - - article.setNumCategorie(rs.getInt("no_categorie")); + article.setId(rs.getInt("a.no_article")); + article.setNom(rs.getString("a.nom_article")); + article.setDesc(rs.getString("a.description")); + article.setDateDebutEnch(rs.getDate("a.date_debut_encheres")); + article.setDateFinEnch(rs.getDate("a.date_fin_encheres")); + article.setPrixInitial(rs.getFloat("a.prix_initial")); + article.setPrixVente(rs.getFloat("a.prix_vente")); + article.setNoUtilisateur(rs.getInt("u.no_utilisateur")); + article.setPseudoUtilisateur(rs.getString("u.pseudo")); + article.setNumCategorie(rs.getInt("a.no_categorie")); return article; } } @@ -59,24 +53,26 @@ public class ArticleRepositoryImpl implements ArticleRepository { @Override public List
findAllArticle() { - String sql = "SELECT * FROM ARTICLES_VENDUS"; + String sql = "SELECT * FROM ARTICLES_VENDUS a"; List
articles = jdbcTemplate.query(sql, new ArticleRowMapper()); return articles; } @Override public List
searchArticle(SearchArticleCritere critere) { - StringBuilder sql = new StringBuilder("SELECT * FROM ARTICLES_VENDUS WHERE 1 = 1 AND isDelete = 0"); + StringBuilder sql = new StringBuilder("SELECT a.*, u.* FROM ARTICLES_VENDUS a "); + sql.append("JOIN UTILISATEURS u ON a.no_utilisateur = u.no_utilisateur "); + sql.append("WHERE 1 = 1 AND a.isDelete = 0"); List params = new ArrayList<>(); if (critere.getNoCategorie() != null) { - sql.append(" AND no_categorie = ?"); - params.add(critere.getNoCategorie()); + sql.append(" AND a.no_categorie = ?"); + params.add(critere.getNoCategorie()); } if (critere.getTitle() != null && !critere.getTitle().isEmpty()) { - sql.append(" AND nom_article LIKE ?"); - params.add( '%' + critere.getTitle() + "%"); + sql.append(" AND a.nom_article LIKE ?"); + params.add('%' + critere.getTitle() + '%'); } return jdbcTemplate.query(sql.toString(), new ArticleRowMapper(), params.toArray()); @@ -89,7 +85,7 @@ public class ArticleRepositoryImpl implements ArticleRepository { @Override public List
findArticleByTitle(String title) { - String sql = "SELECT * FROM ARTICLES_VENDUS WHERE nom_article LIKE ?"; + String sql = "SELECT * FROM ARTICLES_VENDUS a WHERE nom_article LIKE ?"; List
articles = jdbcTemplate.query(sql, new ArticleRowMapper(), "%" + title + "%"); return articles; } diff --git a/src/main/resources/i18n/messages_en.properties b/src/main/resources/i18n/messages_en.properties index e448537..a178a97 100644 --- a/src/main/resources/i18n/messages_en.properties +++ b/src/main/resources/i18n/messages_en.properties @@ -2,24 +2,24 @@ home.search.title = Search for an item by name... home.search.cat = All categories home.search.button = Search -profile.title = My Profile -profile.button = Edit -profile.pseudo = Username: -profile.surname = First Name: -profile.name = Last Name: -profile.email = Email: -profile.phone = Phone: -profile.street = Street: -profile.postal = Zip Code: -profile.city = City: -profile.credit = Credits: +profil.title = My Profile +profil.button = Edit +profil.pseudo = Username: +profil.surname = First Name: +profil.name = Last Name: +profil.email = Email: +profil.phone = Phone: +profil.street = Street: +profil.postal = Zip Code: +profil.city = City: +profil.credit = Credits: -edit.profile.currentpassword = Current Password: -edit.profile.newpassword = New Password: -edit.profile.confirmnewpassword = Confirm New Password: -edit.profile.title = Edit My Profile -edit.profile.button.edit = Save Changes -edit.profile.button.del = Delete My Account +edit.profil.currentpassword = Current Password: +edit.profil.newpassword = New Password: +edit.profil.confirmnewpassword = Confirm New Password: +edit.profil.title = Edit My Profile +edit.profil.button.edit = Save Changes +edit.profil.button.del = Delete My Account login.title = To Log In: login.id = Username: @@ -27,7 +27,7 @@ login.password = Password: login.save = Remember Me login.forgotpassword = Forgot Password login.connection = Login -login.makecompte = Create Account +login.makecompte = Create an Account register.title = My Profile register.button = Edit diff --git a/src/main/resources/i18n/messages_fr.properties b/src/main/resources/i18n/messages_fr.properties index 9f3a9ce..debe0b2 100644 --- a/src/main/resources/i18n/messages_fr.properties +++ b/src/main/resources/i18n/messages_fr.properties @@ -1,6 +1,6 @@ -accueil.search.title = Rechercher un article par nom... -accueil.search.cat = Toutes les cat\u00e9gories -accueil.search.button = Recherche +home.search.title = Rechercher un article par nom... +home.search.cat = Toutes les cat\u00e9gories +home.search.button = Recherche profil.title = Mon profil profil.button = Modifier diff --git a/src/main/resources/templates/accueil.html b/src/main/resources/templates/accueil.html index b88f0bf..6d6f6c4 100644 --- a/src/main/resources/templates/accueil.html +++ b/src/main/resources/templates/accueil.html @@ -9,19 +9,23 @@
-
- -
- +
+
+ +
+ + + +
+
+ +
+
-
- -
- - +
@@ -39,7 +43,7 @@
Prix de vente:
-
Vendeur:
+
Vendeur:

diff --git a/src/main/resources/templates/editProfil.html b/src/main/resources/templates/editProfil.html index 7f0b5dd..76a2dee 100644 --- a/src/main/resources/templates/editProfil.html +++ b/src/main/resources/templates/editProfil.html @@ -110,7 +110,7 @@
- + diff --git a/src/main/resources/templates/inscription.html b/src/main/resources/templates/inscription.html index af30f07..abe53e1 100644 --- a/src/main/resources/templates/inscription.html +++ b/src/main/resources/templates/inscription.html @@ -107,7 +107,7 @@
- +
@@ -118,7 +118,7 @@
- +