test
This commit is contained in:
@@ -14,13 +14,15 @@ public class UserProfil {
|
|||||||
private String ville;
|
private String ville;
|
||||||
private String password;
|
private String password;
|
||||||
private String confirmPassword;
|
private String confirmPassword;
|
||||||
|
private String currentPassword;
|
||||||
|
private String newPassword;
|
||||||
private float credit;
|
private float credit;
|
||||||
private boolean isAdmin;
|
private boolean isAdmin;
|
||||||
|
|
||||||
//Constructeur
|
//Constructeur
|
||||||
public UserProfil(){}
|
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, String confirmPassword, 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, String newPassword, String currentPassword, int credit, boolean isAdmin) {
|
||||||
setId(id);
|
setId(id);
|
||||||
setPrenom(prenom);
|
setPrenom(prenom);
|
||||||
setNom(nom);
|
setNom(nom);
|
||||||
@@ -34,6 +36,8 @@ public class UserProfil {
|
|||||||
setConfirmPassword(confirmPassword);
|
setConfirmPassword(confirmPassword);
|
||||||
setCredit(credit);
|
setCredit(credit);
|
||||||
setAdmin(isAdmin);
|
setAdmin(isAdmin);
|
||||||
|
setCurrentPassword(currentPassword);
|
||||||
|
setNewPassword(newPassword);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Méthode getter et setter
|
//Méthode getter et setter
|
||||||
@@ -141,4 +145,19 @@ public class UserProfil {
|
|||||||
isAdmin = admin;
|
isAdmin = admin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getCurrentPassword() {
|
||||||
|
return currentPassword;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCurrentPassword(String currentPassword) {
|
||||||
|
this.currentPassword = currentPassword;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNewPassword() {
|
||||||
|
return newPassword;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNewPassword(String newPassword) {
|
||||||
|
this.newPassword = newPassword;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,13 +41,13 @@ public class InscriptionController {
|
|||||||
// Utilisez le service approprié pour récupérer les informations de l'utilisateur à partir du nom d'utilisateur
|
// Utilisez le service approprié pour récupérer les informations de l'utilisateur à partir du nom d'utilisateur
|
||||||
UserProfil currentUserProfile = userService.utilisateurByName(username);
|
UserProfil currentUserProfile = userService.utilisateurByName(username);
|
||||||
// Vérifiez si le mot de passe actuel correspond à celui stocké dans la base de données
|
// Vérifiez si le mot de passe actuel correspond à celui stocké dans la base de données
|
||||||
if (!passwordEncoder.matches(userProfile.getPassword(), currentUserProfile.getPassword())) {
|
if (!passwordEncoder.matches(userProfile.getNewPassword(), currentUserProfile.getPassword())) {
|
||||||
// Mot de passe actuel incorrect, renvoyer une erreur
|
// Mot de passe actuel incorrect, renvoyer une erreur
|
||||||
result.rejectValue("currentPassword", "invalid", "Mot de passe actuel incorrect");
|
result.rejectValue("currentPassword", "invalid", "Mot de passe actuel incorrect");
|
||||||
return "editProfil"; // Rediriger vers la page de modification du profil avec une erreur
|
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
|
// Vérifiez si le nouveau mot de passe et sa confirmation correspondent
|
||||||
if (!userProfile.getPassword().equals(userProfile.getConfirmPassword())) {
|
if (!userProfile.getNewPassword().equals(userProfile.getConfirmPassword())) {
|
||||||
// Mauvaise correspondance entre le nouveau mot de passe et sa confirmation, renvoyer une erreur
|
// 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");
|
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
|
return "editProfil"; // Rediriger vers la page de modification du profil avec une erreur
|
||||||
|
|||||||
@@ -39,6 +39,17 @@ public class ProfilController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/edit")
|
||||||
|
public String edit(Model model) {
|
||||||
|
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||||
|
if (!authentication.getName().equals("anonymousUser")) {
|
||||||
|
String username = authentication.getName();
|
||||||
|
UserProfil userProfile = userService.utilisateurByName(username);
|
||||||
|
model.addAttribute("userProfile", userProfile);
|
||||||
|
}
|
||||||
|
return "editProfil";
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("/edit")
|
@PostMapping("/edit")
|
||||||
public String editProfile(Model model) {
|
public String editProfile(Model model) {
|
||||||
// Obtenez l'authentification actuelle
|
// Obtenez l'authentification actuelle
|
||||||
|
|||||||
@@ -17,9 +17,9 @@ public class WebSecurityConfig{
|
|||||||
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||||
http.authorizeHttpRequests((requests) -> requests
|
http.authorizeHttpRequests((requests) -> requests
|
||||||
.requestMatchers("/", "/accueil").permitAll()
|
.requestMatchers("/", "/accueil").permitAll()
|
||||||
.requestMatchers("/accueil", "/login", "/inscription/**", "/searchArticle", "/article/**", "/change-language", "/profile/**").permitAll()
|
.requestMatchers("/accueil", "/login", "/inscription/**", "/searchArticle", "/article/**", "/change-language").permitAll()
|
||||||
.requestMatchers("/css/**", "/images/**", "/assets/**", "/img/**", "/js/**").permitAll()
|
.requestMatchers("/css/**", "/images/**", "/assets/**", "/img/**", "/js/**").permitAll()
|
||||||
.requestMatchers("/profile/**").authenticated()
|
.requestMatchers("/profil/**").authenticated()
|
||||||
.requestMatchers("/admin").hasRole("ADMIN")
|
.requestMatchers("/admin").hasRole("ADMIN")
|
||||||
.anyRequest().authenticated())
|
.anyRequest().authenticated())
|
||||||
.formLogin((form) -> form.loginPage("/login").defaultSuccessUrl("/", true))
|
.formLogin((form) -> form.loginPage("/login").defaultSuccessUrl("/", true))
|
||||||
|
|||||||
@@ -110,7 +110,7 @@
|
|||||||
<div class="champ-saisie">
|
<div class="champ-saisie">
|
||||||
<label for="currentPassword">Mot de passe actuel: </label>
|
<label for="currentPassword">Mot de passe actuel: </label>
|
||||||
<div>
|
<div>
|
||||||
<input type="password" th:field="*{currentPassword}" id="currentPassword" />
|
<input type="password" th:field="*{currentPassword}" name="currentPassword" id="currentPassword" />
|
||||||
</div>
|
</div>
|
||||||
<span style="color: red;" th:if="${#fields.hasErrors('currentPassword')}">
|
<span style="color: red;" th:if="${#fields.hasErrors('currentPassword')}">
|
||||||
<ul>
|
<ul>
|
||||||
@@ -122,7 +122,7 @@
|
|||||||
<div class="champ-saisie">
|
<div class="champ-saisie">
|
||||||
<label for="newPassword">Nouveau mot de passe: </label>
|
<label for="newPassword">Nouveau mot de passe: </label>
|
||||||
<div>
|
<div>
|
||||||
<input type="password" th:field="*{newPassword}" id="newPassword" />
|
<input type="password" th:field="*{newPassword}" name="newPassword" id="newPassword" />
|
||||||
</div>
|
</div>
|
||||||
<span style="color: red;" th:if="${#fields.hasErrors('newPassword')}">
|
<span style="color: red;" th:if="${#fields.hasErrors('newPassword')}">
|
||||||
<ul>
|
<ul>
|
||||||
|
|||||||
Reference in New Issue
Block a user