|
@@ -3,6 +3,7 @@ package com.fdkankan.ucenter.controller;
|
|
import cn.hutool.captcha.CaptchaUtil;
|
|
import cn.hutool.captcha.CaptchaUtil;
|
|
import cn.hutool.captcha.LineCaptcha;
|
|
import cn.hutool.captcha.LineCaptcha;
|
|
import cn.hutool.captcha.generator.MathGenerator;
|
|
import cn.hutool.captcha.generator.MathGenerator;
|
|
|
|
+import cn.hutool.extra.servlet.ServletUtil;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.fdkankan.common.exception.BusinessException;
|
|
import com.fdkankan.common.exception.BusinessException;
|
|
import com.fdkankan.common.util.JwtUtil;
|
|
import com.fdkankan.common.util.JwtUtil;
|
|
@@ -48,33 +49,31 @@ public class LoginController extends BaseController {
|
|
*/
|
|
*/
|
|
@PostMapping("/login")
|
|
@PostMapping("/login")
|
|
public Result login(@RequestBody LoginParam param){
|
|
public Result login(@RequestBody LoginParam param){
|
|
- if(StringUtils.isBlank(param.getAuthCode())){
|
|
|
|
|
|
+
|
|
|
|
+ if (StringUtils.isBlank(param.getAuthCode()) ||StringUtils.isEmpty(param.getPassword()) || StringUtils.isEmpty(param.getPhoneNum())){
|
|
throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
|
|
throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
|
|
}
|
|
}
|
|
|
|
+ String userName = param.getPhoneNum();
|
|
|
|
+ loginService.checkLoginNum(param.getPhoneNum());
|
|
|
|
+
|
|
String id = request.getSession().getId();
|
|
String id = request.getSession().getId();
|
|
String redisKey = String.format(RedisKeyUtil.loginAuthCode,id);
|
|
String redisKey = String.format(RedisKeyUtil.loginAuthCode,id);
|
|
String redisCode = redisUtil.get(redisKey);
|
|
String redisCode = redisUtil.get(redisKey);
|
|
if(!redisUtil.hasKey(redisKey)){
|
|
if(!redisUtil.hasKey(redisKey)){
|
|
|
|
+ loginService.addLoginErrorNum(userName);
|
|
throw new BusinessException(LoginConstant.FAILURE_CODE_3006, LoginConstant.FAILURE_MSG_3006);
|
|
throw new BusinessException(LoginConstant.FAILURE_CODE_3006, LoginConstant.FAILURE_MSG_3006);
|
|
}
|
|
}
|
|
redisUtil.del(redisKey);
|
|
redisUtil.del(redisKey);
|
|
MathGenerator mathGenerator = new MathGenerator(2);
|
|
MathGenerator mathGenerator = new MathGenerator(2);
|
|
boolean verify = mathGenerator.verify(redisCode,param.getAuthCode());
|
|
boolean verify = mathGenerator.verify(redisCode,param.getAuthCode());
|
|
if(!verify){
|
|
if(!verify){
|
|
|
|
+ loginService.addLoginErrorNum(userName);
|
|
throw new BusinessException(LoginConstant.FAILURE_CODE_3006, LoginConstant.FAILURE_MSG_3006);
|
|
throw new BusinessException(LoginConstant.FAILURE_CODE_3006, LoginConstant.FAILURE_MSG_3006);
|
|
}
|
|
}
|
|
-
|
|
|
|
return Result.success(loginService.login(param));
|
|
return Result.success(loginService.login(param));
|
|
}
|
|
}
|
|
- /**
|
|
|
|
- * 登录
|
|
|
|
- * phoneNum 用户名
|
|
|
|
- * password 密码
|
|
|
|
- */
|
|
|
|
- @PostMapping("/loginClear")
|
|
|
|
- public Result loginClear(@RequestBody LoginParam param){
|
|
|
|
- return Result.success(loginService.loginClear(param));
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
/**
|
|
/**
|
|
* 相机扫码登录 获取二维码
|
|
* 相机扫码登录 获取二维码
|
|
@@ -122,15 +121,16 @@ public class LoginController extends BaseController {
|
|
if(!verify){
|
|
if(!verify){
|
|
throw new BusinessException(LoginConstant.FAILURE_CODE_3006, LoginConstant.FAILURE_MSG_3006);
|
|
throw new BusinessException(LoginConstant.FAILURE_CODE_3006, LoginConstant.FAILURE_MSG_3006);
|
|
}
|
|
}
|
|
-
|
|
|
|
-// if(redisUtil.hasKey(String.format(RedisKeyUtil.checkUserCount,id))){
|
|
|
|
-// String countStr = redisUtil.get(String.format(RedisKeyUtil.checkUserCount, id));
|
|
|
|
-// if(Integer.valueOf(countStr) >=5){
|
|
|
|
-// throw new BusinessException(LoginConstant.FAILURE_CODE_3006, LoginConstant.FAILURE_MSG_3006);
|
|
|
|
-// }
|
|
|
|
-// }else {
|
|
|
|
-// redisUtil.set(String.format(RedisKeyUtil.checkUserCount,id),"1",60);
|
|
|
|
-// }
|
|
|
|
|
|
+ Integer count = 0;
|
|
|
|
+ if(redisUtil.hasKey(String.format(RedisKeyUtil.checkUserCount,id))){
|
|
|
|
+ String countStr = redisUtil.get(String.format(RedisKeyUtil.checkUserCount, id));
|
|
|
|
+ count = Integer.valueOf(countStr);
|
|
|
|
+ if(count >=5){
|
|
|
|
+ throw new BusinessException(LoginConstant.FAILURE_CODE_3038, LoginConstant.FAILURE_MSG_3038);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ count ++;
|
|
|
|
+ redisUtil.set(String.format(RedisKeyUtil.checkUserCount,id),count+"",60);
|
|
loginService.checkUser(param.getPhoneNum(),true);
|
|
loginService.checkUser(param.getPhoneNum(),true);
|
|
return Result.success();
|
|
return Result.success();
|
|
}
|
|
}
|