|
@@ -4,10 +4,7 @@ import cn.com.ctop.common.module.entity.CorpFeishuUser;
|
|
|
import cn.com.ctop.common.module.entity.CtopCorpWexinUser;
|
|
|
import cn.com.ctop.common.module.entity.SysDepart;
|
|
|
import cn.com.ctop.common.module.entity.SysUser;
|
|
|
-import cn.com.ctop.common.module.service.ICorpFeishuUserService;
|
|
|
-import cn.com.ctop.common.module.service.ICtopCorpWexinUserService;
|
|
|
-import cn.com.ctop.common.module.service.ISysDepartService;
|
|
|
-import cn.com.ctop.common.module.service.ISysUserService;
|
|
|
+import cn.com.ctop.common.module.service.*;
|
|
|
import cn.com.ctop.common.module.utils.AesEncryptUtil;
|
|
|
import cn.com.ctop.common.module.utils.ResultMapUtils;
|
|
|
import cn.com.ctop.common.module.utils.StatusCode;
|
|
@@ -31,14 +28,12 @@ import org.apache.shiro.SecurityUtils;
|
|
|
import org.jeecg.common.api.vo.Result;
|
|
|
import org.jeecg.common.constant.CacheConstant;
|
|
|
import org.jeecg.common.constant.CommonConstant;
|
|
|
-import cn.com.ctop.common.module.service.ISysBaseApi;
|
|
|
import org.jeecg.common.system.util.JwtUtil;
|
|
|
import org.jeecg.common.system.vo.LoginUser;
|
|
|
import org.jeecg.common.util.*;
|
|
|
import org.jeecg.common.util.encryption.EncryptedString;
|
|
|
import org.jeecg.modules.shiro.vo.DefContants;
|
|
|
import org.jeecg.modules.system.model.SysLoginModel;
|
|
|
-import cn.com.ctop.common.module.service.ISysDictService;
|
|
|
import org.jeecg.modules.system.service.ISysLogService;
|
|
|
import org.jeecg.modules.system.util.RandImageUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -55,7 +50,7 @@ import java.util.*;
|
|
|
*/
|
|
|
@RestController
|
|
|
@RequestMapping("/sys")
|
|
|
-@Api(tags="用户登录")
|
|
|
+@Api(tags = "用户登录")
|
|
|
@Slf4j
|
|
|
public class LoginController {
|
|
|
@Autowired
|
|
@@ -75,12 +70,13 @@ public class LoginController {
|
|
|
@Autowired
|
|
|
private ICtopCorpWexinUserService ctopCorpWexinUserService;
|
|
|
private static final String BASE_CHECK_CODES = "qwertyuiplkjhgfdsazxcvbnmQWERTYUPLKJHGFDSAZXCVBNM1234567890";
|
|
|
+
|
|
|
@GetMapping("feishu/url")
|
|
|
- public Map<String,Object> getUrl(){
|
|
|
- Map<String,Object>result = new HashMap<>();
|
|
|
+ public Map<String, Object> getUrl() {
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
try {
|
|
|
String url = AuthProvider.getAuthUrl("");
|
|
|
- result.put("url",url);
|
|
|
+ result.put("url", url);
|
|
|
ResultMapUtils.setResultMap(result, StatusCode.COMMON_SUCCESS);
|
|
|
return result;
|
|
|
} catch (Exception e) {
|
|
@@ -89,19 +85,20 @@ public class LoginController {
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
@GetMapping("/feishu/auth")
|
|
|
public Result<JSONObject> feishuAuth(HttpServletRequest request,
|
|
|
HttpServletResponse response,
|
|
|
- @RequestParam(name = "code",defaultValue = "code") String code,
|
|
|
- @RequestParam(name = "state",defaultValue = "_t") String state) throws IOException {
|
|
|
+ @RequestParam(name = "code", defaultValue = "code") String code,
|
|
|
+ @RequestParam(name = "state", defaultValue = "_t") String state) throws IOException {
|
|
|
Result<JSONObject> result = new Result<>();
|
|
|
//1:根据code值获取用户飞书信息
|
|
|
try {
|
|
|
- if("code".equals(code.trim())){
|
|
|
+ if ("code".equals(code.trim())) {
|
|
|
JSONObject setData = new JSONObject();
|
|
|
String url = AuthProvider.getAuthUrl("");
|
|
|
- setData.put("url",url);
|
|
|
- setData.put("type",1);
|
|
|
+ setData.put("url", url);
|
|
|
+ setData.put("type", 1);
|
|
|
result.setResult(setData);
|
|
|
result.success("重定向");
|
|
|
return result;
|
|
@@ -113,14 +110,14 @@ public class LoginController {
|
|
|
JSONObject userData = AuthProvider.getUserInfo(accessToken);
|
|
|
JSONObject dataObject = userData.getJSONObject("data");
|
|
|
String email = dataObject.getString("email");
|
|
|
- if(null == email|| "".equals(email.trim())){
|
|
|
+ if (null == email || "".equals(email.trim())) {
|
|
|
return result.error500(StatusCode.CTOP_FEISHU_EMAIL_NOT_EXIST.getDesc());
|
|
|
}
|
|
|
SysUser sysUser = sysUserService.getUserByEmail(email);
|
|
|
if (sysUser == null) {
|
|
|
return result.error500(StatusCode.CTOP_FEISHU_ACCOUNT_NOT_EXIST.getDesc());
|
|
|
}
|
|
|
- if(sysUser.getStatus() != 1){
|
|
|
+ if (sysUser.getStatus() != 1) {
|
|
|
return result.error500(StatusCode.CTOP_FEISHU_ACCOUNT_NOT_EXIST.getDesc());
|
|
|
}
|
|
|
String departId = sysDepartService.selectIdByOrdCode(sysUser.getOrgCode());
|
|
@@ -160,11 +157,11 @@ public class LoginController {
|
|
|
public Result<JSONObject> wxlogin(@RequestParam(name = "code") String code) throws Exception {
|
|
|
Result<JSONObject> result = new Result<>();
|
|
|
val configStorage = new WxCpDefaultConfigImpl();
|
|
|
- configStorage.setCorpId("wwef2e51064c0ac897");
|
|
|
+ configStorage.setCorpId("ww24b8a47826f5875f");
|
|
|
configStorage.setAgentId(1000002);
|
|
|
- configStorage.setCorpSecret("ieoVDAIurCOMdLrvktyQNCqWvTPqdphmXSFdk57NZ1k");
|
|
|
- /* configStorage.setToken("hcst2019");
|
|
|
- configStorage.setAesKey("hcst2019");*/
|
|
|
+ configStorage.setCorpSecret("MJIlySADGPlgvADnkFQPUpfZD4yV-4WN6066OgNnb0s");
|
|
|
+ configStorage.setToken("hcst2019");
|
|
|
+ configStorage.setAesKey("hcst2019");
|
|
|
val service = new WxCpServiceImpl();
|
|
|
|
|
|
service.setWxCpConfigStorage(configStorage);
|
|
@@ -180,7 +177,7 @@ public class LoginController {
|
|
|
result.error500("该用户未注册系统账户,请联系管理员");
|
|
|
return result;
|
|
|
}
|
|
|
- if(sysUser.getStatus() != 1){
|
|
|
+ if (sysUser.getStatus() != 1) {
|
|
|
result.error500("该用户已冻结,请联系管理员");
|
|
|
return result;
|
|
|
}
|
|
@@ -303,22 +300,23 @@ public class LoginController {
|
|
|
|
|
|
/**
|
|
|
* 退出登录
|
|
|
+ *
|
|
|
* @param request
|
|
|
* @param response
|
|
|
* @return
|
|
|
*/
|
|
|
@RequestMapping(value = "/logout")
|
|
|
- public Result<Object> logout(HttpServletRequest request,HttpServletResponse response) {
|
|
|
+ public Result<Object> logout(HttpServletRequest request, HttpServletResponse response) {
|
|
|
//用户退出逻辑
|
|
|
String token = request.getHeader(DefContants.X_ACCESS_TOKEN);
|
|
|
- if(oConvertUtils.isEmpty(token)) {
|
|
|
+ if (oConvertUtils.isEmpty(token)) {
|
|
|
return Result.error("退出登录失败!");
|
|
|
}
|
|
|
String username = JwtUtil.getUsername(token);
|
|
|
LoginUser sysUser = sysBaseApi.getUserByName(username);
|
|
|
- if(sysUser!=null) {
|
|
|
- sysBaseApi.addLog("用户名: "+sysUser.getRealname()+",退出成功!", CommonConstant.LOG_TYPE_1, null);
|
|
|
- log.info(" 用户名: "+sysUser.getRealname()+",退出成功! ");
|
|
|
+ if (sysUser != null) {
|
|
|
+ sysBaseApi.addLog("用户名: " + sysUser.getRealname() + ",退出成功!", CommonConstant.LOG_TYPE_1, null);
|
|
|
+ log.info(" 用户名: " + sysUser.getRealname() + ",退出成功! ");
|
|
|
//清空用户登录Token缓存
|
|
|
redisUtil.del(CommonConstant.PREFIX_USER_TOKEN + token);
|
|
|
//清空用户登录Shiro权限缓存
|
|
@@ -328,13 +326,14 @@ public class LoginController {
|
|
|
//调用shiro的logout
|
|
|
SecurityUtils.getSubject().logout();
|
|
|
return Result.ok("退出登录成功!");
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
return Result.error("Token无效!");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取访问量
|
|
|
+ *
|
|
|
* @return
|
|
|
*/
|
|
|
@GetMapping("loginfo")
|
|
@@ -354,9 +353,9 @@ public class LoginController {
|
|
|
// 获取系统访问记录
|
|
|
Long totalVisitCount = logService.findTotalVisitCount();
|
|
|
obj.put("totalVisitCount", totalVisitCount);
|
|
|
- Long todayVisitCount = logService.findTodayVisitCount(dayStart,dayEnd);
|
|
|
+ Long todayVisitCount = logService.findTodayVisitCount(dayStart, dayEnd);
|
|
|
obj.put("todayVisitCount", todayVisitCount);
|
|
|
- Long todayIp = logService.findTodayIp(dayStart,dayEnd);
|
|
|
+ Long todayIp = logService.findTodayIp(dayStart, dayEnd);
|
|
|
//update-end--Author:zhangweijian Date:20190428 for:传入开始时间,结束时间参数
|
|
|
obj.put("todayIp", todayIp);
|
|
|
result.setResult(obj);
|
|
@@ -366,21 +365,22 @@ public class LoginController {
|
|
|
|
|
|
/**
|
|
|
* 获取访问量
|
|
|
+ *
|
|
|
* @return
|
|
|
*/
|
|
|
@GetMapping("visitInfo")
|
|
|
- public Result<List<Map<String,Object>>> visitInfo() {
|
|
|
- Result<List<Map<String,Object>>> result = new Result<List<Map<String,Object>>>();
|
|
|
+ public Result<List<Map<String, Object>>> visitInfo() {
|
|
|
+ Result<List<Map<String, Object>>> result = new Result<List<Map<String, Object>>>();
|
|
|
Calendar calendar = new GregorianCalendar();
|
|
|
- calendar.set(Calendar.HOUR_OF_DAY,0);
|
|
|
- calendar.set(Calendar.MINUTE,0);
|
|
|
- calendar.set(Calendar.SECOND,0);
|
|
|
- calendar.set(Calendar.MILLISECOND,0);
|
|
|
+ calendar.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
+ calendar.set(Calendar.MINUTE, 0);
|
|
|
+ calendar.set(Calendar.SECOND, 0);
|
|
|
+ calendar.set(Calendar.MILLISECOND, 0);
|
|
|
calendar.add(Calendar.DAY_OF_MONTH, 1);
|
|
|
Date dayEnd = calendar.getTime();
|
|
|
calendar.add(Calendar.DAY_OF_MONTH, -7);
|
|
|
Date dayStart = calendar.getTime();
|
|
|
- List<Map<String,Object>> list = logService.findVisitCount(dayStart, dayEnd);
|
|
|
+ List<Map<String, Object>> list = logService.findVisitCount(dayStart, dayEnd);
|
|
|
result.setResult(oConvertUtils.toLowerCasePageList(list));
|
|
|
return result;
|
|
|
}
|
|
@@ -388,6 +388,7 @@ public class LoginController {
|
|
|
|
|
|
/**
|
|
|
* 登陆成功选择用户当前部门
|
|
|
+ *
|
|
|
* @param user
|
|
|
* @return
|
|
|
*/
|
|
@@ -395,11 +396,11 @@ public class LoginController {
|
|
|
public Result<JSONObject> selectDepart(@RequestBody SysUser user) {
|
|
|
Result<JSONObject> result = new Result<JSONObject>();
|
|
|
String username = user.getUsername();
|
|
|
- if(oConvertUtils.isEmpty(username)) {
|
|
|
- LoginUser sysUser = (LoginUser)SecurityUtils.getSubject().getPrincipal();
|
|
|
+ if (oConvertUtils.isEmpty(username)) {
|
|
|
+ LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
|
username = sysUser.getUsername();
|
|
|
}
|
|
|
- String orgCode= user.getOrgCode();
|
|
|
+ String orgCode = user.getOrgCode();
|
|
|
this.sysUserService.updateUserDepart(username, orgCode);
|
|
|
SysUser sysUser = sysUserService.getUserByName(username);
|
|
|
JSONObject obj = new JSONObject();
|
|
@@ -419,9 +420,9 @@ public class LoginController {
|
|
|
Result<String> result = new Result<String>();
|
|
|
String mobile = jsonObject.get("mobile").toString();
|
|
|
//手机号模式 登录模式: "2" 注册模式: "1"
|
|
|
- String smsmode=jsonObject.get("smsmode").toString();
|
|
|
+ String smsmode = jsonObject.get("smsmode").toString();
|
|
|
log.info(mobile);
|
|
|
- if(oConvertUtils.isEmpty(mobile)){
|
|
|
+ if (oConvertUtils.isEmpty(mobile)) {
|
|
|
result.setMessage("手机号不允许为空!");
|
|
|
result.setSuccess(false);
|
|
|
return result;
|
|
@@ -442,17 +443,17 @@ public class LoginController {
|
|
|
//注册模板
|
|
|
if (CommonConstant.SMS_TPL_TYPE_1.equals(smsmode)) {
|
|
|
SysUser sysUser = sysUserService.getUserByPhone(mobile);
|
|
|
- if(sysUser!=null) {
|
|
|
+ if (sysUser != null) {
|
|
|
result.error500(" 手机号已经注册,请直接登录!");
|
|
|
sysBaseApi.addLog("手机号已经注册,请直接登录!", CommonConstant.LOG_TYPE_1, null);
|
|
|
return result;
|
|
|
}
|
|
|
b = DySmsHelper.sendSms(mobile, obj, DySmsEnum.REGISTER_TEMPLATE_CODE);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
//登录模式,校验用户有效性
|
|
|
SysUser sysUser = sysUserService.getUserByPhone(mobile);
|
|
|
result = sysUserService.checkUserIsEffective(sysUser);
|
|
|
- if(!result.isSuccess()) {
|
|
|
+ if (!result.isSuccess()) {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
@@ -462,7 +463,7 @@ public class LoginController {
|
|
|
if (CommonConstant.SMS_TPL_TYPE_0.equals(smsmode)) {
|
|
|
//登录模板
|
|
|
b = DySmsHelper.sendSms(mobile, obj, DySmsEnum.LOGIN_TEMPLATE_CODE);
|
|
|
- } else if(CommonConstant.SMS_TPL_TYPE_2.equals(smsmode)) {
|
|
|
+ } else if (CommonConstant.SMS_TPL_TYPE_2.equals(smsmode)) {
|
|
|
//忘记密码模板
|
|
|
b = DySmsHelper.sendSms(mobile, obj, DySmsEnum.FORGET_PASSWORD_TEMPLATE_CODE);
|
|
|
}
|
|
@@ -504,7 +505,7 @@ public class LoginController {
|
|
|
//校验用户有效性
|
|
|
SysUser sysUser = sysUserService.getUserByPhone(phone);
|
|
|
result = sysUserService.checkUserIsEffective(sysUser);
|
|
|
- if(!result.isSuccess()) {
|
|
|
+ if (!result.isSuccess()) {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
@@ -537,7 +538,7 @@ public class LoginController {
|
|
|
String token = JwtUtil.sign(username, syspassword);
|
|
|
// 设置token缓存有效时间
|
|
|
redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token);
|
|
|
- redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME*2 / 1000);
|
|
|
+ redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME * 2 / 1000);
|
|
|
|
|
|
// 获取用户部门信息
|
|
|
JSONObject obj = new JSONObject();
|
|
@@ -561,29 +562,31 @@ public class LoginController {
|
|
|
|
|
|
/**
|
|
|
* 获取加密字符串
|
|
|
+ *
|
|
|
* @return
|
|
|
*/
|
|
|
@GetMapping(value = "/getEncryptedString")
|
|
|
- public Result<Map<String,String>> getEncryptedString(){
|
|
|
- Result<Map<String,String>> result = new Result<>();
|
|
|
- Map<String,String> map = new HashMap<>();
|
|
|
+ public Result<Map<String, String>> getEncryptedString() {
|
|
|
+ Result<Map<String, String>> result = new Result<>();
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
map.put("key", EncryptedString.key);
|
|
|
- map.put("iv",EncryptedString.iv);
|
|
|
+ map.put("iv", EncryptedString.iv);
|
|
|
result.setResult(map);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 后台生成图形验证码 :有效
|
|
|
+ *
|
|
|
* @param response
|
|
|
* @param key
|
|
|
*/
|
|
|
@ApiOperation("获取验证码")
|
|
|
@GetMapping(value = "/randomImage/{key}")
|
|
|
- public Result<String> randomImage(HttpServletResponse response,@PathVariable String key){
|
|
|
+ public Result<String> randomImage(HttpServletResponse response, @PathVariable String key) {
|
|
|
Result<String> res = new Result<String>();
|
|
|
try {
|
|
|
- String code = RandomUtil.randomString(BASE_CHECK_CODES,4);
|
|
|
+ String code = RandomUtil.randomString(BASE_CHECK_CODES, 4);
|
|
|
String lowerCaseCode = code.toLowerCase();
|
|
|
String realKey = MD5Util.getMd5(lowerCaseCode);
|
|
|
redisUtil.set(realKey, lowerCaseCode, 60);
|
|
@@ -591,7 +594,7 @@ public class LoginController {
|
|
|
res.setSuccess(true);
|
|
|
res.setResult(base64);
|
|
|
} catch (Exception e) {
|
|
|
- res.error500("获取验证码出错"+e.getMessage());
|
|
|
+ res.error500("获取验证码出错" + e.getMessage());
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return res;
|
|
@@ -599,6 +602,7 @@ public class LoginController {
|
|
|
|
|
|
/**
|
|
|
* app登录
|
|
|
+ *
|
|
|
* @param sysLoginModel
|
|
|
* @return
|
|
|
* @throws Exception
|
|
@@ -612,7 +616,7 @@ public class LoginController {
|
|
|
//1. 校验用户是否有效
|
|
|
SysUser sysUser = sysUserService.getUserByName(username);
|
|
|
result = sysUserService.checkUserIsEffective(sysUser);
|
|
|
- if(!result.isSuccess()) {
|
|
|
+ if (!result.isSuccess()) {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
@@ -625,7 +629,7 @@ public class LoginController {
|
|
|
}
|
|
|
|
|
|
String orgCode = sysUser.getOrgCode();
|
|
|
- if(oConvertUtils.isEmpty(orgCode)) {
|
|
|
+ if (oConvertUtils.isEmpty(orgCode)) {
|
|
|
//如果当前用户无选择部门 查看部门关联信息
|
|
|
List<SysDepart> departs = sysDepartService.queryUserDeparts(sysUser.getId());
|
|
|
if (departs == null || departs.size() == 0) {
|
|
@@ -644,7 +648,7 @@ public class LoginController {
|
|
|
String token = JwtUtil.sign(username, syspassword);
|
|
|
// 设置超时时间
|
|
|
redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token);
|
|
|
- redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME*2 / 1000);
|
|
|
+ redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME * 2 / 1000);
|
|
|
//token 信息
|
|
|
obj.put("token", token);
|
|
|
result.setResult(obj);
|
|
@@ -656,20 +660,21 @@ public class LoginController {
|
|
|
|
|
|
/**
|
|
|
* 图形验证码
|
|
|
+ *
|
|
|
* @param sysLoginModel
|
|
|
* @return
|
|
|
*/
|
|
|
@RequestMapping(value = "/checkCaptcha", method = RequestMethod.POST)
|
|
|
- public Result<?> checkCaptcha(@RequestBody SysLoginModel sysLoginModel){
|
|
|
+ public Result<?> checkCaptcha(@RequestBody SysLoginModel sysLoginModel) {
|
|
|
String captcha = sysLoginModel.getCaptcha();
|
|
|
String checkKey = sysLoginModel.getCheckKey();
|
|
|
- if(captcha==null){
|
|
|
+ if (captcha == null) {
|
|
|
return Result.error("验证码无效");
|
|
|
}
|
|
|
String lowerCaseCaptcha = captcha.toLowerCase();
|
|
|
- String realKey = MD5Util.getMd5(lowerCaseCaptcha+checkKey);
|
|
|
+ String realKey = MD5Util.getMd5(lowerCaseCaptcha + checkKey);
|
|
|
Object checkCode = redisUtil.get(realKey);
|
|
|
- if(checkCode==null || !checkCode.equals(lowerCaseCaptcha)) {
|
|
|
+ if (checkCode == null || !checkCode.equals(lowerCaseCaptcha)) {
|
|
|
return Result.error("验证码错误");
|
|
|
}
|
|
|
return Result.ok();
|