代理商 注册
This commit is contained in:
@@ -1,12 +1,19 @@
|
||||
package com.sqx.modules.sys.controller;
|
||||
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.common.validator.ValidatorUtils;
|
||||
import com.sqx.common.validator.group.AddGroup;
|
||||
import com.sqx.modules.app.dao.MsgDao;
|
||||
import com.sqx.modules.app.entity.Msg;
|
||||
import com.sqx.modules.sys.entity.SysUserEntity;
|
||||
import com.sqx.modules.sys.form.SysLoginForm;
|
||||
import com.sqx.modules.sys.service.SysCaptchaService;
|
||||
import com.sqx.modules.sys.service.SysUserService;
|
||||
import com.sqx.modules.sys.service.SysUserTokenService;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.shiro.crypto.hash.Sha256Hash;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@@ -19,11 +26,14 @@ import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 登录相关
|
||||
*
|
||||
*/
|
||||
@RestController
|
||||
public class SysLoginController extends AbstractController {
|
||||
@@ -33,6 +43,8 @@ public class SysLoginController extends AbstractController {
|
||||
private SysUserTokenService sysUserTokenService;
|
||||
@Autowired
|
||||
private SysCaptchaService sysCaptchaService;
|
||||
@Autowired
|
||||
private MsgDao msgDao;
|
||||
|
||||
/**
|
||||
* 验证码
|
||||
@@ -50,6 +62,32 @@ public class SysLoginController extends AbstractController {
|
||||
IOUtils.closeQuietly(out);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/registered")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "msg", value = "验证码", dataTypeClass = String.class, paramType = "param"),
|
||||
})
|
||||
public Result registered(@RequestBody SysUserEntity user, String msg) {
|
||||
if(StringUtils.isBlank(user.getMobile())){
|
||||
return Result.error("注册失败,请输入手机号");
|
||||
}
|
||||
if(StringUtils.isBlank(msg)){
|
||||
return Result.error("注册失败,请输入验证码");
|
||||
}
|
||||
Msg msg1 = msgDao.findByPhoneAndCode(user.getMobile(), msg);
|
||||
if (msg1 == null) {
|
||||
return Result.error("验证码不正确!");
|
||||
}
|
||||
user.setIsChannel(1);
|
||||
user.setQdRate(new BigDecimal("0.01"));
|
||||
user.setStatus(1);
|
||||
user.setRoleIdList(Collections.singletonList(4L));
|
||||
ValidatorUtils.validateEntity(user, AddGroup.class);
|
||||
sysUserService.saveUser(user);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 登录
|
||||
*/
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.sqx.modules.sys.entity.SysUserEntity;
|
||||
import com.sqx.modules.sys.service.SysRoleService;
|
||||
import com.sqx.modules.sys.service.SysUserRoleService;
|
||||
import com.sqx.modules.sys.service.SysUserService;
|
||||
import com.sqx.modules.utils.InvitationCodeUtil;
|
||||
import org.apache.commons.lang.RandomStringUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.shiro.crypto.hash.Sha256Hash;
|
||||
@@ -25,7 +26,6 @@ import java.util.Map;
|
||||
|
||||
/**
|
||||
* 系统用户
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("ALL")
|
||||
@Service("sysUserService")
|
||||
@@ -80,7 +80,10 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserDao, SysUserEntity> i
|
||||
user.setPassword(new Sha256Hash(user.getPassword(), salt).toHex());
|
||||
user.setSalt(salt);
|
||||
this.save(user);
|
||||
|
||||
if (user.getIsChannel() != null && user.getIsChannel().equals(1) && StringUtils.isBlank(user.getQdCode())) {
|
||||
user.setQdCode(InvitationCodeUtil.toRegisteredCode(user.getUserId()));
|
||||
this.save(user);
|
||||
}
|
||||
//检查角色是否越权
|
||||
checkRole(user);
|
||||
|
||||
|
||||
@@ -2,30 +2,73 @@ package com.sqx.modules.utils;
|
||||
|
||||
/**
|
||||
* 邀请码生成解密工具类
|
||||
*
|
||||
* @author fang
|
||||
* @date 2020/7/8
|
||||
*/
|
||||
public class InvitationCodeUtil {
|
||||
|
||||
|
||||
/** 自定义进制(选择你想要的进制数,不能重复且最好不要0、1这些容易混淆的字符) */
|
||||
/**
|
||||
* 自定义进制(选择你想要的进制数,不能重复且最好不要0、1这些容易混淆的字符)
|
||||
*/
|
||||
private static final char[] r = new char[]{'M', 'J', 'U', 'D', 'Z', 'X', '9', 'C', '7', 'P', 'E', '8', '6', 'B', 'G', 'H', 'S', '2', '5', 'F', 'R', '4', 'Q', 'W', 'K', '3', 'V', 'Y', 'T', 'N'};
|
||||
|
||||
/** 定义一个字符用来补全邀请码长度(该字符前面是计算出来的邀请码,后面是用来补全用的) */
|
||||
/**
|
||||
* 定义一个字符用来补全邀请码长度(该字符前面是计算出来的邀请码,后面是用来补全用的)
|
||||
*/
|
||||
private static final char b = 'A';
|
||||
|
||||
/** 进制长度 */
|
||||
/**
|
||||
* 进制长度
|
||||
*/
|
||||
private static final int binLen = r.length;
|
||||
|
||||
/** 邀请码长度 */
|
||||
/**
|
||||
* 邀请码长度
|
||||
*/
|
||||
private static final int s = 6;
|
||||
|
||||
|
||||
/** 补位字符串 */
|
||||
/**
|
||||
* 补位字符串
|
||||
*/
|
||||
private static final String e = "KSLFXFR";
|
||||
|
||||
/**
|
||||
* 代理注册 补位字符串
|
||||
*/
|
||||
private static final String re = "REGISTER";
|
||||
|
||||
/**
|
||||
* 根据ID生成六位随机码
|
||||
*
|
||||
* @param id ID
|
||||
* @return 随机码
|
||||
*/
|
||||
public static String toRegisteredCode(long id) {
|
||||
char[] buf = new char[32];
|
||||
int charPos = 32;
|
||||
|
||||
while ((id / binLen) > 0) {
|
||||
int ind = (int) (id % binLen);
|
||||
buf[--charPos] = r[ind];
|
||||
id /= binLen;
|
||||
}
|
||||
buf[--charPos] = r[(int) (id % binLen)];
|
||||
String str = new String(buf, charPos, (32 - charPos));
|
||||
// 不够长度的自动补全
|
||||
if (str.length() < s) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(re.subSequence(0, s - str.length()));
|
||||
str += sb.toString();
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID生成六位随机码
|
||||
*
|
||||
* @param id ID
|
||||
* @return 随机码
|
||||
*/
|
||||
@@ -51,6 +94,7 @@ public class InvitationCodeUtil {
|
||||
|
||||
/**
|
||||
* 根据随机码生成ID
|
||||
*
|
||||
* @param code 随机码
|
||||
* @return ID
|
||||
*/
|
||||
@@ -79,8 +123,4 @@ public class InvitationCodeUtil {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user