Commit 4222d919 authored by zhouqian's avatar zhouqian

Merge branch 'master' of http://gitabc.xyqb.com/head_group/xyqb-user2

# Conflicts:
#	src/main/java/cn/quantgroup/xyqb/Constants.java
parent 77e20b3b
......@@ -4,6 +4,7 @@ import cn.quantgroup.xyqb.Constants;
import cn.quantgroup.xyqb.controller.IBaseController;
import cn.quantgroup.xyqb.entity.User;
import cn.quantgroup.xyqb.entity.UserDetail;
import cn.quantgroup.xyqb.exception.UserNotExistException;
import cn.quantgroup.xyqb.model.AuthBean;
import cn.quantgroup.xyqb.model.JsonResult;
import cn.quantgroup.xyqb.model.UserModel;
......@@ -61,14 +62,6 @@ public class UserController implements IBaseController {
@Qualifier("stringRedisTemplate")
private RedisTemplate<String, String> stringRedisTemplate;
@Autowired
@Qualifier("redisConnectionFactory")
private RedisConnectionFactory redisConnectionFactory;
@Autowired
@Qualifier("redisTemplate")
private RedisTemplate redisTemplate;
@Autowired
private ISmsService smsService;
......@@ -164,7 +157,9 @@ public class UserController implements IBaseController {
}*/
@RequestMapping("/login/fast")
public JsonResult loginFast(HttpServletRequest request){
public JsonResult loginFast(
@RequestParam(required = false, defaultValue = "1") Long channelId, String appChannel,
@RequestParam(required = false, defaultValue = "1") Long createdFrom, HttpServletRequest request){
String verificationHeader = "Verification ";
String credential = request.getHeader("authorization");
if(StringUtils.isBlank(credential)){
......@@ -187,38 +182,30 @@ public class UserController implements IBaseController {
}
String phoneNo = credentialArr[0];
String verificationCode = credentialArr[1];
if(!matchPhoneNo(phoneNo)){
LOGGER.info("用户快速登录,phoneNo:{} , verificationCode:{}", phoneNo, verificationCode);
if(!ValidationUtil.validatePhoneNo(phoneNo)){
return JsonResult.buildErrorStateResult("登录失败", null);
}
if(!validateVerificationCode(phoneNo, verificationCode)){
return JsonResult.buildErrorStateResult("登录失败", null);
LOGGER.info("用户快速登录,验证码校验失败,phoneNo:{} , verificationCode:{}", phoneNo, verificationCode);
return JsonResult.buildErrorStateResult("验证码错误", null);
}
User user = userService.findByPhone(phoneNo);
if(user == null){
return JsonResult.buildErrorStateResult("登录失败", null);
user = registerFastWhenLogin(phoneNo, channelId, createdFrom, appChannel);
if (user == null) {
throw new UserNotExistException("用户未找到");
}
}
String sessionId = sessionService.findSessionIdByUserId(user.getId());
if(StringUtils.isBlank(sessionId)){
return JsonResult.buildErrorStateResult("登录失败", null);
}
SessionStruct sessionStruct = null;
if(sessionId.length() == 36){
String value = sessionService.findSessionValueBySessionId(sessionId);
if(StringUtils.isBlank(value)){
sessionStruct = sessionService.newSession(user);
SessionValue sessionValue = new SessionValue();
sessionValue.setUser(user);
sessionValue.setLastAccessTime(new Timestamp(System.currentTimeMillis()));
sessionValue.setCreatedAt(new Timestamp(System.currentTimeMillis()));
Map<String, String> values = new HashMap();
sessionValue.setValues(values);
sessionService.persistSession(sessionStruct.getSid(), sessionValue);
}
sessionStruct.setSid(sessionId);
}else {
sessionStruct = sessionService.newSession(user);
sessionService.persistSession(sessionStruct.getSid(), sessionService.newSession(user).getValues());
}
SessionStruct sessionStruct = sessionService.createSessionAndPersist(user, (session) -> {
session.setAttribute("channelId", String.valueOf(channelId));
session.setAttribute("createdFrom", String.valueOf(createdFrom));
session.setAttribute("appChannel", String.valueOf(appChannel));
});
AuthBean authBean = new AuthBean();
authBean.setPhoneNo(user.getPhoneNo());
authBean.setToken(sessionStruct.getSid());
......@@ -245,15 +232,6 @@ public class UserController implements IBaseController {
return false;
}
private boolean matchPhoneNo(String phoneNo){
String patternString = "1\\d{10}";
Pattern pattern = Pattern.compile(patternString);
Matcher matcher = pattern.matcher(phoneNo);
if(matcher.matches()){
return true;
}
return false;
}
/**
* 用户快速注册
......@@ -484,4 +462,20 @@ public class UserController implements IBaseController {
return JsonResult.buildSuccessResult("token校验成功", userModel);
}
public User registerFastWhenLogin(String phoneNo, Long channelId, Long registerFrom, String appChannel) {
String password = genRandomPwd();
LOGGER.info("用户快速注册, phoneNo:{}, verificationCode:{}, channelId:{}, registerFrom:{},appChannel:{}", phoneNo, channelId, registerFrom, appChannel);
if (!ValidationUtil.validatePhoneNo(phoneNo)) {
LOGGER.info("用户快速注册失败,手机号错误, registerFrom:{}, phoneNo:{}", registerFrom, phoneNo);
throw new UserNotExistException("手机号错误");
}
if (null == registerFrom) {
registerFrom = 1L;
}
LOGGER.info("用户快速注册成功, registerFrom:{}, phoneNo:{}", registerFrom, phoneNo);
return userService.registerAndReturn(phoneNo, password, registerFrom);
}
}
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