Search in sources :

Example 26 with User

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");
}
Also used : User(com.faforever.api.data.domain.User) Test(org.junit.Test)

Example 27 with User

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));
}
Also used : User(com.faforever.api.data.domain.User) OffsetDateTime(java.time.OffsetDateTime) GlobalRating(com.faforever.api.data.domain.GlobalRating) Ladder1v1Rating(com.faforever.api.data.domain.Ladder1v1Rating) Test(org.junit.Test)

Example 28 with User

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);
}
Also used : UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) User(com.faforever.api.data.domain.User) GrantedAuthority(org.springframework.security.core.GrantedAuthority) ArrayList(java.util.ArrayList)

Aggregations

User (com.faforever.api.data.domain.User)28 Test (org.junit.Test)22 OffsetDateTime (java.time.OffsetDateTime)4 AbstractIntegrationTest (com.faforever.api.AbstractIntegrationTest)3 ApiException (com.faforever.api.error.ApiException)3 Error (com.faforever.api.error.Error)3 SteamLinkResult (com.faforever.api.user.UserService.SteamLinkResult)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 Map (java.util.Map)3 SneakyThrows (lombok.SneakyThrows)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 WithAnonymousUser (org.springframework.security.test.context.support.WithAnonymousUser)3 GlobalRating (com.faforever.api.data.domain.GlobalRating)2 Ladder1v1Rating (com.faforever.api.data.domain.Ladder1v1Rating)2 ArrayList (java.util.ArrayList)2 HttpHeaders (org.springframework.http.HttpHeaders)2 WithUserDetails (org.springframework.security.test.context.support.WithUserDetails)2 FafApiProperties (com.faforever.api.config.FafApiProperties)1 NameRecord (com.faforever.api.data.domain.NameRecord)1 Before (org.junit.Before)1