记录用户注册时的UserAgent

This commit is contained in:
liuchengqian 2022-05-19 10:13:26 +08:00
parent de4ed40ea3
commit 329bc490f2
4 changed files with 45 additions and 5 deletions

View File

@ -21,6 +21,7 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
@ -73,7 +74,7 @@ public class SysUserController {
} }
@RequestMapping(value = "/add", method = RequestMethod.POST) @RequestMapping(value = "/add", method = RequestMethod.POST)
public String addUser(@Validated({SysUserQoInsert.class}) @RequestBody SysUserQo userQo, BindingResult bindingResult) { public String addUser(@Validated({SysUserQoInsert.class}) @RequestBody SysUserQo userQo, BindingResult bindingResult, HttpServletRequest servletRequest) {
// 获取区域信息 // 获取区域信息
Locale locale = LocaleContextHolder.getLocale(); Locale locale = LocaleContextHolder.getLocale();
// 验证数据合法性 // 验证数据合法性
@ -85,7 +86,7 @@ public class SysUserController {
return outputEncapsulationObject(PromptMessageEnum.PARAM_ILLEGAL, "该账号已经注册,请勿重复注册", locale); return outputEncapsulationObject(PromptMessageEnum.PARAM_ILLEGAL, "该账号已经注册,请勿重复注册", locale);
} }
// 添加新用户 // 添加新用户
return sysUserService.addUser(userQo); return sysUserService.addUser(userQo, servletRequest);
} }
/** /**

View File

@ -98,6 +98,12 @@ public class SysUserEntity implements Serializable {
*/ */
private String loginLastTime; private String loginLastTime;
/**
* 注册时的UA
*/
@Column(columnDefinition = "varchar(1024)")
private String userAgent;
public SysUserEntity() { public SysUserEntity() {
} }
@ -261,8 +267,38 @@ public class SysUserEntity implements Serializable {
this.loginLastTime = loginLastTime; this.loginLastTime = loginLastTime;
} }
public String getUserAgent() {
return userAgent;
}
public void setUserAgent(String userAgent) {
this.userAgent = userAgent;
}
@Override @Override
public String toString() { public String toString() {
return "SysUserEntity{" + "id=" + id + ", userName='" + userName + '\'' + ", reallyName='" + reallyName + '\'' + ", password='" + password + '\'' + ", salt='" + salt + '\'' + ", telephone='" + telephone + '\'' + ", countyCode='" + countyCode + '\'' + ", signature='" + signature + '\'' + ", activeFlag=" + activeFlag + ", statusCode=" + statusCode + ", addTime='" + addTime + '\'' + ", lastEntryTime=" + lastEntryTime + ", deleteFlag=" + deleteFlag + ", lastEntryIp='" + lastEntryIp + '\'' + ", dayNum=" + dayNum + ", overTime='" + overTime + '\'' + ", accountType='" + accountType + '\'' + ", countyName='" + countyName + '\'' + ", loginNum=" + loginNum + ", loginLastTime='" + loginLastTime + '\'' + '}'; return "SysUserEntity{" +
"id=" + id +
", userName='" + userName + '\'' +
", reallyName='" + reallyName + '\'' +
", password='" + password + '\'' +
", salt='" + salt + '\'' +
", telephone='" + telephone + '\'' +
", countyCode='" + countyCode + '\'' +
", signature='" + signature + '\'' +
", activeFlag=" + activeFlag +
", statusCode=" + statusCode +
", addTime='" + addTime + '\'' +
", lastEntryTime=" + lastEntryTime +
", deleteFlag=" + deleteFlag +
", lastEntryIp='" + lastEntryIp + '\'' +
", dayNum=" + dayNum +
", overTime='" + overTime + '\'' +
", accountType='" + accountType + '\'' +
", countyName='" + countyName + '\'' +
", loginNum=" + loginNum +
", loginLastTime='" + loginLastTime + '\'' +
", userAgent='" + userAgent + '\'' +
'}';
} }
} }

View File

@ -4,6 +4,7 @@ import com.xkrs.model.entity.SysUserEntity;
import com.xkrs.model.qo.SysUserQo; import com.xkrs.model.qo.SysUserQo;
import com.xkrs.model.vo.SysUserVo; import com.xkrs.model.vo.SysUserVo;
import javax.servlet.http.HttpServletRequest;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -28,7 +29,7 @@ public interface SysUserService {
* @param sysUserQo * @param sysUserQo
* @return * @return
*/ */
String addUser(SysUserQo sysUserQo); String addUser(SysUserQo sysUserQo, HttpServletRequest servletRequest);
/** /**
* 删除系统用户 * 删除系统用户

View File

@ -15,6 +15,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
@ -78,12 +79,13 @@ public class SysUserServiceImpl implements SysUserService {
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public String addUser(SysUserQo sysUserQo) { public String addUser(SysUserQo sysUserQo, HttpServletRequest servletRequest) {
// 获取区域信息 // 获取区域信息
Locale locale = LocaleContextHolder.getLocale(); Locale locale = LocaleContextHolder.getLocale();
String salt = KeyGenerators.string().generateKey(); String salt = KeyGenerators.string().generateKey();
SysUserEntity sysUserEntity = new SysUserEntity(); SysUserEntity sysUserEntity = new SysUserEntity();
sysUserEntity.setUserName(sysUserQo.getUserName()); sysUserEntity.setUserName(sysUserQo.getUserName());
sysUserEntity.setUserAgent(servletRequest.getHeader("user-agent"));
String o = (String) redisService.get(sysUserQo.getUserName()); String o = (String) redisService.get(sysUserQo.getUserName());
if ("".equals(o) || o == null) { if ("".equals(o) || o == null) {
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "请先发送验证码!", locale); return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "请先发送验证码!", locale);