-
Notifications
You must be signed in to change notification settings - Fork 5
#23 Add: Feature: Track User Account Creation and Last Login Timestamps #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -4,7 +4,9 @@ | |||||
| import jakarta.persistence.*; | ||||||
| import lombok.Getter; | ||||||
| import lombok.Setter; | ||||||
| import org.hibernate.annotations.CreationTimestamp; | ||||||
|
|
||||||
| import java.time.Instant; | ||||||
| import java.util.UUID; | ||||||
|
|
||||||
| @Entity | ||||||
|
|
@@ -37,5 +39,12 @@ public class User { | |||||
| @Enumerated(EnumType.STRING) | ||||||
| private Role role; | ||||||
|
|
||||||
| @CreationTimestamp | ||||||
| @Column(name = "created_at", nullable = false, updatable = false) | ||||||
| private Instant createdAt; | ||||||
|
|
||||||
| @Column(name = "last_login_at", nullable = false) | ||||||
|
||||||
| @Column(name = "last_login_at", nullable = false) | |
| @Column(name = "last_login_at", nullable = true) |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2,7 +2,6 @@ | |||||
|
|
||||||
|
|
||||||
| import com.fredmaina.chatapp.Auth.Dtos.AuthResponse; | ||||||
| import com.fredmaina.chatapp.Auth.Dtos.GoogleOAuthRequest; | ||||||
| import com.fredmaina.chatapp.Auth.Dtos.LoginRequest; | ||||||
| import com.fredmaina.chatapp.Auth.Dtos.SignUpRequest; | ||||||
| import com.fredmaina.chatapp.Auth.Models.Role; | ||||||
|
|
@@ -15,14 +14,13 @@ | |||||
| import org.springframework.cache.annotation.Cacheable; | ||||||
| import org.springframework.dao.DataIntegrityViolationException; | ||||||
| import org.springframework.http.*; | ||||||
| import org.springframework.security.authentication.AuthenticationManager; | ||||||
| import org.springframework.security.crypto.password.PasswordEncoder; | ||||||
| import org.springframework.stereotype.Service; | ||||||
| import org.springframework.util.LinkedMultiValueMap; | ||||||
| import org.springframework.util.MultiValueMap; | ||||||
| import org.springframework.web.client.RestTemplate; | ||||||
|
|
||||||
| import java.util.HashMap; | ||||||
| import java.time.Instant; | ||||||
| import java.util.Map; | ||||||
| import java.util.Optional; | ||||||
|
|
||||||
|
|
@@ -37,7 +35,7 @@ public class AuthService { | |||||
| final RestTemplate restTemplate; | ||||||
|
|
||||||
| @Autowired | ||||||
| AuthService (UserRepository userRepository, PasswordEncoder passwordEncoder, GoogleOAuthProperties googleOAuthProperties,RestTemplate restTemplate,JWTService jwtService) { | ||||||
| AuthService(UserRepository userRepository, PasswordEncoder passwordEncoder, GoogleOAuthProperties googleOAuthProperties, RestTemplate restTemplate, JWTService jwtService) { | ||||||
| this.userRepository = userRepository; | ||||||
| this.passwordEncoder = passwordEncoder; | ||||||
| this.googleOAuthProperties = googleOAuthProperties; | ||||||
|
|
@@ -133,6 +131,10 @@ public AuthResponse login(LoginRequest loginRequest) { | |||||
| authResponse.setMessage("Login successful"); | ||||||
| authResponse.setUser(user); | ||||||
| authResponse.setToken(token); | ||||||
|
|
||||||
| user.setLastLoginAt(loginRequest.getLastLoginAt()); | ||||||
|
||||||
| user.setLastLoginAt(loginRequest.getLastLoginAt()); | |
| user.setLastLoginAt(Instant.now()); |
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new lastLoginAt timestamp functionality lacks test coverage. Consider adding test cases to verify:
- That
lastLoginAtis correctly set when a user logs in successfully - That
lastLoginAtis persisted to the database (verifyuserRepository.save()is called after setting the timestamp)
The existing test testLogin_success() should be updated to verify this behavior.
Copilot
AI
Dec 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lastLoginAt timestamp functionality in the OAuth flow lacks test coverage. Consider adding test cases to verify that lastLoginAt is correctly set and persisted during OAuth login.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,2 @@ | ||||||
| ALTER TABLE users ADD COLUMN created_at TIMESTAMP WITH TIME ZONE NOT NULL; | ||||||
|
||||||
| ALTER TABLE users ADD COLUMN created_at TIMESTAMP WITH TIME ZONE NOT NULL; | |
| ALTER TABLE users ADD COLUMN created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
lastLoginAtfield should not be included in theLoginRequestDTO. This is a security and design issue because:handleGoogleOAuthmethod correctly setslastLoginAtserver-side usingInstant.now()(line 207 of AuthService)Remove this field entirely from
LoginRequest. The server should set the timestamp in thelogin()method usingInstant.now().