Search in sources :

Example 1 with GlobalRating

use of com.faforever.api.data.domain.GlobalRating in project faf-java-api by FAForever.

the class UserService method activate.

/**
 * Creates a new user based on the information in the activation token.
 *
 * @param token the JWT in the format: <pre>
 *   {
 *     "action": "activate",
 *     "expiry": "2011-12-03T10:15:30Z",
 *     "
 *   }
 * </pre>
 */
@SneakyThrows
@SuppressWarnings("unchecked")
@Transactional
void activate(String token, String ipAddress) {
    Map<String, String> claims = fafTokenService.resolveToken(FafTokenType.REGISTRATION, token);
    String username = claims.get(KEY_USERNAME);
    String email = claims.get(KEY_EMAIL);
    String password = claims.get(KEY_PASSWORD);
    User user = new User();
    user.setPassword(password);
    user.setEmail(email);
    user.setLogin(username);
    user.setRecentIpAddress(ipAddress);
    user = userRepository.save(user);
    // @Deprecated
    // TODO: Move this db activity to the server (upcert instead of update) */
    // >>>
    double mean = properties.getRating().getDefaultMean();
    double deviation = properties.getRating().getDefaultDeviation();
    globalRatingRepository.save((GlobalRating) new GlobalRating().setId(user.getId()).setMean(mean).setDeviation(deviation));
    ladder1v1RatingRepository.save((Ladder1v1Rating) new Ladder1v1Rating().setId(user.getId()).setMean(mean).setDeviation(deviation));
    // <<<
    log.debug("User has been activated: {}", user);
    createOrUpdateMauticContact(user, ipAddress);
}
Also used : User(com.faforever.api.data.domain.User) GlobalRating(com.faforever.api.data.domain.GlobalRating) Ladder1v1Rating(com.faforever.api.data.domain.Ladder1v1Rating) SneakyThrows(lombok.SneakyThrows) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

GlobalRating (com.faforever.api.data.domain.GlobalRating)1 Ladder1v1Rating (com.faforever.api.data.domain.Ladder1v1Rating)1 User (com.faforever.api.data.domain.User)1 SneakyThrows (lombok.SneakyThrows)1 Transactional (org.springframework.transaction.annotation.Transactional)1