Commit 708f3f51 authored by hezhen's avatar hezhen

Merge branch 'master-customer-management'

# Conflicts:
#	ace-auth/ace-auth-server/src/main/java/com/github/wxiaoqi/security/auth/service/AuthService.java
#	ace-modules/ace-admin-api/src/main/java/com/github/wxiaoqi/security/admin/constant/RedisKey.java
parents fa5fa445 df525ee7
...@@ -83,9 +83,10 @@ public class AuthController { ...@@ -83,9 +83,10 @@ public class AuthController {
public JSONObject register(@RequestParam(value="username",defaultValue="")String username, public JSONObject register(@RequestParam(value="username",defaultValue="")String username,
@RequestParam(value="mobilecode",defaultValue="")String mobilecode, @RequestParam(value="mobilecode",defaultValue="")String mobilecode,
@RequestParam(value="password",defaultValue="")String password, @RequestParam(value="password",defaultValue="")String password,
@RequestParam(value="code",defaultValue="")String code)throws Exception{ @RequestParam(value="code",defaultValue="")String code,
@RequestParam(value="channel",defaultValue="1")Integer channel)throws Exception{
log.info(username+"----require register..."); log.info(username+"----require register...");
JSONObject data=appAuthService.register(username,mobilecode,password,code); JSONObject data=appAuthService.register(username,mobilecode,password,code,channel);
if(data!=null&&data.getInteger("status")== ResultCode.SUCCESS_CODE){ if(data!=null&&data.getInteger("status")== ResultCode.SUCCESS_CODE){
JwtAuthenticationRequest authenticationRequest=new JwtAuthenticationRequest(); JwtAuthenticationRequest authenticationRequest=new JwtAuthenticationRequest();
authenticationRequest.setUsername(username); authenticationRequest.setUsername(username);
...@@ -106,11 +107,12 @@ public class AuthController { ...@@ -106,11 +107,12 @@ public class AuthController {
@RequestParam(value="unionid",defaultValue="")String unionid, @RequestParam(value="unionid",defaultValue="")String unionid,
@RequestParam(value="type",defaultValue="0")Integer type, @RequestParam(value="type",defaultValue="0")Integer type,
@RequestParam(value="isQQ",defaultValue="0")Integer isQQ, @RequestParam(value="isQQ",defaultValue="0")Integer isQQ,
@RequestParam(value="code",defaultValue="")String code @RequestParam(value="code",defaultValue="")String code,
@RequestParam(value="channel",defaultValue="1")Integer channel
)throws Exception{ )throws Exception{
log.info(username+"----require wxregister..."); log.info(username+"----require wxregister...");
JSONObject data=appAuthService.wxregister( username, mobilecode, password, nickname, JSONObject data=appAuthService.wxregister( username, mobilecode, password, nickname,
headimgurl, openid, unionid,type,isQQ,code); headimgurl, openid, unionid,type,isQQ,code,channel);
if(data!=null&&data.getInteger("status")== ResultCode.SUCCESS_CODE){ if(data!=null&&data.getInteger("status")== ResultCode.SUCCESS_CODE){
JSONObject result=data.getJSONObject("data"); JSONObject result=data.getJSONObject("data");
if(result==null){ if(result==null){
......
...@@ -34,13 +34,16 @@ public interface IUserService { ...@@ -34,13 +34,16 @@ public interface IUserService {
public JSONObject register( @RequestParam(value="username",defaultValue="")String username, public JSONObject register( @RequestParam(value="username",defaultValue="")String username,
@RequestParam(value="mobilecode",defaultValue="")String mobilecode, @RequestParam(value="mobilecode",defaultValue="")String mobilecode,
@RequestParam(value="password",defaultValue="")String password, @RequestParam(value="password",defaultValue="")String password,
@RequestParam(value="code")String code); @RequestParam(value="code")String code,
@RequestParam(value="channel",defaultValue="1")Integer channel);
@RequestMapping(value = "/api/app/user/wxregister", method = RequestMethod.POST) @RequestMapping(value = "/api/app/user/wxregister", method = RequestMethod.POST)
public JSONObject wxregister( public JSONObject wxregister(
@RequestParam(value="username")String username,@RequestParam(value="mobilecode")String mobilecode, @RequestParam(value="username")String username,@RequestParam(value="mobilecode")String mobilecode,
@RequestParam(value="password")String password,@RequestParam(value="nickname")String nickname, @RequestParam(value="password")String password,@RequestParam(value="nickname")String nickname,
@RequestParam(value="headimgurl")String headimgurl,@RequestParam(value="openid")String openid, @RequestParam(value="headimgurl")String headimgurl,@RequestParam(value="openid")String openid,
@RequestParam(value="unionid")String unionid,@RequestParam(value="type")Integer type,@RequestParam(value="isQQ")Integer isQQ,@RequestParam(value="code")String code); @RequestParam(value="unionid")String unionid,@RequestParam(value="type")Integer type,
@RequestParam(value="isQQ")Integer isQQ,@RequestParam(value="code")String code,
@RequestParam(value="channel",defaultValue="1")Integer channel);
@RequestMapping(value = "/api/app/user/checkBindWechat",method = RequestMethod.POST) @RequestMapping(value = "/api/app/user/checkBindWechat",method = RequestMethod.POST)
public JSONObject checkBindWechat( @RequestParam(value="username")String username); public JSONObject checkBindWechat( @RequestParam(value="username")String username);
@RequestMapping(value = "/api/app/user/wxlogin",method = RequestMethod.POST) @RequestMapping(value = "/api/app/user/wxlogin",method = RequestMethod.POST)
......
...@@ -11,8 +11,8 @@ public interface AuthService { ...@@ -11,8 +11,8 @@ public interface AuthService {
String refresh(String oldToken) throws Exception; String refresh(String oldToken) throws Exception;
void validate(String token) throws Exception; void validate(String token) throws Exception;
JSONObject sendsms(String username, Integer type, String pointList) throws Exception; JSONObject sendsms(String username, Integer type, String pointList) throws Exception;
JSONObject register(String username, String mobilecode, String password,String code) throws Exception; JSONObject register(String username, String mobilecode, String password,String code,Integer channel) throws Exception;
JSONObject wxregister( String username, String mobilecode, String password, String nickname, String headimgurl, String openid, String unionid, Integer type,Integer isQQ,String code) throws Exception; JSONObject wxregister( String username, String mobilecode, String password, String nickname, String headimgurl, String openid, String unionid, Integer type,Integer isQQ,String code,Integer channel) throws Exception;
JSONObject checkBindWechat(String username) throws Exception; JSONObject checkBindWechat(String username) throws Exception;
JSONObject wxlogin(String openid,Integer isQQ,String code) throws Exception; JSONObject wxlogin(String openid,Integer isQQ,String code) throws Exception;
JSONObject tlogin(String username, String password,String mobilecode,Integer type,String code) throws Exception; JSONObject tlogin(String username, String password,String mobilecode,Integer type,String code) throws Exception;
......
...@@ -72,13 +72,13 @@ public class AppAuthServiceImpl implements AuthService { ...@@ -72,13 +72,13 @@ public class AppAuthServiceImpl implements AuthService {
} }
@Override @Override
public JSONObject register(String username, String mobilecode, String password,String code) throws Exception { public JSONObject register(String username, String mobilecode, String password,String code,Integer channel) throws Exception {
return userService.register(username,mobilecode,password,code); return userService.register(username,mobilecode,password,code,channel);
} }
@Override @Override
public JSONObject wxregister(String username, String mobilecode, String password, String nickname, String headimgurl, String openid, String unionid, Integer type,Integer isQQ,String code) throws Exception { public JSONObject wxregister(String username, String mobilecode, String password, String nickname, String headimgurl, String openid, String unionid, Integer type,Integer isQQ,String code,Integer channel) throws Exception {
return userService.wxregister(username,mobilecode,password,nickname,headimgurl,openid,unionid,type,isQQ,code); return userService.wxregister(username,mobilecode,password,nickname,headimgurl,openid,unionid,type,isQQ,code,channel);
} }
@Override @Override
......
...@@ -69,13 +69,13 @@ public class AuthServiceImpl implements AuthService { ...@@ -69,13 +69,13 @@ public class AuthServiceImpl implements AuthService {
return userService.sendsms(username,type, pointList); return userService.sendsms(username,type, pointList);
} }
@Override @Override
public JSONObject register(String username, String mobilecode, String password,String code) throws Exception { public JSONObject register(String username, String mobilecode, String password,String code,Integer channel) throws Exception {
return userService.register(username,mobilecode,password,code); return userService.register(username,mobilecode,password,code,channel);
} }
@Override @Override
public JSONObject wxregister(String username, String mobilecode, String password, String nickname, String headimgurl, String openid, String unionid, Integer type,Integer isQQ,String code) throws Exception { public JSONObject wxregister(String username, String mobilecode, String password, String nickname, String headimgurl, String openid, String unionid, Integer type,Integer isQQ,String code,Integer channel) throws Exception {
return userService.wxregister(username,mobilecode,password,nickname,headimgurl,openid,unionid,type,isQQ,code); return userService.wxregister(username,mobilecode,password,nickname,headimgurl,openid,unionid,type,isQQ,code,channel);
} }
@Override @Override
......
...@@ -7,10 +7,12 @@ public class RedisKey { ...@@ -7,10 +7,12 @@ public class RedisKey {
*/ */
public static final String CONSTANT_CODE_PREFIX ="cache:mobilecode:"; public static final String CONSTANT_CODE_PREFIX ="cache:mobilecode:";
/** /**
* 图片验证码 * 图片验证码
*/ */
public static final String CAPTCHA_PHONE_PREFIX = "captcha:phone:"; public static final String CAPTCHA_PHONE_PREFIX = "captcha:phone:";
public static final String CONSTANT_ERROR_PREFIX ="cache:mobileerror:";
} }
...@@ -88,12 +88,13 @@ public class AppUserRest { ...@@ -88,12 +88,13 @@ public class AppUserRest {
@RequestParam(value="username",defaultValue="")String username, @RequestParam(value="username",defaultValue="")String username,
@RequestParam(value="mobilecode",defaultValue="")String mobilecode, @RequestParam(value="mobilecode",defaultValue="")String mobilecode,
@RequestParam(value="password",defaultValue="")String password, @RequestParam(value="password",defaultValue="")String password,
@RequestParam(value="code",defaultValue="")String code @RequestParam(value="code",defaultValue="")String code,
@RequestParam(value="channel",defaultValue="1")Integer channel
){ ){
//默认昵称 //默认昵称
String nickname=SystemConfig.USER_NIKENAME_DEFAULT+(int)((Math.random()*9+1)*100000); String nickname=SystemConfig.USER_NIKENAME_DEFAULT+(int)((Math.random()*9+1)*100000);
return appPermissionService.register(username, password, SystemConfig.USER_HEADER_URL_DEFAULT,nickname, return appPermissionService.register(username, password, SystemConfig.USER_HEADER_URL_DEFAULT,nickname,
mobilecode, null, null,0,code); mobilecode, null, null,0,code,channel);
} }
...@@ -121,7 +122,8 @@ public class AppUserRest { ...@@ -121,7 +122,8 @@ public class AppUserRest {
@RequestParam(value="unionid",defaultValue="")String unionid, @RequestParam(value="unionid",defaultValue="")String unionid,
@RequestParam(value="type",defaultValue="0")Integer type, @RequestParam(value="type",defaultValue="0")Integer type,
@RequestParam(value="isQQ",defaultValue="0")Integer isQQ, @RequestParam(value="isQQ",defaultValue="0")Integer isQQ,
@RequestParam(value="code",defaultValue="")String code @RequestParam(value="code",defaultValue="")String code,
@RequestParam(value="channel",defaultValue="1")Integer channel
){ ){
if(StringUtils.isBlank(headimgurl)){ if(StringUtils.isBlank(headimgurl)){
headimgurl=SystemConfig.USER_HEADER_URL_DEFAULT; headimgurl=SystemConfig.USER_HEADER_URL_DEFAULT;
...@@ -129,7 +131,7 @@ public class AppUserRest { ...@@ -129,7 +131,7 @@ public class AppUserRest {
if(StringUtils.isBlank(nickname)){ if(StringUtils.isBlank(nickname)){
nickname=SystemConfig.USER_NIKENAME_DEFAULT+(int)((Math.random()*9+1)*100000); nickname=SystemConfig.USER_NIKENAME_DEFAULT+(int)((Math.random()*9+1)*100000);
} }
return appPermissionService.weCahtRegister(username,password,openid, unionid,nickname,headimgurl,type,mobilecode,isQQ,code); return appPermissionService.weCahtRegister(username,password,openid, unionid,nickname,headimgurl,type,mobilecode,isQQ,code,channel);
} }
/** /**
* 手机号码检测是否已绑定 * 手机号码检测是否已绑定
......
...@@ -118,6 +118,9 @@ public class AppPermissionService { ...@@ -118,6 +118,9 @@ public class AppPermissionService {
private AppUserAlipayBiz alipayBiz; private AppUserAlipayBiz alipayBiz;
private static final Integer maxNumber=5;
public AppUserInfo validate(String username, String password) { public AppUserInfo validate(String username, String password) {
AppUserInfo info = new AppUserInfo(); AppUserInfo info = new AppUserInfo();
AppUserLogin user = appUserLoginBiz.checkeUserLogin(username); AppUserLogin user = appUserLoginBiz.checkeUserLogin(username);
...@@ -249,7 +252,7 @@ public class AppPermissionService { ...@@ -249,7 +252,7 @@ public class AppPermissionService {
*/ */
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED) @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
public JSONObject register(String username, String password, String headimgurl, public JSONObject register(String username, String password, String headimgurl,
String nickname, String mobilecode, String openId, String unionid, Integer type,String code) { String nickname, String mobilecode, String openId, String unionid, Integer type,String code,Integer channel) {
log.info("register------code====="+code+"----开始进入方法---time===="+System.currentTimeMillis()/1000L); log.info("register------code====="+code+"----开始进入方法---time===="+System.currentTimeMillis()/1000L);
String activityCode = null; String activityCode = null;
// 判断参数和验证码 // 判断参数和验证码
...@@ -259,13 +262,16 @@ public class AppPermissionService { ...@@ -259,13 +262,16 @@ public class AppPermissionService {
if (StringUtils.isNotBlank(code)){ if (StringUtils.isNotBlank(code)){
//判断处理活动关键字 //判断处理活动关键字
String[] codes = code.split("_"); String[] codes = code.split("_");
if(codes.length > 1) { if(codes.length > 0) {
String userCode = codes[0]; String userCode = codes[0];
if(appUserDetailBiz.getUserByCode(userCode)==0) { if(appUserDetailBiz.getUserByCode(userCode)==0) {
return JsonResultUtil.createFailedResult(ResultCode.NOTEXIST_CODE, "邀请人不存在"); return JsonResultUtil.createFailedResult(ResultCode.NOTEXIST_CODE, "邀请人不存在");
} }
} }
} }
/*if (checkErrorNum(username)){
return JsonResultUtil.createFailedResult(ResultCode.FAILED_CODE, "验证码超过错误次数");
}*/
String redisLockKey = RedisKey.CONSTANT_CODE_PREFIX + username + mobilecode; String redisLockKey = RedisKey.CONSTANT_CODE_PREFIX + username + mobilecode;
String mobilecodeRedis = userRedisTemplate.opsForValue().get(redisLockKey) == null ? "" : userRedisTemplate.opsForValue().get(redisLockKey).toString(); String mobilecodeRedis = userRedisTemplate.opsForValue().get(redisLockKey) == null ? "" : userRedisTemplate.opsForValue().get(redisLockKey).toString();
log.info("注册接口,获取redis中的验证码:" + mobilecodeRedis+"---time===="+System.currentTimeMillis()/1000L); log.info("注册接口,获取redis中的验证码:" + mobilecodeRedis+"---time===="+System.currentTimeMillis()/1000L);
...@@ -337,6 +343,7 @@ public class AppPermissionService { ...@@ -337,6 +343,7 @@ public class AppPermissionService {
} }
//生成邀请码 长度改为8 不然重复率太高 //生成邀请码 长度改为8 不然重复率太高
rsUserDetail.setCode(ReferralCodeUtil.encode(userid)); rsUserDetail.setCode(ReferralCodeUtil.encode(userid));
rsUserDetail.setChannel(channel);
appUserDetailBiz.insertSelective(rsUserDetail); appUserDetailBiz.insertSelective(rsUserDetail);
log.info("注册:新增用户详情: " + userid+"---time===="+System.currentTimeMillis()/1000L); log.info("注册:新增用户详情: " + userid+"---time===="+System.currentTimeMillis()/1000L);
/* //绑定上下线关系 /* //绑定上下线关系
...@@ -560,7 +567,7 @@ public class AppPermissionService { ...@@ -560,7 +567,7 @@ public class AppPermissionService {
*/ */
@Transactional @Transactional
public JSONObject weCahtRegister(String username, String password, String openId, public JSONObject weCahtRegister(String username, String password, String openId,
String unionid, String nickname, String headimgurl, int type, String mobilecode, Integer isQQ,String code) { String unionid, String nickname, String headimgurl, int type, String mobilecode, Integer isQQ,String code,Integer channel) {
// 校验参数和验证码 // 校验参数和验证码
if (StringUtils.isBlank(username) || StringUtils.isBlank(mobilecode)) { if (StringUtils.isBlank(username) || StringUtils.isBlank(mobilecode)) {
return JsonResultUtil.createFailedResult(ResultCode.NULL_CODE, "参数为空"); return JsonResultUtil.createFailedResult(ResultCode.NULL_CODE, "参数为空");
...@@ -590,6 +597,7 @@ public class AppPermissionService { ...@@ -590,6 +597,7 @@ public class AppPermissionService {
// 获取到缓存的验证码后要先清空缓存对应键的值 // 获取到缓存的验证码后要先清空缓存对应键的值
userRedisTemplate.delete(redisLockKey); userRedisTemplate.delete(redisLockKey);
if (StringUtils.isBlank(mobilecodeRedis)) { if (StringUtils.isBlank(mobilecodeRedis)) {
return JsonResultUtil.createFailedResult(ResultCode.NOTEXIST_CODE, "验证码错误"); return JsonResultUtil.createFailedResult(ResultCode.NOTEXIST_CODE, "验证码错误");
} }
Long now = System.currentTimeMillis() / 1000; Long now = System.currentTimeMillis() / 1000;
...@@ -618,6 +626,7 @@ public class AppPermissionService { ...@@ -618,6 +626,7 @@ public class AppPermissionService {
userDetail.setUpdatetime(now); userDetail.setUpdatetime(now);
userDetail.setIsdel(0); userDetail.setIsdel(0);
userDetail.setCrtHost(getIp()); userDetail.setCrtHost(getIp());
userDetail.setChannel(channel);
//setCreateIPInfo(userDetail); //setCreateIPInfo(userDetail);
appUserDetailBiz.insertSelective(userDetail); appUserDetailBiz.insertSelective(userDetail);
...@@ -651,7 +660,7 @@ public class AppPermissionService { ...@@ -651,7 +660,7 @@ public class AppPermissionService {
} }
} else if (type == 2) { // 新增 } else if (type == 2) { // 新增
JSONObject register = register(username, password, headimgurl, nickname, mobilecode, JSONObject register = register(username, password, headimgurl, nickname, mobilecode,
openId, unionid, isQQ,code); openId, unionid, isQQ,code,channel);
if (register.getInteger("status") != ResultCode.SUCCESS_CODE) { if (register.getInteger("status") != ResultCode.SUCCESS_CODE) {
if (register.getInteger("status") == ResultCode.EXIST_CODE) { if (register.getInteger("status") == ResultCode.EXIST_CODE) {
return JsonResultUtil.createFailedResult(ResultCode.EXIST_CODE, "用户已存在"); return JsonResultUtil.createFailedResult(ResultCode.EXIST_CODE, "用户已存在");
...@@ -673,6 +682,34 @@ public class AppPermissionService { ...@@ -673,6 +682,34 @@ public class AppPermissionService {
} }
public void setErrorNum(String username){
String redisLockKey = RedisKey.CONSTANT_ERROR_PREFIX + username;
Integer number=getErrorNum(username,redisLockKey);
userRedisTemplate.delete(redisLockKey);
Boolean suc = userRedisTemplate.opsForValue().setIfAbsent(redisLockKey, number+1);
if (suc) {
userRedisTemplate.expire(redisLockKey, 5, TimeUnit.MINUTES);//5分钟内过期
}
}
public boolean checkErrorNum(String username){
String redisLockKey = RedisKey.CONSTANT_ERROR_PREFIX + username;
Integer number=getErrorNum(username,redisLockKey);
if (number>=maxNumber){
return true;
}
return false;
}
public Integer getErrorNum(String username,String redisLockKey){
String errorNum = userRedisTemplate.opsForValue().get(redisLockKey) == null ?"0": userRedisTemplate.opsForValue().get(redisLockKey).toString();
Integer number=0;
if (StringUtils.isNotBlank(errorNum)){
number=Integer.parseInt(errorNum);
}
return number;
}
/** /**
* 校验手机号码是否已绑定微信 * 校验手机号码是否已绑定微信
* *
......
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