use of com.faforever.api.data.domain.User in project faf-java-api by FAForever.
the class UserServiceTest method changeLoginTooEarly.
@Test
public void changeLoginTooEarly() {
expectedException.expect(ApiExceptionWithCode.apiExceptionWithCode(ErrorCode.USERNAME_CHANGE_TOO_EARLY));
when(nameRecordRepository.getDaysSinceLastNewRecord(anyInt(), anyInt())).thenReturn(Optional.of(BigInteger.valueOf(5)));
User user = createUser(TEST_USERID, TEST_USERNAME, TEST_CURRENT_PASSWORD, TEST_CURRENT_EMAIL);
instance.changeLogin(TEST_USERNAME_CHANGED, user, "127.0.0.1");
}
use of com.faforever.api.data.domain.User in project faf-java-api by FAForever.
the class UserServiceTest method activate.
@Test
public void activate() {
final String TEST_IP_ADDRESS = "127.0.0.1";
when(fafTokenService.resolveToken(FafTokenType.REGISTRATION, TOKEN_VALUE)).thenReturn(ImmutableMap.of(UserService.KEY_USERNAME, TEST_USERNAME, UserService.KEY_EMAIL, TEST_CURRENT_EMAIL, UserService.KEY_PASSWORD, fafPasswordEncoder.encode(TEST_NEW_PASSWORD)));
instance.activate(TOKEN_VALUE, TEST_IP_ADDRESS);
ArgumentCaptor<User> captor = ArgumentCaptor.forClass(User.class);
verify(userRepository).save(captor.capture());
verify(globalRatingRepository).save(any(GlobalRating.class));
verify(ladder1v1RatingRepository).save(any(Ladder1v1Rating.class));
User user = captor.getValue();
assertThat(user.getLogin(), is(TEST_USERNAME));
assertThat(user.getEmail(), is(TEST_CURRENT_EMAIL));
assertThat(user.getPassword(), is(fafPasswordEncoder.encode(TEST_NEW_PASSWORD)));
assertThat(user.getRecentIpAddress(), is(TEST_IP_ADDRESS));
verify(mauticService).createOrUpdateContact(eq(TEST_NEW_EMAIL), eq(String.valueOf(TEST_USERID)), eq(TEST_USERNAME), eq("127.0.0.1"), any(OffsetDateTime.class));
}
use of com.faforever.api.data.domain.User in project faf-java-api by FAForever.
the class FafUserDetailsService method loadUserByUsername.
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
User user = userRepository.findOneByLoginIgnoreCase(username).orElseThrow(() -> new UsernameNotFoundException("User could not be found: " + username));
ArrayList<GrantedAuthority> authorities = new ArrayList<>();
authorities.add(LegacyAccessLevel.ROLE_USER);
if (user.getLobbyGroup() != null) {
authorities.add(user.getLobbyGroup().getAccessLevel());
}
return new FafUserDetails(user, authorities);
}
Aggregations