This commit is contained in:
ls
2024-12-02 13:49:01 +08:00
parent 51a27be4a1
commit aff2f9008e
5 changed files with 66 additions and 72 deletions

View File

@@ -14,9 +14,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CacheConstant;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.constant.SymbolConstant;
import org.jeecg.common.constant.*;
import org.jeecg.common.constant.enums.DySmsEnum;
import org.jeecg.common.system.util.JwtUtil;
import org.jeecg.common.system.vo.LoginUser;
@@ -24,9 +22,7 @@ import org.jeecg.common.util.*;
import org.jeecg.common.util.encryption.EncryptedString;
import org.jeecg.config.JeecgBaseConfig;
import org.jeecg.modules.base.service.BaseCommonService;
import org.jeecg.modules.system.entity.SysDepart;
import org.jeecg.modules.system.entity.SysRoleIndex;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.entity.*;
import org.jeecg.modules.system.model.SysLoginModel;
import org.jeecg.modules.system.service.*;
import org.jeecg.modules.system.service.impl.SysBaseApiImpl;
@@ -46,25 +42,25 @@ import java.util.*;
@Tag(name = "用户登录")
@Slf4j
public class LoginController {
private final String BASE_CHECK_CODES = "qwertyuiplkjhgfdsazxcvbnmQWERTYUPLKJHGFDSAZXCVBNM1234567890";
private final String BASE_CHECK_CODES = "qwertyuiplkjhgfdsazxcvbnmQWERTYUPLKJHGFDSAZXCVBNM1234567890";
@Autowired
private ISysUserService sysUserService;
private ISysUserService sysUserService;
@Autowired
private ISysPermissionService sysPermissionService;
private ISysPermissionService sysPermissionService;
@Autowired
private SysBaseApiImpl sysBaseApi;
private SysBaseApiImpl sysBaseApi;
@Autowired
private ISysLogService logService;
private ISysLogService logService;
@Autowired
private RedisUtil redisUtil;
private RedisUtil redisUtil;
@Autowired
private ISysDepartService sysDepartService;
private ISysDepartService sysDepartService;
@Autowired
private ISysDictService sysDictService;
private ISysDictService sysDictService;
@Resource
private BaseCommonService baseCommonService;
private BaseCommonService baseCommonService;
@Autowired
private JeecgBaseConfig jeecgBaseConfig;
private JeecgBaseConfig jeecgBaseConfig;
@Operation(summary = "登录接口")
@RequestMapping(value = "/login", method = RequestMethod.POST)
@@ -78,24 +74,25 @@ public class LoginController {
}
// step.1 验证码check
// String captcha = sysLoginModel.getCaptcha();
// if(captcha==null){
// result.error500("验证码无效");
// return result;
// }
// String lowerCaseCaptcha = captcha.toLowerCase();
// // 加入密钥作为混淆,避免简单的拼接,被外部利用,用户自定义该密钥即可
// String origin = lowerCaseCaptcha+sysLoginModel.getCheckKey()+jeecgBaseConfig.getSignatureSecret();
// String realKey = Md5Util.md5Encode(origin, "utf-8");
// Object checkCode = redisUtil.get(realKey);
// //当进入登录页时,有一定几率出现验证码错误 #1714
// if(checkCode==null || !checkCode.toString().equals(lowerCaseCaptcha)) {
// log.warn("验证码错误key= {} , Ui checkCode= {}, Redis checkCode = {}", sysLoginModel.getCheckKey(), lowerCaseCaptcha, checkCode);
// result.error500("验证码错误");
// // 改成特殊的code 便于前端判断
// result.setCode(HttpStatus.PRECONDITION_FAILED.value());
// return result;
// }
// String captcha = sysLoginModel.getCaptcha();
// if(captcha==null){
// result.error500("验证码无效");
// return result;
// }
// String lowerCaseCaptcha = captcha.toLowerCase();
// // 加入密钥作为混淆,避免简单的拼接,被外部利用,用户自定义该密钥即可
// String origin = lowerCaseCaptcha+sysLoginModel.getCheckKey()+jeecgBaseConfig.getSignatureSecret();
// String realKey = Md5Util.md5Encode(origin, "utf-8");
// Object checkCode = redisUtil.get(realKey);
// //当进入登录页时,有一定几率出现验证码错误 #1714
// if(checkCode==null || !checkCode.toString().equals(lowerCaseCaptcha)) {
// log.warn("验证码错误key= {} , Ui checkCode= {}, Redis checkCode = {}", sysLoginModel.getCheckKey(), lowerCaseCaptcha,
// checkCode);
// result.error500("验证码错误");
// // 改成特殊的code 便于前端判断
// result.setCode(HttpStatus.PRECONDITION_FAILED.value());
// return result;
// }
// step.2 校验用户是否存在且有效
LambdaQueryWrapper<SysUser> queryWrapper = new LambdaQueryWrapper<>();
@@ -119,17 +116,16 @@ public class LoginController {
userInfo(sysUser, result, request);
// step.5 登录成功删除验证码
// redisUtil.del(realKey);
// redisUtil.del(realKey);
redisUtil.del(CommonConstant.LOGIN_FAIL + username);
// step.6 记录用户登录日志
LoginUser loginUser = new LoginUser();
BeanUtils.copyProperties(sysUser, loginUser);
baseCommonService.addLog("用户名: " + username + ",登录成功!", CommonConstant.LOG_TYPE_1, null, loginUser);
baseCommonService.addLog("用户名: " + username + ",登录成功!", CommonConstant.LOG_TYPE_1, null, loginUser, new Date());
return result;
}
/**
* 【vue3专用】获取用户信息
*/
@@ -189,7 +185,7 @@ public class LoginController {
LoginUser sysUser = sysBaseApi.getUserByName(username);
if (sysUser != null) {
//update-begin--Author:wangshuai Date:20200714 for登出日志没有记录人员
baseCommonService.addLog("用户名: " + sysUser.getRealname() + ",退出成功!", CommonConstant.LOG_TYPE_1, null, sysUser);
baseCommonService.addLog("用户名: " + sysUser.getRealname() + ",退出成功!", CommonConstant.LOG_TYPE_1, null, sysUser,new Date());
//update-end--Author:wangshuai Date:20200714 for登出日志没有记录人员
log.info(" 用户名: " + sysUser.getRealname() + ",退出成功! ");
//清空用户登录Token缓存
@@ -260,7 +256,6 @@ public class LoginController {
return result;
}
/**
* 登陆成功选择用户当前部门
*
@@ -396,7 +391,6 @@ public class LoginController {
return result;
}
/**
* 手机号登录接口
*
@@ -441,7 +435,6 @@ public class LoginController {
return result;
}
/**
* 用户信息
*
@@ -698,7 +691,6 @@ public class LoginController {
return Result.OK("扫码成功");
}
/**
* 获取用户扫码后保存的token
*/
@@ -808,7 +800,6 @@ public class LoginController {
return result;
}
/**
* 图形验证码
*

View File

@@ -21,10 +21,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.*;
/**
* @Description: 在线用户
@@ -112,7 +109,7 @@ public class SysUserOnlineController {
String username = JwtUtil.getUsername(online.getToken());
LoginUser sysUser = sysBaseApi.getUserByName(username);
if (sysUser != null) {
baseCommonService.addLog("强制: " + sysUser.getRealname() + "退出成功!", CommonConstant.LOG_TYPE_1, null, sysUser);
baseCommonService.addLog("强制: " + sysUser.getRealname() + "退出成功!", CommonConstant.LOG_TYPE_1, null, sysUser,new Date());
log.info(" 强制 " + sysUser.getRealname() + "退出成功! ");
//清空用户登录Token缓存
redisUtil.del(CommonConstant.PREFIX_USER_TOKEN + online.getToken());