用户角色消失问题

This commit is contained in:
dinggang 2022-12-02 16:50:29 +08:00
parent 4789a3cb60
commit 5c3f32f313
2 changed files with 17 additions and 9 deletions

View File

@ -24,7 +24,9 @@ import io.renren.modules.security.service.SysUserTokenService;
import io.renren.modules.security.user.SecurityUser; import io.renren.modules.security.user.SecurityUser;
import io.renren.modules.security.user.UserDetail; import io.renren.modules.security.user.UserDetail;
import io.renren.modules.sys.dao.SysDeptDao; import io.renren.modules.sys.dao.SysDeptDao;
import io.renren.modules.sys.dao.SysUserDao;
import io.renren.modules.sys.dto.SysUserDTO; import io.renren.modules.sys.dto.SysUserDTO;
import io.renren.modules.sys.entity.SysUserEntity;
import io.renren.modules.sys.enums.UserStatusEnum; import io.renren.modules.sys.enums.UserStatusEnum;
import io.renren.modules.sys.service.SysUserService; import io.renren.modules.sys.service.SysUserService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
@ -35,6 +37,7 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.subject.Subject; import org.apache.shiro.subject.Subject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
@ -83,6 +86,10 @@ public class LoginController {
@Value("${system.resumeLogonTime}") @Value("${system.resumeLogonTime}")
private Integer resumeLogonTime; private Integer resumeLogonTime;
@Autowired
private SysUserDao sysUserDao;
@GetMapping("captcha") @GetMapping("captcha")
@ApiOperation(value = "验证码", produces = "application/octet-stream") @ApiOperation(value = "验证码", produces = "application/octet-stream")
@ApiImplicitParam(paramType = "query", dataType = "string", name = "uuid", required = true) @ApiImplicitParam(paramType = "query", dataType = "string", name = "uuid", required = true)
@ -133,6 +140,9 @@ public class LoginController {
throw new RenException(ErrorCode.ACCOUNT_PASSWORD_ERROR); throw new RenException(ErrorCode.ACCOUNT_PASSWORD_ERROR);
} }
SysUserEntity userEntity = new SysUserEntity();
BeanUtils.copyProperties(user, userEntity);
//账号停用 //账号停用
if (user.getStatus() == UserStatusEnum.DISABLE.value()) { if (user.getStatus() == UserStatusEnum.DISABLE.value()) {
log.setStatus(LoginStatusEnum.LOCK.value()); log.setStatus(LoginStatusEnum.LOCK.value());
@ -147,7 +157,6 @@ public class LoginController {
if (user.getStatus() == UserStatusEnum.LOCKED.value()) { if (user.getStatus() == UserStatusEnum.LOCKED.value()) {
Date now = DateUtil.date(); Date now = DateUtil.date();
QueryWrapper<SysLogLoginEntity> queryWrapper = new QueryWrapper<>(); QueryWrapper<SysLogLoginEntity> queryWrapper = new QueryWrapper<>();
//queryWrapper.eq("creator_name", params.get("username")).orderByDesc("create_date").last("LIMIT 1");
queryWrapper.eq("creator_name", userName).orderByDesc("create_date").last("LIMIT 1"); queryWrapper.eq("creator_name", userName).orderByDesc("create_date").last("LIMIT 1");
SysLogLoginEntity loginEntity = logLoginDao.selectOne(queryWrapper); SysLogLoginEntity loginEntity = logLoginDao.selectOne(queryWrapper);
Date lastLoginDate = loginEntity.getCreateDate(); Date lastLoginDate = loginEntity.getCreateDate();
@ -167,13 +176,13 @@ public class LoginController {
//2022-11-11 新增限制用户登录次数超过后账户锁定状态变为2 //2022-11-11 新增限制用户登录次数超过后账户锁定状态变为2
if (user.getFrequency() < maxErrorTimes) { if (user.getFrequency() < maxErrorTimes) {
user.setFrequency(user.getFrequency() + 1); userEntity.setFrequency(userEntity.getFrequency() + 1);
if (user.getFrequency() == maxErrorTimes) { if (user.getFrequency() == maxErrorTimes) {
user.setStatus(2); userEntity.setStatus(2);
sysUserService.update(user); sysUserDao.updateById(userEntity);
throw new RenException("账号或密码连续输入错误" + maxErrorTimes + "次,账号已锁定。"); throw new RenException("账号或密码连续输入错误" + maxErrorTimes + "次,账号已锁定。");
} else { } else {
sysUserService.update(user); sysUserDao.updateById(userEntity);
throw new RenException("账号或密码输入错误,当前还可输入" + (maxErrorTimes - user.getFrequency()) + "次。"); throw new RenException("账号或密码输入错误,当前还可输入" + (maxErrorTimes - user.getFrequency()) + "次。");
} }
} }
@ -188,9 +197,9 @@ public class LoginController {
sysLogLoginService.save(log); sysLogLoginService.save(log);
//将用户状态改为正常,登录失败次数置为0 //将用户状态改为正常,登录失败次数置为0
if (user.getStatus() != 1 || user.getFrequency() != 0) { if (user.getStatus() != 1 || user.getFrequency() != 0) {
user.setStatus(1); userEntity.setStatus(1);
user.setFrequency(0); userEntity.setFrequency(0);
sysUserService.update(user); sysUserDao.updateById(userEntity);
} }
Result<Map> token = sysUserTokenService.createToken(user.getId()); Result<Map> token = sysUserTokenService.createToken(user.getId());

View File

@ -22,7 +22,6 @@ import io.renren.modules.sys.service.SysDeptService;
import io.renren.modules.sys.service.SysRoleUserService; import io.renren.modules.sys.service.SysRoleUserService;
import io.renren.modules.sys.service.SysUserPostService; import io.renren.modules.sys.service.SysUserPostService;
import io.renren.modules.sys.service.SysUserService; import io.renren.modules.sys.service.SysUserService;
import io.renren.websocket.WebSocketServer;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiImplicitParams;