Commit 54f30328 authored by 技术部-任文超's avatar 技术部-任文超

按主包逻辑规范文案和调整代码逻辑

parent 323eefa0
......@@ -196,7 +196,6 @@ public class InnerController implements IBaseController {
}
if (StringUtils.isBlank(password)) {
password = genRandomPwd();
password = PasswordUtil.MD5(password.toLowerCase() + Constants.PASSWORD_SALT);
}
if (StringUtils.isBlank(uuid)) {
return JsonResult.buildErrorStateResult("用户uuid为空.", null);
......@@ -1121,7 +1120,10 @@ public class InnerController implements IBaseController {
count++;
}
}
return pwd.toString();
String password = pwd.toString();
// 加密保存
password = PasswordUtil.MD5(password.toLowerCase() + Constants.PASSWORD_SALT);
return password;
}
/**
......@@ -1135,20 +1137,35 @@ public class InnerController implements IBaseController {
@LogHttpCaller
@RequestMapping("/verifyPhoneAndCode")
public JsonResult verifyPhoneAndCode(@RequestParam String phoneNo, @RequestParam String verificationCode) {
User user = null;
if (smsService.verifyPhoneAndCode(phoneNo, verificationCode)) {
user = userService.findByPhoneWithCache(phoneNo);
}else {
return JsonResult.buildErrorStateResult("校验失败", "");
// 验证手机号
if (!ValidationUtil.validatePhoneNo(phoneNo)) {
LOGGER.info("验证手机号和验证码是否匹配,手机号错误, phoneNo:{}", phoneNo);
return JsonResult.buildErrorStateResult("手机号错误", "");
}
// 验证短信验证码
if (!smsService.verifyPhoneAndCode(phoneNo, verificationCode)) {
// 是否需要重新获取
//if(smsService.needResendCode(phoneNo)){
// return JsonResult.buildErrorStateResult("验证码失效,请重新获取", "");
//}
LOGGER.info("验证码校验失败,phoneNo:{} , verificationCode:{}", phoneNo, verificationCode);
return JsonResult.buildErrorStateResult("短信验证码错误", "");
}
if (user == null) {
user = userRegisterService.register(phoneNo, "", null);
User user = userService.findByPhoneWithCache(phoneNo);
// 检查用户有效性
if (user != null && !user.getEnable()) {
LOGGER.error("用户不存在,或者已经注销,phoneNo:{}",phoneNo);
return JsonResult.buildErrorStateResult("登录失败", null);
}
// 用户不存在时自动注册
if (Objects.isNull(user)) {
return JsonResult.buildErrorStateResult("用户不存在", "");
}else{
return JsonResult.buildSuccessResult("校验成功", new UserRet(user));
user = userRegisterService.register(phoneNo, genRandomPwd(), null);
// 注册失败
if (Objects.isNull(user)) {
return JsonResult.buildErrorStateResult("用户不存在", "");
}
}
return JsonResult.buildSuccessResult("校验成功", new UserRet(user));
}
@LogHttpCaller
......
......@@ -181,7 +181,7 @@ public class UserController implements IBaseController {
JsonResult successResult = validMap.get("success");
String phoneNo = successResult.getData().toString();
if (!ValidationUtil.validatePhoneNo(phoneNo)) {
LOGGER.info("用户快速注册失败,手机号错误, createdFrom:{},phoneNo:{}", createdFrom, phoneNo);
LOGGER.info("用户快速登录失败,手机号错误, createdFrom:{},phoneNo:{}", createdFrom, phoneNo);
throw new UserNotExistException("手机号错误");
}
String verificationCode = successResult.getMsg();
......@@ -492,35 +492,13 @@ public class UserController implements IBaseController {
*/
private void verifyPhoneAndCode(String phoneNo, String verificationCode) {
if (!smsService.verifyPhoneAndCode(phoneNo, verificationCode)) {
smsReSendOrNot(phoneNo);
// 是否需要重新发送短信验证码
if(smsService.needResendCode(phoneNo)){
throw new VerificationCodeErrorException("验证码失效,请重新获取");
}
LOGGER.info("验证码校验失败,phoneNo:{} , verificationCode:{}", phoneNo, verificationCode);
throw new VerificationCodeErrorException("短信验证码错误");
}
}
/**
* 是否需要重新获取短信验证码
* @param phoneNo
*/
private void smsReSendOrNot(String phoneNo) {
if(needRetSendCode(phoneNo)){
String key = Constants.REDIS_PREFIX_VERIFICATION_CODE + phoneNo;
stringRedisTemplate.delete(key);
String verificationCountKey = Constants.REDIS_VERIFICATION_COUNT + phoneNo;
stringRedisTemplate.opsForHash().delete(verificationCountKey, Constants.REDIS_VERIFICATION_COUNT);
throw new VerificationCodeErrorException("验证码失效,请重新获取");
}
}
/**
* 是否需要重新发送短信验证码
* @param phoneNo
* @return
*/
private boolean needRetSendCode(String phoneNo) {
String verificationCountKey = Constants.REDIS_VERIFICATION_COUNT + phoneNo;
Long getVerificationCount = stringRedisTemplate.opsForHash().increment(verificationCountKey, Constants.REDIS_VERIFICATION_COUNT, 1);
return (getVerificationCount >= Constants.VERIFICATION_CODE_FINITE_COUNT);
}
}
package cn.quantgroup.xyqb.service.sms;
import cn.quantgroup.sms.SmsSender;
import cn.quantgroup.xyqb.Constants;
/**
* 短信发送服务
......@@ -24,4 +25,11 @@ public interface ISmsService {
*/
boolean verifyPhoneAndCode(String phoneNo, String verificationCode);
/**
* 是否需要重新发送短信验证码
* @param phoneNo
* @return
*/
boolean needResendCode(String phoneNo);
}
......@@ -110,4 +110,17 @@ public class SmsServiceImpl implements ISmsService {
return StringUtils.equals(code, smsVerificationCode);
}
@Override
public boolean needResendCode(String phoneNo) {
String verificationCountKey = Constants.REDIS_VERIFICATION_COUNT + phoneNo;
Long getVerificationCount = stringRedisTemplate.opsForHash().increment(verificationCountKey, Constants.REDIS_VERIFICATION_COUNT, 1);
boolean needResend = getVerificationCount >= Constants.VERIFICATION_CODE_FINITE_COUNT;
if(needResend) {
String key = Constants.REDIS_PREFIX_VERIFICATION_CODE + phoneNo;
stringRedisTemplate.delete(key);
stringRedisTemplate.opsForHash().delete(verificationCountKey, Constants.REDIS_VERIFICATION_COUNT);
}
return needResend;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment