Merge remote-tracking branch 'refs/remotes/origin/Johan' into marvin
# Conflicts: # src/main/java/fr/eni/enchere/security/WebSecurityConfig.java
This commit is contained in:
@@ -12,14 +12,15 @@ public class UserProfil {
|
||||
private String rue;
|
||||
private String code_postal;
|
||||
private String ville;
|
||||
private String password; //Voir la sécurité du mot de passe
|
||||
private String password;
|
||||
private String confirmPassword;
|
||||
private float credit;
|
||||
private boolean isAdmin;
|
||||
|
||||
//Constructeur
|
||||
public UserProfil(){}
|
||||
|
||||
public UserProfil(int id, String pseudo, String nom, String prenom, String email, String telephone, String rue, String code_postal, String ville, String password, int credit, boolean isAdmin) {
|
||||
public UserProfil(int id, String pseudo, String nom, String prenom, String email, String telephone, String rue, String code_postal, String ville, String password, String confirmPassword, int credit, boolean isAdmin) {
|
||||
setId(id);
|
||||
setPrenom(prenom);
|
||||
setNom(nom);
|
||||
@@ -30,6 +31,7 @@ public class UserProfil {
|
||||
setCode_postal(code_postal);
|
||||
setVille(ville);
|
||||
setPassword(password);
|
||||
setConfirmPassword(confirmPassword);
|
||||
setCredit(credit);
|
||||
setAdmin(isAdmin);
|
||||
}
|
||||
@@ -115,6 +117,14 @@ public class UserProfil {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getConfirmPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setConfirmPassword(String confirmPassword) {
|
||||
this.confirmPassword = confirmPassword;
|
||||
}
|
||||
|
||||
public float getCredit() {
|
||||
return credit;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package fr.eni.enchere.controllers;
|
||||
|
||||
import fr.eni.enchere.bll.ArticleService;
|
||||
import fr.eni.enchere.bll.CategorieService;
|
||||
import fr.eni.enchere.bll.UserService;
|
||||
import fr.eni.enchere.bo.Article;
|
||||
import org.springframework.stereotype.Controller;
|
||||
@@ -13,10 +14,12 @@ public class ArticleController {
|
||||
|
||||
private final ArticleService articleService;
|
||||
private final UserService userService;
|
||||
private CategorieService categorieService;
|
||||
|
||||
public ArticleController(ArticleService articleService, UserService userService) {
|
||||
public ArticleController(ArticleService articleService, UserService userService, CategorieService categorieService) {
|
||||
this.articleService = articleService;
|
||||
this.userService = userService;
|
||||
this.categorieService = categorieService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@@ -24,7 +27,8 @@ public class ArticleController {
|
||||
return "accueil";
|
||||
}
|
||||
|
||||
@GetMapping("/article")
|
||||
//Affichage d'un article
|
||||
@GetMapping("/show")
|
||||
public String showArticle(@RequestParam(name = "slug")int id, Model model) {
|
||||
Article article = articleService.findArticleById(id);
|
||||
return "article";
|
||||
@@ -39,14 +43,14 @@ public class ArticleController {
|
||||
|
||||
@GetMapping("/new")
|
||||
public String test(@PathVariable(name = "slug")int id, Model model) {
|
||||
|
||||
return "article";
|
||||
model.addAttribute("categories", categorieService.findAllCategories());
|
||||
return "newArticle";
|
||||
}
|
||||
|
||||
@PostMapping("/new/add")
|
||||
public String newArticle(@ModelAttribute("article") Article article) {
|
||||
articleService.saveArticle(article);
|
||||
return "redirect:/article";
|
||||
return "redirect:/accueil";
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package fr.eni.enchere.controllers;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import fr.eni.enchere.bll.UserService;
|
||||
import fr.eni.enchere.bo.UserProfil;
|
||||
@@ -14,9 +17,11 @@ public class InscriptionController {
|
||||
|
||||
@Autowired
|
||||
private final UserService userService;
|
||||
private PasswordEncoder passwordEncoder;
|
||||
|
||||
public InscriptionController(UserService userService) {
|
||||
public InscriptionController(UserService userService, PasswordEncoder passwordEncoder) {
|
||||
this.userService = userService;
|
||||
this.passwordEncoder = passwordEncoder;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@@ -26,10 +31,33 @@ public class InscriptionController {
|
||||
}
|
||||
|
||||
@PostMapping("/newUser")
|
||||
public String setUser(@ModelAttribute UserProfil user) {
|
||||
//Ajouter vérification du formulaire -> @RequestParam("confirmPassword") String confirmPassword
|
||||
userService.setUtilisateur(user);
|
||||
return "redirect:/accueil";
|
||||
public String setUser(@ModelAttribute("userProfile") UserProfil userProfile, BindingResult result) {
|
||||
// Obtenez l'authentification actuelle
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
// Vérifiez si l'utilisateur est authentifié
|
||||
if (!authentication.getName().equals("anonymousUser")) {
|
||||
// Obtenez les détails de l'utilisateur authentifié
|
||||
String username = authentication.getName();
|
||||
// Utilisez le service approprié pour récupérer les informations de l'utilisateur à partir du nom d'utilisateur
|
||||
UserProfil currentUserProfile = userService.utilisateurByName(username);
|
||||
// Vérifiez si le mot de passe actuel correspond à celui stocké dans la base de données
|
||||
if (!passwordEncoder.matches(userProfile.getPassword(), currentUserProfile.getPassword())) {
|
||||
// Mot de passe actuel incorrect, renvoyer une erreur
|
||||
result.rejectValue("currentPassword", "invalid", "Mot de passe actuel incorrect");
|
||||
return "editProfil"; // Rediriger vers la page de modification du profil avec une erreur
|
||||
}
|
||||
// Vérifiez si le nouveau mot de passe et sa confirmation correspondent
|
||||
if (!userProfile.getPassword().equals(userProfile.getConfirmPassword())) {
|
||||
// Mauvaise correspondance entre le nouveau mot de passe et sa confirmation, renvoyer une erreur
|
||||
result.rejectValue("confirmPassword", "invalid", "La confirmation du mot de passe ne correspond pas au nouveau mot de passe");
|
||||
return "editProfil"; // Rediriger vers la page de modification du profil avec une erreur
|
||||
}
|
||||
// Mettez à jour le mot de passe de l'utilisateur avec le nouveau mot de passe
|
||||
userService.setUtilisateur(currentUserProfile);
|
||||
return "redirect:/profil"; // Rediriger vers la page de profil après la modification réussie
|
||||
} else {
|
||||
return "accueil";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,9 +17,9 @@ public class WebSecurityConfig{
|
||||
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||
http.authorizeHttpRequests((requests) -> requests
|
||||
.requestMatchers("/", "/accueil").permitAll()
|
||||
.requestMatchers("/accueil", "/login", "/inscription/**", "/searchArticle", "/article/**", "/change-language", "/profile/**").permitAll()
|
||||
.requestMatchers("/css/**", "/images/**", "/assets/**", "/img/**", "/js/**", "/assets/**").permitAll()
|
||||
.requestMatchers("/profile/**").authenticated()
|
||||
.requestMatchers("/accueil", "/login", "/inscription/**", "/searchArticle", "/article/**", "/change-language").permitAll()
|
||||
.requestMatchers("/css/**", "/images/**", "/assets/**", "/img/**", "/js/**").permitAll()
|
||||
.requestMatchers("/profil/**", "/article/new/**", "/article/update", "/article/delete").authenticated()
|
||||
.requestMatchers("/admin").hasRole("ADMIN")
|
||||
.anyRequest().authenticated())
|
||||
.formLogin((form) -> form.loginPage("/login").defaultSuccessUrl("/", true))
|
||||
|
||||
@@ -108,34 +108,41 @@
|
||||
</ul>
|
||||
</span>
|
||||
</div>
|
||||
<!-- Champ Mot de passe-->
|
||||
<!-- Champ Mot de passe actuel-->
|
||||
<div class="champ-saisie">
|
||||
<label for="password">Mot de passe actuel: </label>
|
||||
<label for="currentPassword">Mot de passe actuel: </label>
|
||||
<div>
|
||||
<input type="password" th:field="*{password}" id="password" />
|
||||
<input type="password" th:field="*{currentPassword}" id="currentPassword" />
|
||||
</div>
|
||||
<span style="color: red;" th:if="${#fields.hasErrors('password')}">
|
||||
<ul>
|
||||
<li th:each="erreur: ${#fields.errors('password')}" th:text="${erreur}"></li>
|
||||
</ul>
|
||||
</span>
|
||||
<span style="color: red;" th:if="${#fields.hasErrors('currentPassword')}">
|
||||
<ul>
|
||||
<li th:each="erreur: ${#fields.errors('currentPassword')}" th:text="${erreur}"></li>
|
||||
</ul>
|
||||
</span>
|
||||
</div>
|
||||
<!-- Champ Nouveau mot de passe-->
|
||||
<div class="champ-saisie">
|
||||
<label for="password">Nouveau mot de passe: </label>
|
||||
<label for="newPassword">Nouveau mot de passe: </label>
|
||||
<div>
|
||||
<input type="password" th:field="*{password}" id="password" />
|
||||
<input type="password" th:field="*{newPassword}" id="newPassword" />
|
||||
</div>
|
||||
<span style="color: red;" th:if="${#fields.hasErrors('password')}">
|
||||
<ul>
|
||||
<li th:each="erreur: ${#fields.errors('password')}" th:text="${erreur}"></li>
|
||||
</ul>
|
||||
</span>
|
||||
<span style="color: red;" th:if="${#fields.hasErrors('newPassword')}">
|
||||
<ul>
|
||||
<li th:each="erreur: ${#fields.errors('newPassword')}" th:text="${erreur}"></li>
|
||||
</ul>
|
||||
</span>
|
||||
</div>
|
||||
<!-- Champ Confirmation du nouveau mot de passe-->
|
||||
<div class="champ-saisie">
|
||||
<label for="password">Confirmation: </label>
|
||||
<label for="confirmPassword">Confirmation du nouveau mot de passe: </label>
|
||||
<div>
|
||||
<input type="password" id="password" />
|
||||
<input type="password" th:field="*{confirmPassword}" id="confirmPassword" />
|
||||
</div>
|
||||
<span style="color: red;" th:if="${#fields.hasErrors('confirmPassword')}">
|
||||
<ul>
|
||||
<li th:each="erreur: ${#fields.errors('confirmPassword')}" th:text="${erreur}"></li>
|
||||
</ul>
|
||||
</span>
|
||||
</div>
|
||||
<div>Crédits: <span th:text="${userProfile.credit}"></span></div>
|
||||
<!-- Input cacher qui permet de stocker l'id du compte utilisateur à mettre à jour -->
|
||||
|
||||
@@ -5,7 +5,77 @@
|
||||
</head>
|
||||
<body>
|
||||
<div id="container-main">
|
||||
<h1>Nouvelle vente</h1>
|
||||
<form action="/articles/add" method="post" enctype="multipart/form-data">
|
||||
<!-- Nom de l'article -->
|
||||
<div>
|
||||
<label for="nom">Article:</label>
|
||||
<input type="text" id="nom" name="nom" required>
|
||||
</div>
|
||||
|
||||
<!-- Description -->
|
||||
<div>
|
||||
<label for="description">Description:</label>
|
||||
<textarea id="description" name="description" required></textarea>
|
||||
</div>
|
||||
|
||||
<!-- Catégorie -->
|
||||
<div>
|
||||
<label for="categorie">Catégorie:</label>
|
||||
<select id="categorie" name="categorie" required>
|
||||
<option value="categorie1">Catégorie 1</option>
|
||||
<option value="categorie2">Catégorie 2</option>
|
||||
<!-- Ajoutez d'autres options si nécessaire -->
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<!-- Photo -->
|
||||
<div>
|
||||
<label for="photo">Photo de l'article:</label>
|
||||
<input type="file" id="photo" name="photo" accept="image/jpeg" required>
|
||||
</div>
|
||||
|
||||
<!-- Mise à prix -->
|
||||
<div>
|
||||
<label for="prix">Mise à prix:</label>
|
||||
<input type="number" id="prix" name="prix" min="0" required>
|
||||
</div>
|
||||
|
||||
<!-- Date début enchère -->
|
||||
<div>
|
||||
<label for="dateDebut">Date début enchère:</label>
|
||||
<input type="date" id="dateDebut" name="dateDebut" min="<?php echo date('Y-m-d'); ?>" required>
|
||||
</div>
|
||||
|
||||
<!-- Date fin enchère -->
|
||||
<div>
|
||||
<label for="dateFin">Date fin enchère:</label>
|
||||
<input type="date" id="dateFin" name="dateFin" required>
|
||||
</div>
|
||||
|
||||
<!-- Lieu de retrait -->
|
||||
<h2>Retrait</h2>
|
||||
<div>
|
||||
<label for="rue">Rue:</label>
|
||||
<input type="text" id="rue" name="rue" required>
|
||||
</div>
|
||||
<div>
|
||||
<label for="codePostal">Code postal:</label>
|
||||
<input type="text" id="codePostal" name="codePostal" required>
|
||||
</div>
|
||||
<div>
|
||||
<label for="ville">Ville:</label>
|
||||
<input type="text" id="ville" name="ville" required>
|
||||
</div>
|
||||
|
||||
<!-- Bouton Enregistrer -->
|
||||
<div>
|
||||
<button type="submit">Enregistrer</button>
|
||||
</div>
|
||||
</form>
|
||||
<form th:action="@{/accueil}" method="post">
|
||||
<button type="submit">Annuler</button>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user