1
zj
2025-04-17 ff2d1f5acdadc466d7e199028ef385ae8ca277e7
src/main/java/project/web/api/LocalUserController.java
@@ -392,22 +392,25 @@
      String password = request.getParameter("password").replace(" ", "");
      String re_password = request.getParameter("re_password").replace(" ", "");
      String usercode = request.getParameter("usercode");
      String phone = request.getParameter("phone");
      String verifcode = request.getParameter("verifcode");
      // 注册类型:1/手机;2/邮箱;3/用户名;
      String type = request.getParameter("type");
      // 资金密码选填,不填默认 000000
      String safeword = request.getParameter("safeword").replace(" ", "");
      String re_safeword = request.getParameter("re_safeword").replace(" ", "");
      ResultObject resultObject = new ResultObject();
      boolean lock = false;
      try {
         if (!LockFilter.add(username)) {
            throw new BusinessException("重复提交");
         }
         lock = true;
         if (StringUtils.isEmptyString(username)) {
            throw new BusinessException("用户名不能为空");
         }
@@ -427,46 +430,65 @@
         if (!password.equals(re_password)) {
            throw new BusinessException("两次输入的密码不相同");
         }
         if (StringUtils.isEmptyString(safeword)) {
            safeword = "000000";
         }
         if (StringUtils.isEmptyString(re_safeword)) {
            re_safeword = "000000";
         }
         if (safeword.length() != 6 || !Strings.isNumber(safeword)) {
            throw new BusinessException("资金密码不符合设定");
         }
         if (!safeword.equals(re_safeword)) {
            throw new BusinessException("两次输入的资金密码不相同");
         }
         if (StringUtils.isEmptyString(type) || !Arrays.asList("1", "2", "3").contains(type)) {
            throw new BusinessException("类型不能为空");
         }
         // 手机
         if ("1".equals(type)) {
            if(!isValidPhone(username)) {
               throw new BusinessException("not a valid Phone!");
            }
         }
         // 邮箱
         if ("2".equals(type)) {
            if(!isValidEmail(username)) {
               throw new BusinessException("not a valid Email!");
            }
         }
         // 用户名
         if ("3".equals(type)) {
            if(!isValidUsername(username)) {
               throw new BusinessException("not a valid username!");
            }
         }
         String ip = this.getIp();
         if (!IpUtil.isCorrectIpRegular(ip)) {
            logger.error("校验IP不合法,参数{}", ip);
            throw new BusinessException("校验IP不合法");
         }
         ResultObject resultObject1 = save_email(username, verifcode);
         if(resultObject1.getCode().equals("1")){
            return resultObject1;
         }
         LocalNormalReg reg = new LocalNormalReg();
         reg.setUsername(username);
         reg.setPassword(password);
         reg.setSafeword("000000");
         reg.setSafeword(safeword);
         reg.setReco_usercode(usercode);
         SecUser  secUser = this.secUserService.findUserByLoginName(username);
         this.localUserService.saveRegisterNoVerifcode(reg, type);
         SecUser secUser = this.secUserService.findUserByLoginName(username);
         project.log.Log log = new project.log.Log();
         log.setCategory(Constants.LOG_CATEGORY_SECURITY);
         log.setLog("用户注册,ip[" + this.getIp(getRequest()) + "]");
@@ -474,23 +496,22 @@
         log.setUsername(username);
         this.logService.saveAsyn(log);
         // 注册完直接登录返回token
         String token = this.tokenService.savePut(secUser.getPartyId(),secUser.getUsername());
         this.userService.online(secUser.getPartyId());
         this.ipMenuService.saveIpMenuWhite(this.getIp());
         Party party = this.partyService.cachePartyBy(secUser.getPartyId(), true);
         Map<String, Object> data = new HashMap<String, Object>();
         data.put("token", token);
         data.put("username", secUser.getUsername());
         data.put("usercode", party.getUsercode());
         party.setLogin_ip(this.getIp(getRequest()));
         this.partyService.update(party);
         ThreadUtils.sleep(500);
         resultObject.setData(data);
@@ -507,10 +528,49 @@
            LockFilter.remove(username);
         }
      }
      return resultObject;
   }
   public ResultObject save_email(String email ,String verifcode) {
      ResultObject resultObject = new ResultObject();
      try {
         if (StringUtils.isEmptyString(email) || !Strings.isEmail(email)) {
            throw new BusinessException("请填写正确的邮箱地址");
         }
         Party partyEmail = this.partyService.findPartyByVerifiedEmail(email);
         if (null != partyEmail) {
            throw new BusinessException("邮箱已绑定其他用户");
         }
         String authcode = this.identifyingCodeTimeWindowService.getAuthCode(email);
         if (StringUtils.isEmptyString(verifcode)) {
            throw new BusinessException("请填写正确的验证码");
         }
         if ((null == authcode) || (!authcode.equals(verifcode))) {
            resultObject.setCode("1");
            resultObject.setMsg("验证码不正确");
            return resultObject;
         }
      } catch (BusinessException e) {
         resultObject.setCode("1");
         resultObject.setMsg(e.getMessage());
      } catch (Throwable t) {
         resultObject.setCode("1");
         resultObject.setMsg("邮箱验证程序错误");
         logger.error("error:", t);
      }
      return resultObject;
   }
   /**
    * 体验用户注册
    */
@@ -631,6 +691,7 @@
      String password = request.getParameter("password").replace(" ", "");
      String re_password = request.getParameter("re_password").replace(" ", "");
      String usercode = request.getParameter("usercode");
      String verifcode = request.getParameter("verifcode");
      // 注册类型:1/手机;2/邮箱;3/用户名;
      String type = request.getParameter("type");
      // 资金密码选填,不填默认 000000
@@ -713,7 +774,10 @@
            logger.error("校验IP不合法,参数{}", ip);
            throw new BusinessException("校验IP不合法");
         }
         ResultObject resultObject1 = save_email(username, verifcode);
         if(resultObject1.getCode().equals(1)){
            return resultObject1;
         }
         LocalNormalReg reg = new LocalNormalReg();
         reg.setUsername(username);
         reg.setPassword(password);         
@@ -958,10 +1022,10 @@
      String verifcode = request.getParameter("verifcode");
      ResultObject resultObject = new ResultObject();
      resultObject = this.readSecurityContextFromSession(resultObject);
      if (!"0".equals(resultObject.getCode())) {
         return resultObject;
      }
//      resultObject = this.readSecurityContextFromSession(resultObject);
//      if (!"0".equals(resultObject.getCode())) {
//         return resultObject;
//      }
      try {
         
@@ -969,15 +1033,15 @@
            throw new BusinessException("请填写正确的邮箱地址");
         }
         String loginPartyId = this.getLoginPartyId();
         Party party = this.partyService.cachePartyBy(loginPartyId, false);
         if (null != party.getEmail() && party.getEmail().equals(email) && true == party.getEmail_authority()) {
            throw new BusinessException("邮箱已绑定");
         }
//         String loginPartyId = this.getLoginPartyId();
//         Party party = this.partyService.cachePartyBy(loginPartyId, false);
//
//         if (null != party.getEmail() && party.getEmail().equals(email) && true == party.getEmail_authority()) {
//            throw new BusinessException("邮箱已绑定");
//         }
         
         Party partyEmail = this.partyService.findPartyByVerifiedEmail(email);
         if (null != partyEmail && !partyEmail.getId().toString().equals(loginPartyId)) {
         if (null != partyEmail) {
            throw new BusinessException("邮箱已绑定其他用户");
         }
         
@@ -986,41 +1050,18 @@
         String bind_phone_email_ver = sysparaService.find("bind_phone_email_ver").getValue();
         // 如果是演示用户,则不判断验证码
         if (!"GUEST".contentEquals(party.getRolename())) {
            if ("1".contentEquals(bind_phone_email_ver)) {
               if (StringUtils.isEmptyString(verifcode)) {
                  throw new BusinessException("请填写正确的验证码");
               }
               if ((null == authcode) || (!authcode.equals(verifcode))) {
                  resultObject.setCode("1");
                  resultObject.setMsg("验证码不正确");
                  return resultObject;
               }
         if ("1".contentEquals(bind_phone_email_ver)) {
            if (StringUtils.isEmptyString(verifcode)) {
               throw new BusinessException("请填写正确的验证码");
            }
            if ((null == authcode) || (!authcode.equals(verifcode))) {
               resultObject.setCode("1");
               resultObject.setMsg("验证码不正确");
               return resultObject;
            }
         }
         // 邮箱绑定成功
         party.setEmail(email);
         party.setEmail_authority(true);
         // 获取用户系统等级:1/新注册;2/邮箱谷歌手机其中有一个已验证;3/用户实名认证; 4/用户高级认证;
         int userLevelSystem = this.partyService.getUserLevelByAuth(party);
         // 十进制个位表示系统级别:1/新注册;2/邮箱谷歌手机其中有一个已验证;3/用户实名认证;4/用户高级认证;
         // 十进制十位表示自定义级别:对应在前端显示为如VIP1 VIP2等级、黄金 白银等级;
         // 如:级别11表示:新注册的前端显示为VIP1;
         int userLevel = party.getUser_level();
         party.setUser_level(((int) Math.floor(userLevel / 10)) * 10 + userLevelSystem);
         this.partyService.update(party);
         Log log = new Log();
         log.setCategory(Constants.LOG_CATEGORY_SECURITY);
         log.setLog("用户邮箱绑定,ip[" + this.getIp(getRequest()) + "]");
         log.setPartyId(party.getId());
         log.setUsername(party.getUsername());
         logService.saveAsyn(log);
      } catch (BusinessException e) {
         resultObject.setCode("1");
         resultObject.setMsg(e.getMessage());