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