refactor: 修改用户表字段,修改IP地址格式
This commit is contained in:
parent
4462de2530
commit
8d6ad3b386
|
@ -90,8 +90,13 @@ public class IpUtil {
|
||||||
*/
|
*/
|
||||||
public static IpEntity getCurrentUserIpAddress() {
|
public static IpEntity getCurrentUserIpAddress() {
|
||||||
ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||||
|
|
||||||
|
// 判断IP地址归属地
|
||||||
String remoteAddr = requestAttributes != null ? getIpAddr(requestAttributes.getRequest()) : "0:0:0:0:0:0:0:1";
|
String remoteAddr = requestAttributes != null ? getIpAddr(requestAttributes.getRequest()) : "0:0:0:0:0:0:0:1";
|
||||||
String ipRegion = IpUtil.getIpRegion(remoteAddr);
|
String ipRegion = IpUtil.getIpRegion(remoteAddr);
|
||||||
|
|
||||||
|
// 转成环回地址
|
||||||
|
remoteAddr = remoteAddr.equals("0:0:0:0:0:0:0:1") ? "127.0.0.1" : remoteAddr;
|
||||||
return IpEntity.builder().ipAddr(remoteAddr).ipRegion(ipRegion).build();
|
return IpEntity.builder().ipAddr(remoteAddr).ipRegion(ipRegion).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,6 @@ public class LoginDto {
|
||||||
@NotNull(message = "密码不能为空")
|
@NotNull(message = "密码不能为空")
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
|
|
||||||
@Schema(name = "emailCode", title = "邮箱验证码")
|
@Schema(name = "emailCode", title = "邮箱验证码")
|
||||||
@NotBlank(message = "邮箱验证码不能为空")
|
@NotBlank(message = "邮箱验证码不能为空")
|
||||||
@NotNull(message = "邮箱验证码不能为空")
|
@NotNull(message = "邮箱验证码不能为空")
|
||||||
|
|
|
@ -46,14 +46,14 @@ public class AdminUser extends BaseEntity {
|
||||||
@Schema(name = "summary", title = "个人描述")
|
@Schema(name = "summary", title = "个人描述")
|
||||||
private String summary;
|
private String summary;
|
||||||
|
|
||||||
@Schema(name = "lastLoginIp", title = "最后登录IP")
|
@Schema(name = "ipAddress", title = "登录Ip")
|
||||||
private String lastLoginIp;
|
private String ipAddress;
|
||||||
|
|
||||||
@Schema(name = "lastLoginIpAddress", title = "最后登录ip归属地")
|
@Schema(name = "ipRegion", title = "登录Ip归属地")
|
||||||
private String lastLoginIpAddress;
|
private String ipRegion;
|
||||||
|
|
||||||
@Schema(name = "status", title = "状态", description = "1:禁用 0:正常")
|
@Schema(name = "status", title = "状态", description = "1:禁用 0:正常")
|
||||||
private Boolean status;
|
private Boolean status;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,11 +46,11 @@ public class AdminUserAndDept extends BaseEntity {
|
||||||
@Schema(name = "summary", title = "个人描述")
|
@Schema(name = "summary", title = "个人描述")
|
||||||
private String summary;
|
private String summary;
|
||||||
|
|
||||||
@Schema(name = "lastLoginIp", title = "最后登录IP")
|
@Schema(name = "ipAddress", title = "登录Ip")
|
||||||
private String lastLoginIp;
|
private String ipAddress;
|
||||||
|
|
||||||
@Schema(name = "lastLoginIpAddress", title = "最后登录ip归属地")
|
@Schema(name = "ipRegion", title = "登录Ip归属地")
|
||||||
private String lastLoginIpAddress;
|
private String ipRegion;
|
||||||
|
|
||||||
@Schema(name = "status", title = "状态", description = "1:禁用 0:正常")
|
@Schema(name = "status", title = "状态", description = "1:禁用 0:正常")
|
||||||
private Boolean status;
|
private Boolean status;
|
||||||
|
|
|
@ -35,11 +35,11 @@ public class AdminUserVo extends BaseVo {
|
||||||
@Schema(name = "summary", title = "个人描述")
|
@Schema(name = "summary", title = "个人描述")
|
||||||
private String summary;
|
private String summary;
|
||||||
|
|
||||||
@Schema(name = "lastLoginIp", title = "最后登录IP")
|
@Schema(name = "ipAddress", title = "登录Ip")
|
||||||
private String lastLoginIp;
|
private String ipAddress;
|
||||||
|
|
||||||
@Schema(name = "lastLoginIpAddress", title = "最后登录ip归属地")
|
@Schema(name = "ipRegion", title = "登录Ip归属地")
|
||||||
private String lastLoginIpAddress;
|
private String ipRegion;
|
||||||
|
|
||||||
@Schema(name = "deptId", title = "部门")
|
@Schema(name = "deptId", title = "部门")
|
||||||
@JsonFormat(shape = JsonFormat.Shape.STRING)
|
@JsonFormat(shape = JsonFormat.Shape.STRING)
|
||||||
|
|
|
@ -41,11 +41,11 @@ public class LoginVo extends BaseVo {
|
||||||
@Schema(name = "personDescription", title = "个人描述")
|
@Schema(name = "personDescription", title = "个人描述")
|
||||||
private String personDescription;
|
private String personDescription;
|
||||||
|
|
||||||
@Schema(name = "lastLoginIp", title = "最后登录IP")
|
@Schema(name = "ipAddress", title = "登录Ip")
|
||||||
private String lastLoginIp;
|
private String ipAddress;
|
||||||
|
|
||||||
@Schema(name = "lastLoginIpAddress", title = "最后登录ip地址")
|
@Schema(name = "ipRegion", title = "登录Ip归属地")
|
||||||
private String lastLoginIpAddress;
|
private String ipRegion;
|
||||||
|
|
||||||
@Schema(name = "status", title = "1:禁用 0:正常")
|
@Schema(name = "status", title = "1:禁用 0:正常")
|
||||||
private Boolean status;
|
private Boolean status;
|
||||||
|
|
|
@ -13,8 +13,8 @@ import lombok.NoArgsConstructor;
|
||||||
@Schema(description = "验证码响应结果实体类")
|
@Schema(description = "验证码响应结果实体类")
|
||||||
public class ValidateCodeVo {
|
public class ValidateCodeVo {
|
||||||
@Schema(description = "验证码key")
|
@Schema(description = "验证码key")
|
||||||
private String codeKey; // 验证码的key
|
private String codeKey;
|
||||||
|
|
||||||
@Schema(description = "验证码value")
|
@Schema(description = "验证码value")
|
||||||
private String codeValue; // 图片验证码对应的字符串数据
|
private String codeValue;
|
||||||
}
|
}
|
1692
data/auth_admin.sql
1692
data/auth_admin.sql
File diff suppressed because it is too large
Load Diff
|
@ -66,20 +66,12 @@ public class UserFactory {
|
||||||
// 更新用户登录信息
|
// 更新用户登录信息
|
||||||
setUpdateUser(userId, ipAddr, ipRegion);
|
setUpdateUser(userId, ipAddr, ipRegion);
|
||||||
|
|
||||||
|
// 将用户登录保存在用户登录日志表中
|
||||||
|
userLoginLogMapper.insert(setUserLoginLog(user, token, ipAddr, ipRegion));
|
||||||
|
|
||||||
// 设置用户返回信息
|
// 设置用户返回信息
|
||||||
LoginVo loginVo = setLoginVo(user, token, readMeDay, ipAddr, ipRegion);
|
LoginVo loginVo = setLoginVo(user, token, readMeDay, ipAddr, ipRegion);
|
||||||
|
|
||||||
// 将用户登录保存在用户登录日志表中
|
|
||||||
UserLoginLog userLoginLog = new UserLoginLog();
|
|
||||||
userLoginLog.setUsername(user.getUsername());
|
|
||||||
userLoginLog.setUserId(userId);
|
|
||||||
userLoginLog.setIpAddress(ipAddr);
|
|
||||||
userLoginLog.setIpRegion(ipRegion);
|
|
||||||
userLoginLog.setToken(token);
|
|
||||||
userLoginLog.setType("login");
|
|
||||||
setUserLoginLog(userLoginLog);
|
|
||||||
userLoginLogMapper.insert(userLoginLog);
|
|
||||||
|
|
||||||
// 将信息保存在Redis中
|
// 将信息保存在Redis中
|
||||||
redisTemplate.opsForValue().set(RedisUserConstant.getAdminLoginInfoPrefix(email), loginVo, readMeDay, TimeUnit.DAYS);
|
redisTemplate.opsForValue().set(RedisUserConstant.getAdminLoginInfoPrefix(email), loginVo, readMeDay, TimeUnit.DAYS);
|
||||||
|
|
||||||
|
@ -123,8 +115,8 @@ public class UserFactory {
|
||||||
loginVo.setAvatar(avatar);
|
loginVo.setAvatar(avatar);
|
||||||
loginVo.setToken(token);
|
loginVo.setToken(token);
|
||||||
loginVo.setRefreshToken(token);
|
loginVo.setRefreshToken(token);
|
||||||
loginVo.setLastLoginIp(ipAddr);
|
loginVo.setIpAddress(ipAddr);
|
||||||
loginVo.setLastLoginIpAddress(ipRegion);
|
loginVo.setIpRegion(ipRegion);
|
||||||
loginVo.setRoles(roles);
|
loginVo.setRoles(roles);
|
||||||
loginVo.setPermissions(permissions);
|
loginVo.setPermissions(permissions);
|
||||||
loginVo.setUpdateUser(userId);
|
loginVo.setUpdateUser(userId);
|
||||||
|
@ -142,20 +134,32 @@ public class UserFactory {
|
||||||
// 设置用户IP地址,并更新用户信息
|
// 设置用户IP地址,并更新用户信息
|
||||||
AdminUser updateUser = new AdminUser();
|
AdminUser updateUser = new AdminUser();
|
||||||
updateUser.setId(userId);
|
updateUser.setId(userId);
|
||||||
updateUser.setLastLoginIp(ipAddr);
|
updateUser.setIpAddress(ipAddr);
|
||||||
updateUser.setLastLoginIpAddress(ipRegion);
|
updateUser.setIpRegion(ipRegion);
|
||||||
userMapper.updateById(updateUser);
|
userMapper.updateById(updateUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* * 设置用户登录日志内容
|
* * 设置用户登录日志内容
|
||||||
*
|
|
||||||
* @param userLoginLog 用户登录日志
|
|
||||||
*/
|
*/
|
||||||
public void setUserLoginLog(UserLoginLog userLoginLog) {
|
public UserLoginLog setUserLoginLog(AdminUser user, String token, String ipAddr, String ipRegion) {
|
||||||
|
Long userId = user.getId();
|
||||||
|
|
||||||
|
UserLoginLog userLoginLog = new UserLoginLog();
|
||||||
|
userLoginLog.setUsername(user.getUsername());
|
||||||
|
userLoginLog.setUserId(userId);
|
||||||
|
userLoginLog.setIpAddress(ipAddr);
|
||||||
|
userLoginLog.setIpRegion(ipRegion);
|
||||||
|
userLoginLog.setToken(token);
|
||||||
|
userLoginLog.setType("login");
|
||||||
|
userLoginLog.setCreateUser(userId);
|
||||||
|
userLoginLog.setUpdateUser(userId);
|
||||||
|
userLoginLog.setCreateTime(LocalDateTime.now());
|
||||||
|
userLoginLog.setUpdateTime(LocalDateTime.now());
|
||||||
|
|
||||||
// 当前请求request
|
// 当前请求request
|
||||||
ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||||
if (requestAttributes == null) return;
|
if (requestAttributes == null) return userLoginLog;
|
||||||
|
|
||||||
HttpServletRequest request = requestAttributes.getRequest();
|
HttpServletRequest request = requestAttributes.getRequest();
|
||||||
|
|
||||||
|
@ -178,5 +182,7 @@ public class UserFactory {
|
||||||
// 获取Sec-CH-UA-Platform
|
// 获取Sec-CH-UA-Platform
|
||||||
String secCHUAPlatform = request.getHeader("Sec-CH-UA-Platform");
|
String secCHUAPlatform = request.getHeader("Sec-CH-UA-Platform");
|
||||||
userLoginLog.setSecChUaPlatform(secCHUAPlatform);
|
userLoginLog.setSecChUaPlatform(secCHUAPlatform);
|
||||||
|
|
||||||
|
return userLoginLog;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -220,8 +220,8 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, AdminUser> implemen
|
||||||
UserLoginLog userLoginLog = new UserLoginLog();
|
UserLoginLog userLoginLog = new UserLoginLog();
|
||||||
BeanUtils.copyProperties(adminUser, userLoginLog);
|
BeanUtils.copyProperties(adminUser, userLoginLog);
|
||||||
userLoginLog.setUserId(adminUser.getId());
|
userLoginLog.setUserId(adminUser.getId());
|
||||||
userLoginLog.setIpAddress(adminUser.getLastLoginIp());
|
userLoginLog.setIpAddress(adminUser.getIpAddress());
|
||||||
userLoginLog.setIpRegion(adminUser.getLastLoginIpAddress());
|
userLoginLog.setIpRegion(adminUser.getIpRegion());
|
||||||
userLoginLog.setToken(null);
|
userLoginLog.setToken(null);
|
||||||
userLoginLog.setType("forcedOffline");
|
userLoginLog.setType("forcedOffline");
|
||||||
userLoginLogMapper.insert(userLoginLog);
|
userLoginLogMapper.insert(userLoginLog);
|
||||||
|
|
|
@ -13,8 +13,8 @@
|
||||||
<result column="avatar" property="avatar"/>
|
<result column="avatar" property="avatar"/>
|
||||||
<result column="sex" property="sex"/>
|
<result column="sex" property="sex"/>
|
||||||
<result column="summary" property="summary"/>
|
<result column="summary" property="summary"/>
|
||||||
<result column="last_login_ip" property="lastLoginIp"/>
|
<result column="ip_address" property="ipAddress"/>
|
||||||
<result column="last_login_ip_address" property="lastLoginIpAddress"/>
|
<result column="ip_region" property="ipRegion"/>
|
||||||
<result column="status" property="status"/>
|
<result column="status" property="status"/>
|
||||||
<result column="create_user" property="createUser"/>
|
<result column="create_user" property="createUser"/>
|
||||||
<result column="create_time" property="createTime"/>
|
<result column="create_time" property="createTime"/>
|
||||||
|
@ -25,7 +25,7 @@
|
||||||
|
|
||||||
<!-- 通用查询结果列 -->
|
<!-- 通用查询结果列 -->
|
||||||
<sql id="Base_Column_List">
|
<sql id="Base_Column_List">
|
||||||
id, username, nick_name, email, phone, password, avatar, sex, summary, last_login_ip, last_login_ip_address, status, create_user, create_time, update_time, update_user, is_deleted
|
id, username, nick_name, email, phone, password, avatar, sex, summary, ip_address, ip_region, status, create_user, create_time, update_time, update_user, is_deleted
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
<!-- 分页查询用户信息内容 -->
|
<!-- 分页查询用户信息内容 -->
|
||||||
|
|
Loading…
Reference in New Issue