use of py.org.fundacionparaguaya.pspserver.security.entities.UserEntity in project FP-PSP-SERVER by FundacionParaguaya.
the class PasswordResetTokenServiceImpl method validatePasswordResetToken.
@Override
public void validatePasswordResetToken(String token, Long userId, String password, String repeatPassword) {
checkArgument(userId > 0, i18n.translate("argument.nonNegative", userId));
UserEntity userEntity = userRepository.findOne(userId);
if (userEntity == null) {
throw new UnknownResourceException(i18n.translate("user.notExist", userId));
}
PasswordResetTokenEntity passwordResetTokenEntity = passwordTokenRepository.findByToken(token);
if (passwordResetTokenEntity == null || passwordResetTokenEntity.getUser().getId().longValue() != userId.longValue()) {
throw new CustomParameterizedException(i18n.translate("email.invalidToken", token));
}
Calendar cal = Calendar.getInstance();
if ((passwordResetTokenEntity.getExpiryDate().getTime() - cal.getTime().getTime()) <= 0) {
throw new CustomParameterizedException(i18n.translate("email.expiredToken", token));
}
if (!password.equals(repeatPassword)) {
throw new CustomParameterizedException("Password does not match the confirm password");
}
userEntity.setPass(encryptPassword(repeatPassword));
userRepository.save(userEntity);
}
use of py.org.fundacionparaguaya.pspserver.security.entities.UserEntity in project FP-PSP-SERVER by FundacionParaguaya.
the class UserServiceImpl method addUserWithRoleAndApplication.
@Override
public UserDTO addUserWithRoleAndApplication(UserRoleApplicationDTO userRoleApplicationDTO, UserDetailsDTO userDetails) {
userRepository.findOneByUsername(userRoleApplicationDTO.getUsername()).ifPresent(user -> {
throw new CustomParameterizedException("User already exists.", new ImmutableMultimap.Builder<String, String>().put("username", user.getUsername()).build().asMap());
});
UserEntity user = new UserEntity();
user.setUsername(userRoleApplicationDTO.getUsername());
user.setEmail(userRoleApplicationDTO.getEmail());
user.setPass(new BCryptPasswordEncoder().encode(userRoleApplicationDTO.getPass()));
user.setActive(true);
UserEntity newUser = userRepository.save(user);
if (userRoleApplicationDTO.getRole() != null) {
createUserRole(newUser, userRoleApplicationDTO.getRole());
}
if (userRoleApplicationDTO.getOrganizationId() != null) {
createUserOrganization(newUser, userRoleApplicationDTO);
} else if (userRoleApplicationDTO.getApplicationId() != null) {
createUserApplication(newUser, userRoleApplicationDTO);
}
return userMapper.entityToDto(newUser);
}
Aggregations