1
0
forked from PGL/Clyde

fix register

This commit is contained in:
Debucquoy Anthony 2024-04-21 22:15:55 +02:00
parent 636e17b4bf
commit a90243f4b9
Signed by: tonitch
GPG Key ID: A78D6421F083D42E
4 changed files with 15 additions and 16 deletions

View File

@ -1,6 +1,5 @@
package ovh.herisson.Clyde.EndPoints; package ovh.herisson.Clyde.EndPoints;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import ovh.herisson.Clyde.Repositories.*; import ovh.herisson.Clyde.Repositories.*;
import ovh.herisson.Clyde.Repositories.Inscription.ExternalCurriculumRepository; import ovh.herisson.Clyde.Repositories.Inscription.ExternalCurriculumRepository;
@ -20,7 +19,6 @@ import java.util.Date;
@CrossOrigin(originPatterns = "*", allowCredentials = "true") @CrossOrigin(originPatterns = "*", allowCredentials = "true")
public class MockController { public class MockController {
private final BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
public final UserService userService; public final UserService userService;
public final UserRepository userRepo; public final UserRepository userRepo;
public final TokenRepository tokenRepo; public final TokenRepository tokenRepo;
@ -75,13 +73,13 @@ public class MockController {
public void postMock(){ public void postMock(){
// user part // user part
User herobrine = new User("brine","hero","admin@admin.com","behind","ShadowsLand",new Date(0), null,Role.Admin,passwordEncoder.encode("admin")); 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,passwordEncoder.encode("student")); 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,passwordEncoder.encode("secretary")); 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,passwordEncoder.encode("teacher")); 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,passwordEncoder.encode("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,passwordEncoder.encode("inscriptionService")); 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, passwordEncoder.encode("jesuispaulleroi")); 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)); mockUsers = new ArrayList<>(Arrays.asList(herobrine,joe,meh,joke,lena,jojo, popo));
userService.saveAll(mockUsers); userService.saveAll(mockUsers);

View File

@ -1,6 +1,5 @@
package ovh.herisson.Clyde.Services.Inscription; package ovh.herisson.Clyde.Services.Inscription;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import ovh.herisson.Clyde.Repositories.*; import ovh.herisson.Clyde.Repositories.*;
import ovh.herisson.Clyde.Repositories.Inscription.ExternalCurriculumRepository; import ovh.herisson.Clyde.Repositories.Inscription.ExternalCurriculumRepository;
@ -27,7 +26,6 @@ public class InscriptionService {
private final CurriculumRepository curriculumRepo; private final CurriculumRepository curriculumRepo;
private final MinervalRepository minervalRepository; private final MinervalRepository minervalRepository;
private final BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
private final ExternalCurriculumRepository externalCurriculumRepository; private final ExternalCurriculumRepository externalCurriculumRepository;
private final UserService userService; private final UserService userService;
public InscriptionService(InscriptionRepository inscriptionRepo, UserRepository userRepo, UserCurriculumRepository userCurriculumRepo, CurriculumRepository curriculumRepo, MinervalRepository minervalRepository, ExternalCurriculumRepository externalCurriculumRepository, 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){ public InscriptionRequest save(InscriptionRequest inscriptionRequest){
inscriptionRequest.setPassword(passwordEncoder.encode(inscriptionRequest.getPassword()));
return inscriptionRepo.save(inscriptionRequest); return inscriptionRepo.save(inscriptionRequest);
} }

View File

@ -77,7 +77,7 @@ public class UserService {
target.setProfilePictureUrl((String) entry.getValue()); target.setProfilePictureUrl((String) entry.getValue());
break; break;
case "password": case "password":
target.setPassword(passwordEncoder.encode((String) entry.getValue())); target.setPassword((String) entry.getValue());
break; break;
} }
} }
@ -109,7 +109,6 @@ public class UserService {
public User save(User user){ public User save(User user){
RegNoGenerator.resetCount(); RegNoGenerator.resetCount();
user.setPassword(passwordEncoder.encode(user.getPassword()));
return userRepo.save(user); return userRepo.save(user);
} }

View File

@ -6,6 +6,7 @@ import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import org.hibernate.annotations.OnDelete; import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction; import org.hibernate.annotations.OnDeleteAction;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.GenericGenerator;
import ovh.herisson.Clyde.Tables.Msg.Discussion; import ovh.herisson.Clyde.Tables.Msg.Discussion;
import ovh.herisson.Clyde.Tables.Msg.Message; import ovh.herisson.Clyde.Tables.Msg.Message;
@ -63,7 +64,7 @@ public class User {
this.birthDate = birthDate; this.birthDate = birthDate;
this.profilePictureUrl = profilePictureUrl; this.profilePictureUrl = profilePictureUrl;
this.role = role; this.role = role;
this.password = password; this.password = (new BCryptPasswordEncoder()).encode(password);
} }
@ -78,8 +79,12 @@ public class User {
this.country = country; this.country = country;
this.birthDate = birthDate; this.birthDate = birthDate;
this.profilePictureUrl = profilePictureUrl; this.profilePictureUrl = profilePictureUrl;
this.password = password; this.password = (new BCryptPasswordEncoder()).encode(password);
this.role = Role.Student; this.role = Role.Student;
this.identityCardUrl = identityCardUrl; this.identityCardUrl = identityCardUrl;
} }
public void setPassword(String password) {
this.password = (new BCryptPasswordEncoder()).encode(password);
}
} }