|
|
|
@@ -54,7 +54,7 @@ public class UserServiceImpl implements UserService {
|
|
|
|
private String reseturl ;
|
|
|
|
private String reseturl ;
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${dgi.sigibe-foncier.reset-pw.token-delay}")
|
|
|
|
@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 user = entityFromPayLoadService.getUserFromPayLoadWeb(userPaylaodWeb);
|
|
|
|
user.setPassword(passwordEncoder.encode(userPaylaodWeb.getPassword()));
|
|
|
|
user.setUsername(user.getEmail());
|
|
|
|
|
|
|
|
user.setPassword(passwordEncoder.encode(stringService.getUniqueString()));
|
|
|
|
|
|
|
|
|
|
|
|
user.setTokenDate(LocalDateTime.now());
|
|
|
|
user.setTokenDate(LocalDateTime.now());
|
|
|
|
String token= stringService.getUniqueString();
|
|
|
|
String token= stringService.getUniqueString();
|
|
|
|
@@ -280,6 +281,7 @@ public class UserServiceImpl implements UserService {
|
|
|
|
|
|
|
|
|
|
|
|
user.setPassword(passwordEncoder.encode(password));
|
|
|
|
user.setPassword(passwordEncoder.encode(password));
|
|
|
|
user.setResetPassword(false);
|
|
|
|
user.setResetPassword(false);
|
|
|
|
|
|
|
|
user.setToken("");
|
|
|
|
user= userRepository.save(user);
|
|
|
|
user= userRepository.save(user);
|
|
|
|
Optional<UserPaylaodWeb> optionalUserPaylaodWeb = userRepository.findUserToDtoById(user.getId());
|
|
|
|
Optional<UserPaylaodWeb> optionalUserPaylaodWeb = userRepository.findUserToDtoById(user.getId());
|
|
|
|
return optionalUserPaylaodWeb.orElse(null);
|
|
|
|
return optionalUserPaylaodWeb.orElse(null);
|
|
|
|
@@ -361,24 +363,25 @@ public class UserServiceImpl implements UserService {
|
|
|
|
public Boolean validationTokenResetPassword(String token) {
|
|
|
|
public Boolean validationTokenResetPassword(String token) {
|
|
|
|
Optional<User> optionalUser=userRepository.findByToken(token);
|
|
|
|
Optional<User> optionalUser=userRepository.findByToken(token);
|
|
|
|
if(optionalUser.isEmpty()){
|
|
|
|
if(optionalUser.isEmpty()){
|
|
|
|
throw new ApplicationException("Token invalide") ;
|
|
|
|
return false ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LocalDateTime tokenDate= optionalUser.get().getTokenDate();
|
|
|
|
LocalDateTime tokenDate= optionalUser.get().getTokenDate();
|
|
|
|
if(isTokenExpired(tokenDate)){
|
|
|
|
return !isTokenExpired(tokenDate);
|
|
|
|
throw new ApplicationException("Token expiré") ;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Calcule la date d'expiration du token en ajoutant 24h à sa date de génération.
|
|
|
|
* 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) {
|
|
|
|
if (dateToken == null) {
|
|
|
|
throw new IllegalArgumentException("La date du token ne peut pas être 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
|
|
|
|
* Le token expire dès que la date actuelle est égale ou supérieure
|
|
|
|
* à dateToken + 24h.
|
|
|
|
* à dateToken + 24h.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static boolean isTokenExpired(LocalDateTime dateToken) {
|
|
|
|
public boolean isTokenExpired(LocalDateTime dateToken) {
|
|
|
|
if (dateToken == null) {
|
|
|
|
if (dateToken == null) {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LocalDateTime dateExpiration = calculerDateExpiration(dateToken);
|
|
|
|
LocalDateTime dateExpiration = calculerDateExpiration(dateToken);
|
|
|
|
|
|
|
|
|
|
|
|
return LocalDateTime.now().isBefore(dateExpiration);
|
|
|
|
return LocalDateTime.now().isAfter(dateExpiration);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|