From a90243f4b9e45684789b09d331b658ac3a81e307 Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Sun, 21 Apr 2024 22:15:55 +0200 Subject: [PATCH] fix register --- .../herisson/Clyde/EndPoints/MockController.java | 16 +++++++--------- .../Services/Inscription/InscriptionService.java | 3 --- .../ovh/herisson/Clyde/Services/UserService.java | 3 +-- .../java/ovh/herisson/Clyde/Tables/User.java | 9 +++++++-- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java index 3b80212..1e89142 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java @@ -1,6 +1,5 @@ package ovh.herisson.Clyde.EndPoints; -import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.web.bind.annotation.*; import ovh.herisson.Clyde.Repositories.*; import ovh.herisson.Clyde.Repositories.Inscription.ExternalCurriculumRepository; @@ -20,7 +19,6 @@ import java.util.Date; @CrossOrigin(originPatterns = "*", allowCredentials = "true") public class MockController { - private final BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); public final UserService userService; public final UserRepository userRepo; public final TokenRepository tokenRepo; @@ -75,13 +73,13 @@ public class MockController { public void postMock(){ // user part - User herobrine = new User("brine","hero","admin@admin.com","behind","ShadowsLand",new Date(0), null,Role.Admin,passwordEncoder.encode("admin")); - User joe = new User("Mama","Joe","student@student.com","roundabout","England",new Date(0), null,Role.Student,passwordEncoder.encode("student")); - User meh = new User("Polo","Marco","secretary@secretary.com","a Box","Monaco",new Date(0), null,Role.Secretary,passwordEncoder.encode("secretary")); - User joke = new User("Gaillard","Corentin","teacher@teacher.com","lab","faculty",new Date(0), null,Role.Teacher,passwordEncoder.encode("teacher")); - User jojo = new User("Bridoux","Justin","teacher2@teacher2.com","lab","faculty",new Date(0), null,Role.Teacher,passwordEncoder.encode("teacher")); - User lena = new User("Louille","Lena","inscriptionService@InscriptionService.com","no","yes",new Date(0), null,Role.InscriptionService,passwordEncoder.encode("inscriptionService")); - User popo = new User("Smith", "Paul", "paulsmith@gmail.com", "306 rue du poulet", "belgique", new Date(0), null, Role.Student, passwordEncoder.encode("jesuispaulleroi")); + User herobrine = new User("brine","hero","admin@admin.com","behind","ShadowsLand",new Date(0), null,Role.Admin,"admin"); + User joe = new User("Mama","Joe","student@student.com","roundabout","England",new Date(0), null,Role.Student,"student"); + User meh = new User("Polo","Marco","secretary@secretary.com","a Box","Monaco",new Date(0), null,Role.Secretary,"secretary"); + User joke = new User("Gaillard","Corentin","teacher@teacher.com","lab","faculty",new Date(0), null,Role.Teacher,"teacher"); + User jojo = new User("Bridoux","Justin","teacher2@teacher2.com","lab","faculty",new Date(0), null,Role.Teacher,"teacher"); + User lena = new User("Louille","Lena","inscriptionService@InscriptionService.com","no","yes",new Date(0), null,Role.InscriptionService,"inscriptionService"); + User popo = new User("Smith", "Paul", "paulsmith@gmail.com", "306 rue du poulet", "belgique", new Date(0), null, Role.Student, "jesuispaulleroi"); mockUsers = new ArrayList<>(Arrays.asList(herobrine,joe,meh,joke,lena,jojo, popo)); userService.saveAll(mockUsers); diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/Inscription/InscriptionService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/Inscription/InscriptionService.java index 374b03b..aef2beb 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/Inscription/InscriptionService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/Inscription/InscriptionService.java @@ -1,6 +1,5 @@ package ovh.herisson.Clyde.Services.Inscription; -import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.stereotype.Service; import ovh.herisson.Clyde.Repositories.*; import ovh.herisson.Clyde.Repositories.Inscription.ExternalCurriculumRepository; @@ -27,7 +26,6 @@ public class InscriptionService { private final CurriculumRepository curriculumRepo; private final MinervalRepository minervalRepository; - private final BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); private final ExternalCurriculumRepository externalCurriculumRepository; private final UserService userService; public InscriptionService(InscriptionRepository inscriptionRepo, UserRepository userRepo, UserCurriculumRepository userCurriculumRepo, CurriculumRepository curriculumRepo, MinervalRepository minervalRepository, ExternalCurriculumRepository externalCurriculumRepository, UserService userService){ @@ -41,7 +39,6 @@ public class InscriptionService { } public InscriptionRequest save(InscriptionRequest inscriptionRequest){ - inscriptionRequest.setPassword(passwordEncoder.encode(inscriptionRequest.getPassword())); return inscriptionRepo.save(inscriptionRequest); } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/UserService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/UserService.java index 638c0c9..483d731 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/UserService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/UserService.java @@ -77,7 +77,7 @@ public class UserService { target.setProfilePictureUrl((String) entry.getValue()); break; case "password": - target.setPassword(passwordEncoder.encode((String) entry.getValue())); + target.setPassword((String) entry.getValue()); break; } } @@ -109,7 +109,6 @@ public class UserService { public User save(User user){ RegNoGenerator.resetCount(); - user.setPassword(passwordEncoder.encode(user.getPassword())); return userRepo.save(user); } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/User.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/User.java index 6b724de..90fb0da 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Tables/User.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/User.java @@ -6,6 +6,7 @@ import lombok.Data; import lombok.NoArgsConstructor; import org.hibernate.annotations.OnDelete; import org.hibernate.annotations.OnDeleteAction; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.hibernate.annotations.GenericGenerator; import ovh.herisson.Clyde.Tables.Msg.Discussion; import ovh.herisson.Clyde.Tables.Msg.Message; @@ -63,7 +64,7 @@ public class User { this.birthDate = birthDate; this.profilePictureUrl = profilePictureUrl; this.role = role; - this.password = password; + this.password = (new BCryptPasswordEncoder()).encode(password); } @@ -78,8 +79,12 @@ public class User { this.country = country; this.birthDate = birthDate; this.profilePictureUrl = profilePictureUrl; - this.password = password; + this.password = (new BCryptPasswordEncoder()).encode(password); this.role = Role.Student; this.identityCardUrl = identityCardUrl; } + + public void setPassword(String password) { + this.password = (new BCryptPasswordEncoder()).encode(password); + } }