Beispiel #1
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);
    userSearchRepository.save(newUser);
    log.debug("Created Information for User: {}", newUser);
    return newUser;
  }
Beispiel #2
0
 public void updateUserInformation(
     String firstName, String lastName, String email, String langKey) {
   userRepository
       .findOneByLogin(SecurityUtils.getCurrentUserLogin())
       .ifPresent(
           u -> {
             u.setFirstName(firstName);
             u.setLastName(lastName);
             u.setEmail(email);
             u.setLangKey(langKey);
             userRepository.save(u);
             userSearchRepository.save(u);
             log.debug("Changed Information for User: {}", u);
           });
 }
Beispiel #3
0
 public Optional<User> activateRegistration(String key) {
   log.debug("Activating user for activation key {}", key);
   userRepository
       .findOneByActivationKey(key)
       .map(
           user -> {
             // activate given user for the registration key.
             user.setActivated(true);
             user.setActivationKey(null);
             userRepository.save(user);
             userSearchRepository.save(user);
             log.debug("Activated user: {}", user);
             return user;
           });
   return Optional.empty();
 }