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