Max/Backend/UserControllerUpdate #94

Merged
Maxime merged 6 commits from Max/Backend/UserControllerUpdate into master 2024-03-14 21:53:35 +01:00
2 changed files with 10 additions and 12 deletions
Showing only changes of commit dae59f67ce - Show all commits

View File

@ -41,10 +41,10 @@ public class MockController {
@PostMapping("/mock")
public void postMock(){
User herobrine = new User("brine","hero","admin@admin.com","in your WalLs","ShadowsLand",new Date(0), "none",Role.Admin,passwordEncoder.encode("admin"));
User joe = new User("Mama","Joe","student@student.com","roundabout","DaWarudo",new Date(0), "None",Role.Student,passwordEncoder.encode("student"));
User meh = new User("Inspiration","lackOf","secretary@secretary.com","a Box","the street",new Date(0),"none", Role.Teacher,passwordEncoder.encode("secretary"));
User joke = new User("CthemBalls","Lemme","teacher@teacher.com","lab","faculty",new Date(0), "none",Role.Teacher,passwordEncoder.encode("teacher"));
User herobrine = new User("brine","hero","admin@admin.com","in your WalLs","ShadowsLand",new Date(0), "none",Role.Admin,"admin");
User joe = new User("Mama","Joe","student@student.com","roundabout","DaWarudo",new Date(0), "None",Role.Student,"student");
User meh = new User("Inspiration","lackOf","secretary@secretary.com","a Box","the street",new Date(0),"none", Role.Teacher,"secretary");
User joke = new User("CthemBalls","Lemme","teacher@teacher.com","lab","faculty",new Date(0), "none",Role.Teacher,"teacher");
mockUsers = new ArrayList<User>(Arrays.asList(herobrine,joe,meh,joke));

View File

@ -5,16 +5,10 @@ import org.springframework.stereotype.Service;
import ovh.herisson.Clyde.Repositories.UserRepository;
import ovh.herisson.Clyde.Tables.Role;
import ovh.herisson.Clyde.Tables.User;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.*;
@Service
public class UserService {
private final UserRepository userRepo;
private final BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
@ -35,16 +29,20 @@ public class UserService {
}
public boolean checkPassword(User user, String tryingPassword){
return passwordEncoder.matches(tryingPassword, user.getPassword());
}
public void save(User user){
user.setPassword(encodePassword(user.getPassword()));
userRepo.save(user);
}
Maxime marked this conversation as resolved
Review

Si c'est du debug il faudrais l'enlever, si c'est du log c'est mieux d'utiliser Logger.info(msg) https://docs.oracle.com/en/java/javase/21/docs/api/java.logging/java/util/logging/Logger.html#info(java.lang.String)

Si c'est du debug il faudrais l'enlever, si c'est du log c'est mieux d'utiliser `Logger.info(msg)` https://docs.oracle.com/en/java/javase/21/docs/api/java.logging/java/util/logging/Logger.html#info(java.lang.String)
Review

hups !

hups !
public Iterable<User> getAll(){
return userRepo.findAll();
}
public String encodePassword(String rawPassword){
return passwordEncoder.encode(rawPassword);
}
}