Search in sources :

Example 1 with ActivationToken

use of pl.pollub.cs.pentagoncafe.flare.domain.ActivationToken in project Flare-event-calendar by PollubCafe.

the class RegistrationServiceImpl method register.

@Transactional(rollbackFor = { MessagingException.class, ObjectNotFoundException.class })
public void register(RegistrationReqDTO registrationReqDTO) {
    String token = UUID.randomUUID().toString();
    ActivationToken activationToken = new ActivationToken(token);
    User user = User.builder().name(registrationReqDTO.getName()).surname(registrationReqDTO.getSurname()).nick(registrationReqDTO.getNick()).email(registrationReqDTO.getEmail()).phoneNumber(registrationReqDTO.getPhoneNumber()).password(passwordEncoder.encode(registrationReqDTO.getPassword())).role(Role.DISABLED).activationToken(activationToken).build();
    userRepository.save(user);
    Email activationEmail = emailBuilder.buildActivationEmail(token).to(user.getEmail());
    this.sendActivationEmail(activationEmail);
}
Also used : User(pl.pollub.cs.pentagoncafe.flare.domain.User) Email(pl.pollub.cs.pentagoncafe.flare.component.email.Email) HtmlEmail(pl.pollub.cs.pentagoncafe.flare.component.email.HtmlEmail) ActivationToken(pl.pollub.cs.pentagoncafe.flare.domain.ActivationToken) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with ActivationToken

use of pl.pollub.cs.pentagoncafe.flare.domain.ActivationToken in project Flare-event-calendar by PollubCafe.

the class RegistrationServiceImpl method finishRegistration.

public void finishRegistration(String token) {
    User user = userRepository.findByActivationToken(token).orElseThrow(() -> new ObjectNotFoundException(User.class));
    if (user.isEnabled())
        throw new UserAlreadyActivatedException(user.getNick());
    ActivationToken activationToken = user.getActivationToken();
    if (activationToken.getExpirationDate().isBefore(Instant.now())) {
        throw new TokenExpiredException();
    }
    user.setEnabled(true);
    user.setRole(Role.USER);
    userRepository.save(user);
}
Also used : User(pl.pollub.cs.pentagoncafe.flare.domain.User) ActivationToken(pl.pollub.cs.pentagoncafe.flare.domain.ActivationToken)

Example 3 with ActivationToken

use of pl.pollub.cs.pentagoncafe.flare.domain.ActivationToken in project Flare-event-calendar by PollubCafe.

the class RegistrationServiceImpl method resendToken.

@Transactional(rollbackFor = { MessagingException.class, ObjectNotFoundException.class })
public void resendToken(EmailReqDTO emailReqDTO) {
    User user = userRepository.findByEmail(emailReqDTO.getEmail()).orElseThrow(() -> new ObjectNotFoundException(User.class, "e-mail", emailReqDTO.getEmail()));
    if (user.isEnabled())
        throw new UserAlreadyActivatedException(user.getNick());
    String newToken = UUID.randomUUID().toString();
    ActivationToken newActivationToken = user.getActivationToken();
    newActivationToken.setToken(newToken);
    newActivationToken.refreshDate();
    userRepository.save(user);
    Email repeatedActivationEmail = emailBuilder.buildActivationEmail(newToken).to(user.getEmail());
    this.sendActivationEmail(repeatedActivationEmail);
}
Also used : User(pl.pollub.cs.pentagoncafe.flare.domain.User) Email(pl.pollub.cs.pentagoncafe.flare.component.email.Email) HtmlEmail(pl.pollub.cs.pentagoncafe.flare.component.email.HtmlEmail) ActivationToken(pl.pollub.cs.pentagoncafe.flare.domain.ActivationToken) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ActivationToken (pl.pollub.cs.pentagoncafe.flare.domain.ActivationToken)3 User (pl.pollub.cs.pentagoncafe.flare.domain.User)3 Transactional (org.springframework.transaction.annotation.Transactional)2 Email (pl.pollub.cs.pentagoncafe.flare.component.email.Email)2 HtmlEmail (pl.pollub.cs.pentagoncafe.flare.component.email.HtmlEmail)2