|
@@ -9,6 +9,7 @@ import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.NumberUtil;
|
|
|
+import cn.hutool.core.util.RandomUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.crypto.SecureUtil;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
@@ -18,6 +19,7 @@ import com.txz.cif.web.bo.UserBo;
|
|
|
import com.txz.cif.web.bo.UserInfoBO;
|
|
|
import com.txz.cif.web.para.LoginAccountParameters;
|
|
|
import com.txz.cif.web.para.MyUserParam;
|
|
|
+import com.txz.cif.web.para.RegisterAccountParameters;
|
|
|
import com.txz.cif.web.para.UserInfoForm;
|
|
|
import com.txz.cif.core.*;
|
|
|
import com.txz.cif.model.*;
|
|
@@ -178,6 +180,59 @@ public class UserApiController extends AbstractApiController {
|
|
|
return ResultGenerator.genSuccessResult(user.generator());
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ @PostMapping("/register")
|
|
|
+ @ApiOperation(value = "注册",httpMethod = "POST")
|
|
|
+ public Result register(@RequestBody RegisterAccountParameters params) {
|
|
|
+ if(params == null){
|
|
|
+ return ResultGenerator.genFailResult(ResultCode.OBJECT_IS_NULL);
|
|
|
+ }
|
|
|
+ if(StrUtil.isBlank(params.getPhone())){
|
|
|
+ return ResultGenerator.genFailResult(ResultCode.ACCOUNT_IS_NULL);
|
|
|
+ }
|
|
|
+ Condition condition = new Condition(User.class);
|
|
|
+ condition.createCriteria().andEqualTo("phoneNo",params.getPhone());
|
|
|
+ List<User> users = userService.findByCondition(condition);
|
|
|
+ if(CollUtil.isNotEmpty(users)){
|
|
|
+ return ResultGenerator.genFailResult(ResultCode.USER_IS_EXIST);
|
|
|
+ }
|
|
|
+ String salt = RandomUtil.randomString(4);
|
|
|
+ String pwd2 = SecureUtil.md5(params.getPwd() + salt).toUpperCase();
|
|
|
+ log.error("[密码]"+params.getPhone() + " :"+pwd2);
|
|
|
+
|
|
|
+ String code = getInviteCode(0);
|
|
|
+ if (code == null){
|
|
|
+ return ResultGenerator.genFailResult(ResultCode.INTERNAL_SERVER_ERROR);
|
|
|
+ }
|
|
|
+ User parent = userService.findBy("invitedCode", params.getCode());
|
|
|
+ User user = User.builder().createTime(DateUtil.date()).invitedCode(code)
|
|
|
+ .name(params.getName())
|
|
|
+ .status((byte)1) .phoneNo(params.getPhone()).pwd(pwd2).salt(salt).build();
|
|
|
+ if (parent != null){
|
|
|
+ user.setPid(parent.getId());
|
|
|
+ if (parent.getPid() != null){
|
|
|
+ user.setPpid(parent.getPid());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ user.setVipLevel(1);
|
|
|
+ userService.saveUseGeneratedKeys(user);
|
|
|
+ user.setPwd("***");
|
|
|
+ user.setSalt("***");
|
|
|
+ return ResultGenerator.genSuccessResult(user);
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getInviteCode(int index) {
|
|
|
+ if (index > 10000){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ String s = RandomUtil.randomString(8);
|
|
|
+ User inviteCode = userService.findBy("inviteCode", s);
|
|
|
+ if (inviteCode == null){
|
|
|
+ return s;
|
|
|
+ }
|
|
|
+ return getInviteCode(index + 1);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 通过旧密码设置密码
|
|
|
*
|