test ip address
This commit is contained in:
@@ -4,6 +4,7 @@ import com.honey.honey.dto.UserDto;
|
||||
import com.honey.honey.model.UserA;
|
||||
import com.honey.honey.security.UserContext;
|
||||
import com.honey.honey.service.UserService;
|
||||
import com.honey.honey.util.IpUtils;
|
||||
import lombok.Data;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -22,9 +23,13 @@ public class UserController {
|
||||
public UserDto getCurrentUser() {
|
||||
UserA user = UserContext.get();
|
||||
|
||||
// Convert IP from byte[] to string for display
|
||||
String ipAddress = IpUtils.bytesToIp(user.getIp());
|
||||
|
||||
return UserDto.builder()
|
||||
.telegram_id(user.getTelegramId())
|
||||
.username(user.getTelegramName())
|
||||
.ip(ipAddress)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -12,5 +12,6 @@ import lombok.NoArgsConstructor;
|
||||
public class UserDto {
|
||||
private Long telegram_id;
|
||||
private String username;
|
||||
private String ip;
|
||||
}
|
||||
|
||||
|
||||
@@ -56,8 +56,8 @@ public class UserService {
|
||||
// Build screen_name from first_name and last_name
|
||||
String screenName = buildScreenName(firstName, lastName);
|
||||
|
||||
// device_code should be language_code from initData
|
||||
String deviceCode = languageCode != null ? languageCode : "XX";
|
||||
// device_code should be language_code from initData (uppercase)
|
||||
String deviceCode = languageCode != null ? languageCode.toUpperCase() : "XX";
|
||||
|
||||
// Get client IP and convert to bytes
|
||||
String clientIp = IpUtils.getClientIp(request);
|
||||
@@ -94,7 +94,7 @@ public class UserService {
|
||||
userA.setTelegramName(username != null ? username : "-");
|
||||
userA.setIsPremium(isPremium != null && isPremium ? 1 : 0);
|
||||
userA.setCountryCode(countryCode);
|
||||
userA.setDeviceCode(deviceCode != null ? deviceCode : "XX");
|
||||
userA.setDeviceCode(deviceCode != null ? deviceCode.toUpperCase() : "XX");
|
||||
userA.setIp(ipBytes);
|
||||
userA.setDateLogin((int) nowSeconds);
|
||||
// language_code is NOT updated here - it's updated via separate endpoint when user changes language
|
||||
@@ -130,9 +130,9 @@ public class UserService {
|
||||
.telegramId(telegramId)
|
||||
.telegramName(username != null ? username : "-")
|
||||
.isPremium(isPremium != null && isPremium ? 1 : 0)
|
||||
.languageCode(languageCode != null ? languageCode : "XX")
|
||||
.languageCode(languageCode != null ? languageCode.toUpperCase() : "XX")
|
||||
.countryCode(countryCode)
|
||||
.deviceCode(deviceCode != null ? deviceCode : "XX")
|
||||
.deviceCode(deviceCode != null ? deviceCode.toUpperCase() : "XX")
|
||||
.ip(ipBytes)
|
||||
.dateReg((int) nowSeconds)
|
||||
.dateLogin((int) nowSeconds)
|
||||
|
||||
Reference in New Issue
Block a user