|
@@ -1,24 +1,35 @@
|
|
package com.fdkankan.ucenter.controller;
|
|
package com.fdkankan.ucenter.controller;
|
|
|
|
|
|
|
|
+import cn.hutool.captcha.CaptchaUtil;
|
|
|
|
+import cn.hutool.captcha.LineCaptcha;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.fdkankan.common.exception.BusinessException;
|
|
import com.fdkankan.common.util.JwtUtil;
|
|
import com.fdkankan.common.util.JwtUtil;
|
|
import com.fdkankan.redis.util.RedisUtil;
|
|
import com.fdkankan.redis.util.RedisUtil;
|
|
import com.fdkankan.ucenter.common.BaseController;
|
|
import com.fdkankan.ucenter.common.BaseController;
|
|
import com.fdkankan.ucenter.common.RedisKeyUtil;
|
|
import com.fdkankan.ucenter.common.RedisKeyUtil;
|
|
import com.fdkankan.ucenter.common.Result;
|
|
import com.fdkankan.ucenter.common.Result;
|
|
|
|
+import com.fdkankan.ucenter.constant.LoginConstant;
|
|
import com.fdkankan.ucenter.service.impl.LoginService;
|
|
import com.fdkankan.ucenter.service.impl.LoginService;
|
|
import com.fdkankan.ucenter.vo.request.LoginParam;
|
|
import com.fdkankan.ucenter.vo.request.LoginParam;
|
|
import com.fdkankan.ucenter.vo.request.RegisterParam;
|
|
import com.fdkankan.ucenter.vo.request.RegisterParam;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
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.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
+import java.io.IOException;
|
|
|
|
+
|
|
|
|
|
|
/**
|
|
/**
|
|
* 登录
|
|
* 登录
|
|
*/
|
|
*/
|
|
@RestController
|
|
@RestController
|
|
@RequestMapping("/ucenter/sso/user")
|
|
@RequestMapping("/ucenter/sso/user")
|
|
|
|
+@Slf4j
|
|
public class LoginController extends BaseController {
|
|
public class LoginController extends BaseController {
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
@@ -36,6 +47,17 @@ 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())){
|
|
|
|
+ throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
|
|
|
|
+ }
|
|
|
|
+ String id = request.getSession().getId();
|
|
|
|
+ if(!redisUtil.hasKey(String.format(RedisKeyUtil.loginAuthCode,id))){
|
|
|
|
+ throw new BusinessException(LoginConstant.FAILURE_CODE_3006, LoginConstant.FAILURE_MSG_3006);
|
|
|
|
+ }
|
|
|
|
+ if(!redisUtil.get(String.format(RedisKeyUtil.loginAuthCode,id)).equals(param.getAuthCode())){
|
|
|
|
+ throw new BusinessException(LoginConstant.FAILURE_CODE_3006, LoginConstant.FAILURE_MSG_3006);
|
|
|
|
+ }
|
|
|
|
+
|
|
return Result.success(loginService.login(param));
|
|
return Result.success(loginService.login(param));
|
|
}
|
|
}
|
|
/**
|
|
/**
|
|
@@ -78,6 +100,24 @@ public class LoginController extends BaseController {
|
|
*/
|
|
*/
|
|
@PostMapping("/checkUser")
|
|
@PostMapping("/checkUser")
|
|
public Result checkUser(@RequestBody LoginParam param){
|
|
public Result checkUser(@RequestBody LoginParam param){
|
|
|
|
+ if(StringUtils.isBlank(param.getAuthCode())){
|
|
|
|
+ throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
|
|
|
|
+ }
|
|
|
|
+ String id = request.getSession().getId();
|
|
|
|
+ if(!redisUtil.hasKey(String.format(RedisKeyUtil.loginAuthCode,id))){
|
|
|
|
+ throw new BusinessException(LoginConstant.FAILURE_CODE_3006, LoginConstant.FAILURE_MSG_3006);
|
|
|
|
+ }
|
|
|
|
+ if(!redisUtil.get(String.format(RedisKeyUtil.loginAuthCode,id)).equals(param.getAuthCode())){
|
|
|
|
+ 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);
|
|
|
|
+// }
|
|
loginService.checkUser(param.getPhoneNum(),true);
|
|
loginService.checkUser(param.getPhoneNum(),true);
|
|
return Result.success();
|
|
return Result.success();
|
|
}
|
|
}
|
|
@@ -169,5 +209,23 @@ public class LoginController extends BaseController {
|
|
|
|
|
|
return Result.success();
|
|
return Result.success();
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @GetMapping("/getLoginAuthCode")
|
|
|
|
+ public void getLoginCode(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
|
|
|
+ response.setHeader("Cache-Control", "no-store, no-cache");
|
|
|
|
+ response.setContentType("image/jpeg");
|
|
|
|
+ String id = request.getSession().getId();
|
|
|
|
+ try {
|
|
|
|
+ LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(200, 100,4,60);
|
|
|
|
+ redisUtil.set(String.format(RedisKeyUtil.loginAuthCode,id),lineCaptcha.getCode(),60*5);
|
|
|
|
+ lineCaptcha.write(response.getOutputStream());
|
|
|
|
+ response.getOutputStream().close();
|
|
|
|
+ } catch (Exception e){
|
|
|
|
+ log.info("生成登录验证码错误:",e);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|