Skip to content

Commit

Permalink
Merge 11d695e into ee10c1d
Browse files Browse the repository at this point in the history
  • Loading branch information
Brutus5000 committed Sep 15, 2018
2 parents ee10c1d + 11d695e commit 2bb942f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ before_install:
install:
- git clone https://github.com/FAForever/faf-stack.git faf-stack
&& pushd faf-stack
&& git checkout 2169c0c
&& git checkout fc3551f
&& cp -r config.template config
&& popd
- docker-compose -f faf-stack/docker-compose.yml up -d faf-db
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/faforever/api/data/domain/Login.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Transient;
import java.time.OffsetDateTime;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;
Expand All @@ -28,6 +29,7 @@ public abstract class Login extends AbstractEntity implements OwnableEntity {
private Set<UserNote> userNotes;
private LobbyGroup lobbyGroup;
private String recentIpAddress;
private OffsetDateTime lastLogin;

public Login() {
this.bans = new HashSet<>(0);
Expand Down Expand Up @@ -57,6 +59,12 @@ public String getRecentIpAddress() {
return recentIpAddress;
}

@Column(name = "last_login")
@ReadPermission(expression = IsEntityOwner.EXPRESSION + " OR " + IsModerator.EXPRESSION)
public OffsetDateTime getLastLogin() {
return lastLogin;
}

@Column(name = "user_agent")
public String getUserAgent() {
return userAgent;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/faforever/api/user/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ void activate(String token, String ipAddress) {
user.setPassword(password);
user.setEmail(email);
user.setLogin(username);
user.setRecentIpAddress(ipAddress);

user = userRepository.save(user);

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/config/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ faf-api:
challonge:
key: ${CHALLONGE_KEY:}
database:
schema-version: ${DATABASE_SCHEMA_VERSION:58}
schema-version: ${DATABASE_SCHEMA_VERSION:59}
mautic:
base-url: ${MAUTIC_BASE_URL:false}
client-id: ${MAUTIC_CLIENT_ID:false}
Expand Down
4 changes: 3 additions & 1 deletion src/test/java/com/faforever/api/user/UserServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,14 @@ public void registerUsernameReserved() throws Exception {

@Test
public void activate() throws Exception {
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, "127.0.0.1");
instance.activate(TOKEN_VALUE, TEST_IP_ADDRESS);

ArgumentCaptor<User> captor = ArgumentCaptor.forClass(User.class);
verify(userRepository).save(captor.capture());
Expand All @@ -191,6 +192,7 @@ public void activate() throws Exception {
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));
}
Expand Down

0 comments on commit 2bb942f

Please sign in to comment.