use of pl.pollub.cs.pentagoncafe.flare.exception.ObjectNotFoundException in project Flare-event-calendar by PollubCafe.
the class EventServiceImpl method createEvent.
@Override
public SimplifiedEventResponseDTO createEvent(CreateEventReqDTO createEventReqDTO) {
String authenticatedUserNick = SecurityContextHolder.getContext().getAuthentication().getName();
User authenticatedUser = userRepository.findByNick(authenticatedUserNick).orElseThrow(() -> new ObjectNotFoundException(User.class, "nick", authenticatedUserNick));
Address address = Address.builder().town(createEventReqDTO.getAddress_town()).zipCode(createEventReqDTO.getAddress_zipCode()).street(createEventReqDTO.getAddress_street()).province(Province.valueOf(createEventReqDTO.getAddress_province())).blockNumber(createEventReqDTO.getAddress_blockNumber()).houseNumber(createEventReqDTO.getAddress_houseNumber()).additionalInformation(createEventReqDTO.getAddress_additionalInformation()).build();
Event event = Event.builder().address(address).title(createEventReqDTO.getTitle()).description(createEventReqDTO.getDescription()).duration(createEventReqDTO.getDuration()).dateOfEventApproval(createEventReqDTO.getDateOfEventApproval().toInstant()).isApproved(false).onlyForRegisteredUsers(createEventReqDTO.isOnlyForRegisteredUsers()).dateOfCreation(Instant.now()).build();
authenticatedUser.addEvent(event);
Event createdEvent = eventRepository.save(event);
userRepository.save(authenticatedUser);
return eventMapper.mapToResponseDTO(createdEvent);
}
use of pl.pollub.cs.pentagoncafe.flare.exception.ObjectNotFoundException in project Flare-event-calendar by PollubCafe.
the class SecurityServiceImpl method resetPassword.
@Override
@Transactional(rollbackFor = { MessagingException.class, ObjectNotFoundException.class, ResetPasswordException.class })
public void resetPassword(EmailReqDTO emailReqDTO) {
String recipientAddress = emailReqDTO.getEmail();
User user = userRepository.findByEmail(recipientAddress).orElseThrow(() -> new ObjectNotFoundException(User.class, "e-mail", emailReqDTO.getEmail()));
if (!user.isEnabled()) {
throw new ResetPasswordException(messages.get("login.userAccount.disabled"));
}
if (user.isBanned()) {
throw new ResetPasswordException(messages.get("login.userAccount.locked"));
}
String generatedPassword = RandomPasswordGenerator.generate();
user.setPassword(passwordEncoder.encode(generatedPassword));
userRepository.save(user);
Email resetPasswordEmail = emailBuilder.buildResetPasswordEmail(generatedPassword).to(recipientAddress);
this.sendResetPasswordEmail(resetPasswordEmail);
}
use of pl.pollub.cs.pentagoncafe.flare.exception.ObjectNotFoundException in project Flare-event-calendar by PollubCafe.
the class EmailSenderServiceImpl method sendEmail.
@Override
public void sendEmail(EmailToEventAuthorReqDTO emailToEventAuthorReqDTO) {
Event event = eventRepository.findById(emailToEventAuthorReqDTO.getEventID()).orElseThrow(() -> new ObjectNotFoundException(Event.class, "id", emailToEventAuthorReqDTO.getEventID()));
User eventAuthor = event.getOrganizer();
String message = emailToEventAuthorReqDTO.getContent();
String subject = emailToEventAuthorReqDTO.getSubject();
Email email = emailBuilder.buildEmailToEventAuthor(message, subject).to(eventAuthor.getEmail());
try {
checkArgument(email instanceof HtmlEmail);
emailSender.send((HtmlEmail) email);
} catch (MessagingException e) {
e.printStackTrace();
throw new SendingEmailException("Email to author sending filed.");
}
}
Aggregations