Esempio n. 1
0
  public User createUser(
      String username, String email, String password, String nickname, boolean emailRegistration) {
    User user = new User();
    user.setUsername(username);
    user.setEmail(email);
    user.setPassword(encodePassword(password));
    user.setNickname(nickname);
    user.setEmailRegistration(emailRegistration);

    String verificationCode = UUID.randomUUID().toString();
    user.setVerificationCode(verificationCode);

    user = userRepository.save(user);

    UserDetails userDetails = new UserDetails();
    userDetails.setUserId(user.getId());
    userDetails.setSendLimitPerDay(DEFAULT_SEND_LIMIT_PER_DAY);
    userDetails.setReceiveLimitPerDay(DEFAULT_RECEIVE_LIMIT_PER_DAY);
    userDetailsRepository.save(userDetails);

    UserStatistics userStatistics = new UserStatistics();
    userStatistics.setUserId(user.getId());
    userStatisticsRepository.save(userStatistics);

    return user;
  }
Esempio n. 2
0
  public void changePassword(ChangePasswordDto changePassword) {
    User user = findOne(changePassword.getUserId());
    user.setPassword(encodePassword(changePassword.getNewPassword()));

    String oldPass = encodePassword(changePassword.getOldPassword());
    if (!oldPass.equals(user.getPassword())) {
      throw new IllegalArgumentException("Old password doesn't match");
    }

    userRepository.save(user);
  }
Esempio n. 3
0
  public void updateSettings(UserSettingsDto userSettings, Long userId) {
    UserDetails userDetails = getUserDetails(userId);
    if (userSettings.getReceiveLimitPerDay() != null) {
      userDetails.setReceiveLimitPerDay(userSettings.getReceiveLimitPerDay());
    }
    userDetails.setReceiveNewPhotoNotifications(userSettings.getReceiveNewPhotoNotifications());
    userDetails.setReceiveCommentNotifications(userSettings.getReceiveCommentNotifications());

    if (StringUtils.hasText(userSettings.getNickname())) {
      userDetails.getUser().setNickname(userSettings.getNickname().trim());
      userRepository.save(userDetails.getUser());
    }

    userDetailsRepository.save(userDetails);
  }
Esempio n. 4
0
 public User findOne(Long userId) {
   return userRepository.findOne(userId);
 }
Esempio n. 5
0
 public User findByUsernameIgnoreCaseOrEmailIgnoreCase(String p_username, String p_email) {
   return userRepository.findByUsernameIgnoreCaseOrEmailIgnoreCase(p_username, p_email);
 }