|
|
@@ -3,6 +3,7 @@ package com.iformall.controller; |
|
|
|
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.google.code.kaptcha.Constants; |
|
|
|
import com.google.code.kaptcha.Producer; |
|
|
|
import com.iformall.annotation.AuthIgnore; |
|
|
|
import com.iformall.annotation.TenantIgnore; |
|
|
@@ -42,6 +43,7 @@ import javax.imageio.ImageIO; |
|
|
|
import javax.servlet.ServletOutputStream; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import javax.servlet.http.HttpSession; |
|
|
|
import java.awt.image.BufferedImage; |
|
|
|
import java.io.IOException; |
|
|
|
import java.util.Date; |
|
|
@@ -115,7 +117,7 @@ public class WxUserGrantController extends BaseController { |
|
|
|
@AuthIgnore |
|
|
|
@ApiOperation("验证码") |
|
|
|
@GetMapping("/captcha.jpg") |
|
|
|
public void captcha(HttpServletResponse response) { |
|
|
|
public void captcha(HttpServletResponse response, HttpSession session) { |
|
|
|
logger.debug("[" + getIpAddr() + "] WxUserGrantController::captcha"); |
|
|
|
response.setHeader("Cache-Control", "no-store, no-cache"); |
|
|
|
response.setContentType("image/jpeg"); |
|
|
@@ -126,9 +128,11 @@ public class WxUserGrantController extends BaseController { |
|
|
|
BufferedImage image = producer.createImage(text); |
|
|
|
|
|
|
|
//保存到redis |
|
|
|
String ipAddr = getIpAddr(); |
|
|
|
String key = Constant.captchaPrev + ":" + ipAddr; |
|
|
|
RedisCacheUtils.cache(redisTemplate, key, text, 60); |
|
|
|
// String ipAddr = getIpAddr(); |
|
|
|
// String key = Constant.captchaPrev + ":" + ipAddr; |
|
|
|
// RedisCacheUtils.cache(redisTemplate, key, text, 60); |
|
|
|
|
|
|
|
session.setAttribute(Constants.KAPTCHA_SESSION_KEY, text); |
|
|
|
|
|
|
|
ServletOutputStream out = null; |
|
|
|
try { |
|
|
@@ -152,7 +156,7 @@ public class WxUserGrantController extends BaseController { |
|
|
|
@AuthIgnore |
|
|
|
@PostMapping("/login") |
|
|
|
@ApiOperation(value = "用户登录", notes = "{\"phone\":\"string\",\"password\":\"string\",\"code\":\"string\"}") |
|
|
|
public ResultData loginByPhone(@RequestBody Map<String, String> map) { |
|
|
|
public ResultData loginByPhone(@RequestBody Map<String, String> map, HttpSession session) { |
|
|
|
String ipAddr = getIpAddr(); |
|
|
|
logger.debug("[" + ipAddr + "] WxUserGrantController::loginByPhone"); |
|
|
|
String code = map.get("code"); |
|
|
@@ -160,8 +164,18 @@ public class WxUserGrantController extends BaseController { |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "请输入验证码"); |
|
|
|
} |
|
|
|
|
|
|
|
String key = Constant.captchaPrev + ":" + ipAddr; |
|
|
|
String code1 = RedisCacheUtils.getCacheString(redisTemplate, key); |
|
|
|
Object kaptcha = session.getAttribute(Constants.KAPTCHA_SESSION_KEY); |
|
|
|
if(kaptcha == null){ |
|
|
|
return new ResultData(ErrorCode.KAPCHA_NOT_VALID.getCode()); |
|
|
|
} |
|
|
|
session.removeAttribute(Constants.KAPTCHA_SESSION_KEY); |
|
|
|
if(!kaptcha.toString().equals(code)){ |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "验证码不正确"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// String key = Constant.captchaPrev + ":" + ipAddr; |
|
|
|
// String code1 = RedisCacheUtils.getCacheString(redisTemplate, key); |
|
|
|
// if (StringUtils.isBlank(code1)) { |
|
|
|
// return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "验证码已过期"); |
|
|
|
// } |
|
|
@@ -205,23 +219,31 @@ public class WxUserGrantController extends BaseController { |
|
|
|
@AuthIgnore |
|
|
|
@PostMapping("/loginByEmail") |
|
|
|
@ApiOperation(value = "用户登录", notes = "{\"email\":\"string\",\"password\":\"string\",\"code\":\"string\"}") |
|
|
|
public ResultData loginByEmail(@RequestBody Map<String, String> map) { |
|
|
|
public ResultData loginByEmail(@RequestBody Map<String, String> map, HttpSession session) { |
|
|
|
String ipAddr = getIpAddr(); |
|
|
|
logger.debug("[" + ipAddr + "] WxUserGrantController::loginByEmail"); |
|
|
|
String code = map.get("code"); |
|
|
|
if (StringUtils.isBlank(code)) { |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "请输入验证码"); |
|
|
|
} |
|
|
|
|
|
|
|
String key = Constant.captchaPrev + ":" + ipAddr; |
|
|
|
String code1 = RedisCacheUtils.getCacheString(redisTemplate, key); |
|
|
|
if (StringUtils.isBlank(code1)) { |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "验证码已过期"); |
|
|
|
Object kaptcha = session.getAttribute(Constants.KAPTCHA_SESSION_KEY); |
|
|
|
if(kaptcha == null){ |
|
|
|
return new ResultData(ErrorCode.KAPCHA_NOT_VALID.getCode()); |
|
|
|
} |
|
|
|
if (!code1.equals(code)) { |
|
|
|
session.removeAttribute(Constants.KAPTCHA_SESSION_KEY); |
|
|
|
if(!kaptcha.toString().equals(code)){ |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "验证码不正确"); |
|
|
|
} |
|
|
|
|
|
|
|
// String key = Constant.captchaPrev + ":" + ipAddr; |
|
|
|
// String code1 = RedisCacheUtils.getCacheString(redisTemplate, key); |
|
|
|
// if (StringUtils.isBlank(code1)) { |
|
|
|
// return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "验证码已过期"); |
|
|
|
// } |
|
|
|
// if (!code1.equals(code)) { |
|
|
|
// return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "验证码不正确"); |
|
|
|
// } |
|
|
|
|
|
|
|
String email = map.get("email"); |
|
|
|
String password = map.get("password"); |
|
|
|
if (StringUtils.isBlank(email) || StringUtils.isBlank(password)) { |
|
|
@@ -337,7 +359,7 @@ public class WxUserGrantController extends BaseController { |
|
|
|
@GetMapping("sendPhoneCode") |
|
|
|
@ApiImplicitParams({ |
|
|
|
@ApiImplicitParam(name = "phone", value = "手机号", dataType = "String", paramType = "query", required = true)}) |
|
|
|
public ResultData sendPhoneCode(String phone, String code) { |
|
|
|
public ResultData sendPhoneCode(String phone, String code, HttpSession session) { |
|
|
|
String ipAddr = getIpAddr(); |
|
|
|
logger.debug("[" + ipAddr + "] WxUserGrantController::sendPhoneCode"); |
|
|
|
if (StringUtils.isBlank(phone)) { |
|
|
@@ -347,14 +369,23 @@ public class WxUserGrantController extends BaseController { |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "请输入验证码"); |
|
|
|
} |
|
|
|
|
|
|
|
String key = Constant.captchaPrev + ":" + ipAddr; |
|
|
|
String code1 = RedisCacheUtils.getCacheString(redisTemplate, key); |
|
|
|
if (StringUtils.isBlank(code1)) { |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "验证码已过期"); |
|
|
|
Object kaptcha = session.getAttribute(Constants.KAPTCHA_SESSION_KEY); |
|
|
|
if(kaptcha == null){ |
|
|
|
return new ResultData(ErrorCode.KAPCHA_NOT_VALID.getCode()); |
|
|
|
} |
|
|
|
if (!code1.equals(code)) { |
|
|
|
session.removeAttribute(Constants.KAPTCHA_SESSION_KEY); |
|
|
|
if(!kaptcha.toString().equals(code)){ |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "验证码不正确"); |
|
|
|
} |
|
|
|
|
|
|
|
// String key = Constant.captchaPrev + ":" + ipAddr; |
|
|
|
// String code1 = RedisCacheUtils.getCacheString(redisTemplate, key); |
|
|
|
// if (StringUtils.isBlank(code1)) { |
|
|
|
// return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "验证码已过期"); |
|
|
|
// } |
|
|
|
// if (!code1.equals(code)) { |
|
|
|
// return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "验证码不正确"); |
|
|
|
// } |
|
|
|
WxCUserBasicInfo basicInfo = wxCUserBasicInfoService.findInfoByPhone(getTenantInfo(), phone); |
|
|
|
if (basicInfo == null) { |
|
|
|
return new ResultData(ErrorCode.USER_IS_EMPTY.getCode(), "该手机号未注册"); |
|
|
|