use of py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException in project FP-PSP-SERVER by FundacionParaguaya.
the class EmailServiceImpl method sendSimpleMessage.
@Override
public void sendSimpleMessage(String to, String subject, String text) {
try {
MimeMessage mail = mailSender.createMimeMessage();
mail.setFrom(appProperties.getSender().getFrom());
MimeMessageHelper helper = new MimeMessageHelper(mail, true);
helper.setTo(to);
helper.setSubject(subject);
helper.setText(text, true);
mailSender.send(mail);
} catch (Exception e) {
LOG.error("Mail server connection failed ", e);
throw new CustomParameterizedException(i18n.translate("email.serverError"));
}
}
use of py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException in project FP-PSP-SERVER by FundacionParaguaya.
the class EmailServiceImpl method sendMessageWithAttachment.
@Override
public void sendMessageWithAttachment(String to, String subject, String text, String pathToAttachment) {
try {
MimeMessage message = mailSender.createMimeMessage();
message.setFrom(appProperties.getSender().getFrom());
MimeMessageHelper helper = new MimeMessageHelper(message, true);
helper.setTo(to);
helper.setSubject(subject);
helper.setText(text);
FileSystemResource file = new FileSystemResource(new File(pathToAttachment));
helper.addAttachment("File", file);
mailSender.send(message);
} catch (MessagingException e) {
LOG.error("Error sending mail ", e);
throw new CustomParameterizedException(i18n.translate("email.errorSendingMail"));
}
}
use of py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException 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.common.exceptions.CustomParameterizedException in project FP-PSP-SERVER by FundacionParaguaya.
the class PasswordResetTokenServiceImpl method loadTemplate.
private String loadTemplate(String template) {
URL url = Resources.getResource(template);
String content = "";
try {
content = Resources.toString(url, Charsets.UTF_8);
} catch (IOException e) {
throw new CustomParameterizedException(i18n.translate("email.readById", template));
}
return content;
}
use of py.org.fundacionparaguaya.pspserver.common.exceptions.CustomParameterizedException 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