|
@ -1,8 +1,5 @@
|
|
|
package com.yihu.jw.security.oauth2.provider.endpoint;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yihu.jw.patient.util.ConstantUtils;
|
|
|
import com.yihu.jw.restmodel.ResultStatus;
|
|
|
import com.yihu.jw.security.exception.ImgCaptchaException;
|
|
|
import com.yihu.jw.security.model.Captcha;
|
|
|
import com.yihu.jw.security.model.Oauth2Envelop;
|
|
@ -111,51 +108,51 @@ public class WlyyIotLoginEndpoint {
|
|
|
return pass;
|
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "/oauth/captchaAndRegister", method = RequestMethod.POST)
|
|
|
@ApiOperation("验证短信验证码并注册")
|
|
|
public ResponseEntity<Oauth2Envelop> captchaCheck(@RequestParam Map<String, String> parameters) throws Exception {
|
|
|
String client_id = parameters.get("client_id");
|
|
|
String mobile = parameters.get("username");
|
|
|
String captcha = parameters.get("captcha");
|
|
|
String jsonData = parameters.get("jsonData");
|
|
|
if (StringUtils.isEmpty(client_id)) {
|
|
|
throw new InvalidRequestException("client_id");
|
|
|
}
|
|
|
if (StringUtils.isEmpty(mobile)) {
|
|
|
throw new InvalidRequestException("username");
|
|
|
}
|
|
|
if (StringUtils.isEmpty(captcha)) {
|
|
|
throw new InvalidRequestException("captcha");
|
|
|
}
|
|
|
|
|
|
//图形验证码验证
|
|
|
String key = parameters.get("key");
|
|
|
String text = parameters.get("text");
|
|
|
|
|
|
if(!verifyCaptcha(key,text)){
|
|
|
throw new ImgCaptchaException("图形验证码错误!");
|
|
|
}
|
|
|
|
|
|
Oauth2Envelop<Boolean> oauth2Envelop;
|
|
|
//判断当前手机号是否注册过
|
|
|
Boolean b = userService.isRegisterUserName(mobile);
|
|
|
if(!b){
|
|
|
oauth2Envelop = new Oauth2Envelop<>("该手机号已注册过,请直接登录!", ResultStatus.INVALID_GRANT, false);
|
|
|
}else {
|
|
|
if (wlyyRedisVerifyCodeService.verification(client_id, mobile, captcha)) {
|
|
|
oauth2Envelop = new Oauth2Envelop<>("注册成功", 200, true);
|
|
|
//注册账号
|
|
|
JSONObject jsonObject = userService.createUser(jsonData);
|
|
|
if (jsonObject.getString("response").equalsIgnoreCase(ConstantUtils.FAIL)) {
|
|
|
oauth2Envelop = new Oauth2Envelop<>(jsonObject.getString("msg"), ResultStatus.INVALID_GRANT, false);
|
|
|
}
|
|
|
} else {
|
|
|
oauth2Envelop = new Oauth2Envelop<>("短信验证码错误", ResultStatus.INVALID_GRANT, false);
|
|
|
}
|
|
|
}
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
headers.set("Cache-Control", "no-store");
|
|
|
headers.set("Pragma", "no-cache");
|
|
|
return new ResponseEntity<>(oauth2Envelop, headers, HttpStatus.OK);
|
|
|
}
|
|
|
// @RequestMapping(value = "/oauth/captchaAndRegister", method = RequestMethod.POST)
|
|
|
// @ApiOperation("验证短信验证码并注册")
|
|
|
// public ResponseEntity<Oauth2Envelop> captchaCheck(@RequestParam Map<String, String> parameters) throws Exception {
|
|
|
// String client_id = parameters.get("client_id");
|
|
|
// String mobile = parameters.get("username");
|
|
|
// String captcha = parameters.get("captcha");
|
|
|
// String jsonData = parameters.get("jsonData");
|
|
|
// if (StringUtils.isEmpty(client_id)) {
|
|
|
// throw new InvalidRequestException("client_id");
|
|
|
// }
|
|
|
// if (StringUtils.isEmpty(mobile)) {
|
|
|
// throw new InvalidRequestException("username");
|
|
|
// }
|
|
|
// if (StringUtils.isEmpty(captcha)) {
|
|
|
// throw new InvalidRequestException("captcha");
|
|
|
// }
|
|
|
//
|
|
|
// //图形验证码验证
|
|
|
// String key = parameters.get("key");
|
|
|
// String text = parameters.get("text");
|
|
|
//
|
|
|
// if(!verifyCaptcha(key,text)){
|
|
|
// throw new ImgCaptchaException("图形验证码错误!");
|
|
|
// }
|
|
|
//
|
|
|
// Oauth2Envelop<Boolean> oauth2Envelop;
|
|
|
// //判断当前手机号是否注册过
|
|
|
// Boolean b = userService.isRegisterUserName(mobile);
|
|
|
// if(!b){
|
|
|
// oauth2Envelop = new Oauth2Envelop<>("该手机号已注册过,请直接登录!", ResultStatus.INVALID_GRANT, false);
|
|
|
// }else {
|
|
|
// if (wlyyRedisVerifyCodeService.verification(client_id, mobile, captcha)) {
|
|
|
// oauth2Envelop = new Oauth2Envelop<>("注册成功", 200, true);
|
|
|
// //注册账号
|
|
|
// JSONObject jsonObject = userService.createUser(jsonData);
|
|
|
// if (jsonObject.getString("response").equalsIgnoreCase(ConstantUtils.FAIL)) {
|
|
|
// oauth2Envelop = new Oauth2Envelop<>(jsonObject.getString("msg"), ResultStatus.INVALID_GRANT, false);
|
|
|
// }
|
|
|
// } else {
|
|
|
// oauth2Envelop = new Oauth2Envelop<>("短信验证码错误", ResultStatus.INVALID_GRANT, false);
|
|
|
// }
|
|
|
// }
|
|
|
// HttpHeaders headers = new HttpHeaders();
|
|
|
// headers.set("Cache-Control", "no-store");
|
|
|
// headers.set("Pragma", "no-cache");
|
|
|
// return new ResponseEntity<>(oauth2Envelop, headers, HttpStatus.OK);
|
|
|
// }
|
|
|
}
|