Пример #1
0
 public void changePassword(String password) {
   User currentUser = userRepository.findOneByLogin(SecurityUtils.getCurrentLogin());
   String encryptedPassword = passwordEncoder.encode(password);
   currentUser.setPassword(encryptedPassword);
   userRepository.save(currentUser);
   log.debug("Changed password for User: {}", currentUser);
 }
Пример #2
0
 public User requestPasswordReset(String mail) {
   User user = userRepository.findOneByEmail(mail);
   if (user != null && user.getActivated()) {
     user.setResetKey(RandomUtil.generateResetKey());
     user.setResetDate(DateTime.now());
     userRepository.save(user);
     return user;
   }
   return null;
 }
Пример #3
0
 /**
  * Not activated users should be automatically deleted after 3 days.
  *
  * <p>
  *
  * <p>This is scheduled to get fired everyday, at 01:00 (am).
  */
 @Scheduled(cron = "0 0 1 * * ?")
 public void removeNotActivatedUsers() {
   DateTime now = new DateTime();
   List<User> users =
       userRepository.findAllByActivatedIsFalseAndCreatedDateBefore(now.minusDays(3));
   for (User user : users) {
     log.debug("Deleting not activated user {}", user.getLogin());
     userRepository.delete(user);
   }
 }
Пример #4
0
 public void updateUserInformation(
     String firstName, String lastName, String email, String langKey) {
   User currentUser = userRepository.findOneByLogin(SecurityUtils.getCurrentLogin());
   currentUser.setFirstName(firstName);
   currentUser.setLastName(lastName);
   currentUser.setEmail(email);
   currentUser.setLangKey(langKey);
   userRepository.save(currentUser);
   log.debug("Changed Information for User: {}", currentUser);
 }
Пример #5
0
 public User activateRegistration(String key) {
   log.debug("Activating user for activation key {}", key);
   User user = userRepository.findOneByActivationKey(key);
   // activate given user for the registration key.
   if (user != null) {
     user.setActivated(true);
     user.setActivationKey(null);
     userRepository.save(user);
     log.debug("Activated user: {}", user);
   }
   return user;
 }
Пример #6
0
  public User createUserInformation(
      String login,
      String password,
      String firstName,
      String lastName,
      String email,
      String langKey) {

    User newUser = new User();
    Authority authority = authorityRepository.findOne("ROLE_USER");
    Set<Authority> authorities = new HashSet<>();
    String encryptedPassword = passwordEncoder.encode(password);
    newUser.setLogin(login);
    // new user gets initially a generated password
    newUser.setPassword(encryptedPassword);
    newUser.setFirstName(firstName);
    newUser.setLastName(lastName);
    newUser.setEmail(email);
    newUser.setLangKey(langKey);
    // new user is not active
    newUser.setActivated(false);
    // new user gets registration key
    newUser.setActivationKey(RandomUtil.generateActivationKey());
    authorities.add(authority);
    newUser.setAuthorities(authorities);
    userRepository.save(newUser);
    log.debug("Created Information for User: {}", newUser);
    return newUser;
  }
Пример #7
0
 public User completePasswordReset(String newPassword, String key) {
   log.debug("Reset user password for reset key {}", key);
   User user = userRepository.findOneByResetKey(key);
   DateTime oneDayAgo = DateTime.now().minusHours(24);
   if (user != null && user.getActivated()) {
     if (user.getResetDate().isAfter(oneDayAgo.toInstant().getMillis())) {
       user.setPassword(passwordEncoder.encode(newPassword));
       user.setResetKey(null);
       user.setResetDate(null);
       userRepository.save(user);
       return user;
     } else {
       return null;
     }
   }
   return null;
 }
Пример #8
0
 @Transactional(readOnly = true)
 public User getUserWithAuthorities() {
   User currentUser = userRepository.findOneByLogin(SecurityUtils.getCurrentLogin());
   currentUser.getAuthorities().size(); // eagerly load the association
   return currentUser;
 }