Browse Source

feat: [登录日志] 增加姓名

master
memorylkf 2 months ago
parent
commit
02e8b72e26
5 changed files with 33 additions and 15 deletions
  1. +12
    -0
      hxhq-api/hxhq-api-system/src/main/java/com/hxhq/system/api/domain/SysLogininfor.java
  2. +9
    -9
      hxhq-auth/src/main/java/com/hxhq/auth/service/SysLoginService.java
  3. +1
    -1
      hxhq-auth/src/main/java/com/hxhq/auth/service/SysPasswordService.java
  4. +4
    -2
      hxhq-auth/src/main/java/com/hxhq/auth/service/SysRecordLogService.java
  5. +7
    -3
      hxhq-modules/hxhq-system/src/main/resources/mapper/system/SysLogininforMapper.xml

+ 12
- 0
hxhq-api/hxhq-api-system/src/main/java/com/hxhq/system/api/domain/SysLogininfor.java View File

@ -23,6 +23,10 @@ public class SysLogininfor extends BaseEntity
@Excel(name = "用户账号")
private String userName;
/** 姓名 */
@Excel(name = "姓名")
private String nickName;
/** 状态 0成功 1失败 */
@Excel(name = "状态", readConverterExp = "0=成功,1=失败")
private String status;
@ -60,6 +64,14 @@ public class SysLogininfor extends BaseEntity
this.userName = userName;
}
public String getNickName() {
return nickName;
}
public void setNickName(String nickName) {
this.nickName = nickName;
}
public String getStatus()
{
return status;

+ 9
- 9
hxhq-auth/src/main/java/com/hxhq/auth/service/SysLoginService.java View File

@ -54,28 +54,28 @@ public class SysLoginService
// 用户名或密码为空 错误
if (StringUtils.isAnyBlank(username, password))
{
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户/密码必须填写");
recordLogService.recordLogininfor(username,null, Constants.LOGIN_FAIL, "用户/密码必须填写");
throw new ServiceException("用户/密码必须填写");
}
// 密码如果不在指定范围内 错误
if (password.length() < UserConstants.PASSWORD_MIN_LENGTH
|| password.length() > UserConstants.PASSWORD_MAX_LENGTH)
{
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户密码不在指定范围");
recordLogService.recordLogininfor(username,null, Constants.LOGIN_FAIL, "用户密码不在指定范围");
throw new ServiceException("用户密码不在指定范围");
}
// 用户名不在指定范围内 错误
if (username.length() < UserConstants.USERNAME_MIN_LENGTH
|| username.length() > UserConstants.USERNAME_MAX_LENGTH)
{
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户名不在指定范围");
recordLogService.recordLogininfor(username,null, Constants.LOGIN_FAIL, "用户名不在指定范围");
throw new ServiceException("用户名不在指定范围");
}
// IP黑名单校验
String blackStr = Convert.toStr(redisService.getCacheObject(CacheConstants.SYS_LOGIN_BLACKIPLIST));
if (IpUtils.isMatchedIp(blackStr, IpUtils.getIpAddr()))
{
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "很遗憾,访问IP已被列入系统黑名单");
recordLogService.recordLogininfor(username,null, Constants.LOGIN_FAIL, "很遗憾,访问IP已被列入系统黑名单");
throw new ServiceException("很遗憾,访问IP已被列入系统黑名单");
}
// 查询用户信息
@ -91,12 +91,12 @@ public class SysLoginService
if (UserStatus.DELETED.getCode().equals(user.getDelFlag()))
{
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "对不起,您的账号已被删除");
recordLogService.recordLogininfor(username,user.getNickName(), Constants.LOGIN_FAIL, "对不起,您的账号已被删除");
throw new ServiceException("对不起,您的账号:" + username + " 已被删除");
}
if (UserStatus.DISABLE.getCode().equals(user.getStatus()))
{
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户已停用,请联系管理员");
recordLogService.recordLogininfor(username,user.getNickName(), Constants.LOGIN_FAIL, "用户已停用,请联系管理员");
throw new ServiceException("对不起,您的账号:" + username + " 已停用");
}
passwordService.validate(user, password);
@ -117,7 +117,7 @@ public class SysLoginService
}
}
recordLogService.recordLogininfor(username, Constants.LOGIN_SUCCESS, "登录成功");
recordLogService.recordLogininfor(username,user.getNickName(), Constants.LOGIN_SUCCESS, "登录成功");
recordLoginInfo(user.getUserId());
return userInfo;
}
@ -140,7 +140,7 @@ public class SysLoginService
public void logout(String loginName)
{
recordLogService.recordLogininfor(loginName, Constants.LOGOUT, "退出成功");
recordLogService.recordLogininfor(loginName,null, Constants.LOGOUT, "退出成功");
}
/**
@ -176,6 +176,6 @@ public class SysLoginService
{
throw new ServiceException(registerResult.getMsg());
}
recordLogService.recordLogininfor(username, Constants.REGISTER, "注册成功");
recordLogService.recordLogininfor(username,null, Constants.REGISTER, "注册成功");
}
}

+ 1
- 1
hxhq-auth/src/main/java/com/hxhq/auth/service/SysPasswordService.java View File

@ -60,7 +60,7 @@ public class SysPasswordService
if (!matches(user, password))
{
retryCount = retryCount + 1;
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, String.format("密码输入错误%s次", retryCount));
recordLogService.recordLogininfor(username,user.getNickName(), Constants.LOGIN_FAIL, String.format("密码输入错误%s次", retryCount));
redisService.setCacheObject(getCacheKey(username), retryCount, lockTime, TimeUnit.MINUTES);
throw new ServiceException("用户不存在/密码错误");
}

+ 4
- 2
hxhq-auth/src/main/java/com/hxhq/auth/service/SysRecordLogService.java View File

@ -22,16 +22,18 @@ public class SysRecordLogService
/**
* 记录登录信息
*
*
* @param username 用户名
* @param nickName 姓名
* @param status 状态
* @param message 消息内容
* @return
*/
public void recordLogininfor(String username, String status, String message)
public void recordLogininfor(String username,String nickName, String status, String message)
{
SysLogininfor logininfor = new SysLogininfor();
logininfor.setUserName(username);
logininfor.setNickName(nickName);
logininfor.setIpaddr(IpUtils.getIpAddr());
logininfor.setMsg(message);
// 日志状态

+ 7
- 3
hxhq-modules/hxhq-system/src/main/resources/mapper/system/SysLogininforMapper.xml View File

@ -7,6 +7,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<resultMap type="com.hxhq.system.api.domain.SysLogininfor" id="SysLogininforResult">
<id property="infoId" column="info_id" />
<result property="userName" column="user_name" />
<result property="nickName" column="nick_name" />
<result property="status" column="status" />
<result property="ipaddr" column="ipaddr" />
<result property="msg" column="msg" />
@ -14,12 +15,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<insert id="insertLogininfor" parameterType="com.hxhq.system.api.domain.SysLogininfor">
insert into sys_logininfor (user_name, status, ipaddr, msg, access_time)
values (#{userName}, #{status}, #{ipaddr}, #{msg}, sysdate())
insert into sys_logininfor (user_name,nick_name, status, ipaddr, msg, access_time)
values (#{userName},#{nickName}, #{status}, #{ipaddr}, #{msg}, sysdate())
</insert>
<select id="selectLogininforList" parameterType="com.hxhq.system.api.domain.SysLogininfor" resultMap="SysLogininforResult">
select info_id, user_name, ipaddr, status, msg, access_time from sys_logininfor
select info_id, user_name,nick_name, ipaddr, status, msg, access_time from sys_logininfor
<where>
<if test="ipaddr != null and ipaddr != ''">
AND ipaddr like concat('%', #{ipaddr}, '%')
@ -30,6 +31,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="userName != null and userName != ''">
AND user_name like concat('%', #{userName}, '%')
</if>
<if test="nickName != null and nickName != ''">
AND nick_name like concat('%', #{nickName}, '%')
</if>
<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
AND access_time &gt;= #{params.beginTime}
</if>

Loading…
Cancel
Save