public User createUserInformation( String login, String password, String firstName, String lastName, String email, String langKey) { User newUser = new User(); Role role = roleRepository.findOne("ROLE_USER"); Set<Role> roles = 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()); roles.add(role); newUser.setRoles(roles); userRepository.save(newUser); log.debug("Created Information for User: {}", newUser); return newUser; }
/** * 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() { ZonedDateTime now = ZonedDateTime.now(); List<User> users = userRepository.findAllByActivatedIsFalseAndCreatedDateBefore(now.minusDays(3)); for (User user : users) { log.debug("Deleting not activated user {}", user.getLogin()); userRepository.delete(user); } }
@Transactional(readOnly = true) public User getUserWithRoles() { User user = userRepository.findOneByLogin(SecurityUtils.getCurrentUser().getUsername()).get(); user.getRoles().size(); // eagerly load the association return user; }
@Transactional(readOnly = true) public User getUserWithRoles(Long id) { User user = userRepository.findOne(id); user.getRoles().size(); // eagerly load the association return user; }