Merge pull request 'gestion processus reinitialisation de mot de passe' (#242) from features/fiche_refonte into develop
Reviewed-on: #242
This commit was merged in pull request #242.
This commit is contained in:
@@ -47,7 +47,7 @@ public class UserController {
|
||||
|
||||
@PostMapping("/create")
|
||||
@PreAuthorize("hasAuthority('CREATE_USER')")
|
||||
public ResponseEntity<?> createUser(@RequestBody @Valid @Validated UserPaylaodWeb userPaylaodWeb) {
|
||||
public ResponseEntity<?> createUser(@RequestBody UserPaylaodWeb userPaylaodWeb) {
|
||||
try {
|
||||
userPaylaodWeb = userService.createUser(userPaylaodWeb);
|
||||
return new ResponseEntity<>(
|
||||
|
||||
@@ -54,7 +54,7 @@ public class UserServiceImpl implements UserService {
|
||||
private String reseturl ;
|
||||
|
||||
@Value("${dgi.sigibe-foncier.reset-pw.token-delay}")
|
||||
private static long tokenDelay ;
|
||||
private String tokenDelay ;
|
||||
|
||||
|
||||
|
||||
@@ -83,7 +83,8 @@ public class UserServiceImpl implements UserService {
|
||||
}
|
||||
|
||||
User user = entityFromPayLoadService.getUserFromPayLoadWeb(userPaylaodWeb);
|
||||
user.setPassword(passwordEncoder.encode(userPaylaodWeb.getPassword()));
|
||||
user.setUsername(user.getEmail());
|
||||
user.setPassword(passwordEncoder.encode(stringService.getUniqueString()));
|
||||
|
||||
user.setTokenDate(LocalDateTime.now());
|
||||
String token= stringService.getUniqueString();
|
||||
@@ -280,6 +281,7 @@ public class UserServiceImpl implements UserService {
|
||||
|
||||
user.setPassword(passwordEncoder.encode(password));
|
||||
user.setResetPassword(false);
|
||||
user.setToken("");
|
||||
user= userRepository.save(user);
|
||||
Optional<UserPaylaodWeb> optionalUserPaylaodWeb = userRepository.findUserToDtoById(user.getId());
|
||||
return optionalUserPaylaodWeb.orElse(null);
|
||||
@@ -361,24 +363,25 @@ public class UserServiceImpl implements UserService {
|
||||
public Boolean validationTokenResetPassword(String token) {
|
||||
Optional<User> optionalUser=userRepository.findByToken(token);
|
||||
if(optionalUser.isEmpty()){
|
||||
throw new ApplicationException("Token invalide") ;
|
||||
return false ;
|
||||
}
|
||||
LocalDateTime tokenDate= optionalUser.get().getTokenDate();
|
||||
if(isTokenExpired(tokenDate)){
|
||||
throw new ApplicationException("Token expiré") ;
|
||||
}
|
||||
return true;
|
||||
return !isTokenExpired(tokenDate);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calcule la date d'expiration du token en ajoutant 24h à sa date de génération.
|
||||
*/
|
||||
public static LocalDateTime calculerDateExpiration(LocalDateTime dateToken) {
|
||||
public LocalDateTime calculerDateExpiration(LocalDateTime dateToken) {
|
||||
if (dateToken == null) {
|
||||
throw new IllegalArgumentException("La date du token ne peut pas être null");
|
||||
}
|
||||
return dateToken.plusHours(tokenDelay);
|
||||
|
||||
if(tokenDelay=="")
|
||||
return dateToken ;
|
||||
|
||||
return dateToken.plusHours(Integer.parseInt(tokenDelay));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -386,14 +389,14 @@ public class UserServiceImpl implements UserService {
|
||||
* Le token expire dès que la date actuelle est égale ou supérieure
|
||||
* à dateToken + 24h.
|
||||
*/
|
||||
public static boolean isTokenExpired(LocalDateTime dateToken) {
|
||||
public boolean isTokenExpired(LocalDateTime dateToken) {
|
||||
if (dateToken == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
LocalDateTime dateExpiration = calculerDateExpiration(dateToken);
|
||||
|
||||
return LocalDateTime.now().isBefore(dateExpiration);
|
||||
return LocalDateTime.now().isAfter(dateExpiration);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -582,6 +582,7 @@ public class EntityFromPayLoadService {
|
||||
}
|
||||
|
||||
|
||||
|
||||
public User getUserFromPayLoadWeb(UserPaylaodWeb userPaylaodWeb){
|
||||
User user =new User();
|
||||
Optional<Structure> optionalStructure = Optional.empty();
|
||||
|
||||
Reference in New Issue
Block a user