Beispiel #1
0
  public static String getDisplayName(User user) {
    String displayName;
    if (StringUtils.hasText(user.getNickname())) {
      displayName = user.getNickname();
    } else {
      displayName = CityUtils.getLocationName(user.getDetails().getCurrentCity());
    }

    return com.sendish.api.util.StringUtils.trim(displayName, MAX_NAME_LENGTH, "...");
  }
Beispiel #2
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;
  }
Beispiel #3
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);
  }
Beispiel #4
0
  public UserProfileDto getUserProfile(Long userId) {
    UserDetails userDetails = getUserDetails(userId);

    UserProfileDto userProfileDto = new UserProfileDto();
    if (userDetails.getLastLocationTime() != null) {
      userProfileDto.setLastPlace(
          CityUtils.getLocationName(
              userDetails.getCurrentCity(), MAX_LOCATION_NAME_PROFILE_DETAILS));
      userProfileDto.setLastLat(userDetails.getLocation().getLatitude());
      userProfileDto.setLastLng(userDetails.getLocation().getLongitude());
      userProfileDto.setLastLocationTime(userDetails.getLastInteractionTime().toDate());
    }

    User user = userDetails.getUser();
    userProfileDto.setEmailRegistration(user.getEmailRegistration());
    userProfileDto.setNick(user.getNickname());

    Long userRank = rankingService.getRank(userId);
    if (userRank == null) {
      userProfileDto.setRank("No rank");
    } else {
      userProfileDto.setRank(userRank.toString());
      Long score = rankingService.getScore(userId);
      userProfileDto.setRankScore(score < 0 ? "< 0" : String.valueOf(score));
    }

    UserStatisticsDto userStatistics = statisticsService.getUserStatistics(userId);
    userProfileDto.setTotalDislikes(userStatistics.getTotalDislikeCount());
    userProfileDto.setTotalLikes(userStatistics.getTotalLikeCount());
    userProfileDto.setCitiesCount(userStatistics.getTotalCityCount());
    userProfileDto.setUnseenPhotoCount(userStatistics.getUnseenPhotoCount());
    userProfileDto.setDailySendLimitLeft(getSentLimitLeft(userDetails, userStatistics));
    userProfileDto.setNewActivities(userStatistics.getHasNewActivities());
    userProfileDto.setNewPhotoReplyActivities(userStatistics.getHasNewPhotoReplyActivities());
    userProfileDto.setUnreadInboxItemCount(userStatistics.getUnreadInboxItemCount());
    userProfileDto.setId(userId);

    DateTime now = DateTime.now();
    if (userDetails.getLastInteractionTime() != null
        && userDetails.getLastInteractionTime().isBefore(now.minusMinutes(10))) {
      userDetails.setLastInteractionTime(now);
      userDetails.setComeBackReminderTime(null);
      userDetailsRepository.save(userDetails);
    }

    return userProfileDto;
  }