@Override
 @Transactional(readOnly = true)
 public VerificationToken getByEmail(String email, VerificationTokenPK.Type type) {
   VerificationToken verificationToken = verificationTokenDao.getByEmail(email, type);
   if (verificationToken == null) throw new NotFoundException();
   return verificationToken;
 }
 @Override
 @Transactional(timeout = 60)
 public VerificationToken resentToken(VerificationToken verificationToken) {
   generateToken(verificationToken);
   if (verificationToken.getType() == VerificationTokenPK.Type.PASSWORD_RESET
       && verificationToken.isVerified()) {
     verificationToken.setVerified(false);
   }
   VerificationToken updated = verificationTokenDao.update(verificationToken);
   emailService.sentVerificationToken(
       updated.getEmail(), verificationToken.getType(), updated.getToken());
   return verificationToken;
 }
  @Override
  @Transactional(timeout = 60)
  public VerificationToken registrateNewToken(VerificationToken verificationToken) {
    if (verificationToken.getType() == VerificationTokenPK.Type.PASSWORD_RESET
        && !userService.findByEmail(verificationToken.getEmail()).isPresent()) {
      throw new NotFoundException(
          String.format("The user with email %s was not found.", verificationToken.getEmail()));
    }

    generateToken(verificationToken);
    verificationTokenDao.save(verificationToken);
    emailService.sentVerificationToken(
        verificationToken.getEmail(), verificationToken.getType(), verificationToken.getToken());
    return verificationToken;
  }
 @Override
 @Transactional(readOnly = true)
 public Optional<VerificationToken> getToken(VerificationToken token) {
   return verificationTokenDao.getToken(token);
 }
 @Override
 @Transactional(readOnly = true)
 public boolean isPresent(VerificationToken verificationToken) {
   Optional<VerificationToken> token = verificationTokenDao.getToken(verificationToken);
   return token.isPresent();
 }
 @Override
 @Transactional
 public VerificationToken update(VerificationToken verificationToken) {
   return verificationTokenDao.update(verificationToken);
 }
 @Override
 @Transactional(readOnly = true)
 public Optional<VerificationToken> getByToken(String token) {
   return Optional.ofNullable(verificationTokenDao.getByToken(token));
 }