private SimpleMailMessage constructEmail(String subject, String body, User user) {
   final SimpleMailMessage email = new SimpleMailMessage();
   email.setSubject(subject);
   email.setText(body);
   email.setTo(user.getEmail());
   email.setFrom(env.getProperty("support.email"));
   return email;
 }
Example #2
0
  @Override
  @Transactional
  public void onApplicationEvent(final ContextRefreshedEvent event) {
    if (alreadySetup) {
      return;
    }

    // == create initial privileges
    final Privilege readPrivilege = createPrivilegeIfNotFound("READ_PRIVILEGE");
    final Privilege writePrivilege = createPrivilegeIfNotFound("WRITE_PRIVILEGE");

    // == create initial roles
    final List<Privilege> adminPrivileges = Arrays.asList(readPrivilege, writePrivilege);
    createRoleIfNotFound("ROLE_ADMIN", adminPrivileges);
    createRoleIfNotFound("ROLE_USER", Arrays.asList(readPrivilege));

    final Role adminRole = roleRepository.findByName("ROLE_ADMIN");
    final User user = new User();
    user.setFirstName("Test");
    user.setLastName("Test");
    user.setPassword(passwordEncoder.encode("test"));
    user.setEmail("*****@*****.**");
    user.setRoles(Arrays.asList(adminRole));
    user.setEnabled(true);
    userRepository.save(user);

    alreadySetup = true;
  }
 @Override
 public int hashCode() {
   final int prime = 31;
   int result = 1;
   result = prime * result + ((expiryDate == null) ? 0 : expiryDate.hashCode());
   result = prime * result + ((token == null) ? 0 : token.hashCode());
   result = prime * result + ((user == null) ? 0 : user.hashCode());
   return result;
 }
 private final SimpleMailMessage constructEmailMessage(
     final OnRegistrationCompleteEvent event, final User user, final String token) {
   final String recipientAddress = user.getEmail();
   final String subject = "Registration Confirmation";
   final String confirmationUrl = event.getAppUrl() + "/regitrationConfirm.html?token=" + token;
   final String message = messages.getMessage("message.regSucc", null, event.getLocale());
   final SimpleMailMessage email = new SimpleMailMessage();
   email.setTo(recipientAddress);
   email.setSubject(subject);
   email.setText(message + " \r\n" + confirmationUrl);
   email.setFrom(env.getProperty("support.email"));
   return email;
 }
 @Override
 public boolean equals(Object obj) {
   if (this == obj) return true;
   if (obj == null) return false;
   if (getClass() != obj.getClass()) return false;
   VerificationToken other = (VerificationToken) obj;
   if (expiryDate == null) {
     if (other.expiryDate != null) return false;
   } else if (!expiryDate.equals(other.expiryDate)) return false;
   if (token == null) {
     if (other.token != null) return false;
   } else if (!token.equals(other.token)) return false;
   if (user == null) {
     if (other.user != null) return false;
   } else if (!user.equals(other.user)) return false;
   return true;
 }
 private final SimpleMailMessage constructResetTokenEmail(
     final String contextPath, final Locale locale, final String token, final User user) {
   final String url = contextPath + "/user/changePassword?id=" + user.getId() + "&token=" + token;
   final String message = messages.getMessage("message.resetPassword", null, locale);
   return constructEmail("Reset Password", message + " \r\n" + url, user);
 }