新版仿ok交易所-后端
1
zj
19 hours ago 640ccb9229224642515527daf87f308a7aa9bdf4
trading-order-admin/src/main/java/com/yami/trading/api/controller/ApiUserController.java
@@ -86,18 +86,18 @@
    public Result login(String username, String password) {
        if (StringUtils.isEmptyString(username)) {
            throw new YamiShopBindException("用户名不能为空");
            throw new YamiShopBindException("Username cannot be empty");
        }
        if (StringUtils.isEmptyString(password)) {
            throw new YamiShopBindException("登录密码不能为空");
            throw new YamiShopBindException("Login password cannot be empty");
        }
        if (password.length() < 6 || password.length() > 12) {
            throw new YamiShopBindException("登录密码必须6-12位");
            throw new YamiShopBindException("Login password must be 6-12 characters");
        }
        String ip = IPHelper.getIpAddr();
        if (!IpUtil.isCorrectIpRegular(ip)) {
            log.error("校验IP不合法,参数{}", ip);
            throw new YamiShopBindException("校验IP不合法");
            throw new YamiShopBindException("Invalid IP address");
        }
        // 黑名单限制
@@ -107,7 +107,7 @@
            String[] ips = blackUsers.split(",");
            if(Arrays.asList(ips).contains(ip.trim())){
                throw new YamiShopBindException("当前用户在黑名单中");
                throw new YamiShopBindException("Current user is on the blacklist");
            }
        }
@@ -179,17 +179,62 @@
        if (!StringUtils.isNullOrEmpty(error)) {
            throw new YamiShopBindException(error);
        }
        if (StringUtils.isEmptyString(safeword)) {
            throw new YamiShopBindException("资金密码不能为空");
        /*if (StringUtils.isEmptyString(safeword)) {
            throw new YamiShopBindException("Fund password cannot be empty");
        }
        if (safeword.length() != 6 || !Strings.isNumber(safeword)) {
            throw new YamiShopBindException("资金密码不符合设定");
        }
            throw new YamiShopBindException("Fund password does not meet requirements");
        }*/
        //默认123456
        safeword = "123456";
        userService.saveRegister(username, password, usercode, safeword, verifcode, type);
        User secUser = userService.findByUserName(username);
        Log log = new Log();
        log.setCategory(Constants.LOG_CATEGORY_SECURITY);
        log.setLog("用户注册,ip[" + IPHelper.getIpAddr() + "]");
        log.setUserId(secUser.getUserId());
        log.setUsername(username);
        logService.save(log);
        UserInfoInTokenBO userInfoInToken = new UserInfoInTokenBO();
        userInfoInToken.setUserId(secUser.getUserId());
        userInfoInToken.setSysType(SysTypeEnum.ORDINARY.value());
        userInfoInToken.setEnabled(secUser.getStatus() == 1);
        tokenStore.deleteAllToken(String.valueOf(SysTypeEnum.ORDINARY.value()), String.valueOf(secUser.getUserId()));
        TokenInfoVO tokenInfoVO = tokenStore.storeAndGetVo(userInfoInToken);
        this.userService.online(secUser.getUserId());
        this.ipMenuService.saveIpMenuWhite(IPHelper.getIpAddr());
        Map<String, Object> data = new HashMap<String, Object>();
        data.put("token", tokenInfoVO.getAccessToken());
        data.put("username", secUser.getUserName());
        data.put("usercode", secUser.getUserName());
        secUser.setUserLastip(IPHelper.getIpAddr());
        userService.updateById(secUser);
        return Result.succeed(data);
    }
    /**
     * 重置登录账号
     */
    @RequestMapping("resetUserName")
    public Object resetUserName(String username, String password, String safeword, String verifcode, String type) {
        String userId = SecurityUtils.getUser().getUserId();
        if (StringUtils.isEmptyString(userId)) {
            throw new YamiShopBindException("Please log in first");
        }
        // 重置类型:1/手机;2/邮箱;
        String error = this.validateParam(username, verifcode, password, type);
        if (!StringUtils.isNullOrEmpty(error)) {
            throw new YamiShopBindException(error);
        }
        if (StringUtils.isEmptyString(safeword)) {
            throw new YamiShopBindException("Fund password cannot be empty");
        }
        userService.resetUserName(userId ,username, password, safeword, verifcode, type);
        User secUser = userService.findByUserName(username);
        Log log = new Log();
        log.setCategory(Constants.LOG_CATEGORY_SECURITY);
        log.setLog("用户重置登录账号,ip[" + IPHelper.getIpAddr() + "]");
        log.setUserId(secUser.getUserId());
        log.setUsername(username);
        logService.save(log);
@@ -222,7 +267,7 @@
            throw new YamiShopBindException("The fund password cannot be blank");
        }
        if (safeword.length() != 6 || !Strings.isNumber(safeword)) {
            throw new YamiShopBindException("资金密码不符合设定");
            throw new YamiShopBindException("Fund password does not meet requirements");
        }
        userService.setSafeword(SecurityUtils.getUser().getUserId(), passwordEncoder.encode(model.getSafeword()));
        return Result.succeed(null);
@@ -311,23 +356,23 @@
        String verifcode_type = request.getParameter("verifcode_type");
        String verifcode = request.getParameter("verifcode");
        if (StringUtils.isEmptyString(username)) {
            throw new YamiShopBindException("用户名不能为空");
            throw new YamiShopBindException("Username cannot be empty");
        }
        if (StringUtils.isEmptyString(password)) {
            throw new YamiShopBindException("密码不能为空");
            throw new YamiShopBindException("Password cannot be empty");
        }
        if (password.length() < 6 || password.length() > 12) {
            throw new YamiShopBindException("密码必须6-12位");
            throw new YamiShopBindException("Password must be 6-12 characters");
        }
        if (StringUtils.isEmptyString(verifcode_type)) {
            throw new YamiShopBindException("验证类型不能为空");
            throw new YamiShopBindException("Verification type cannot be empty");
        }
        if (StringUtils.isEmptyString(verifcode)) {
            throw new YamiShopBindException("验证码不能为空");
            throw new YamiShopBindException("Verification code cannot be empty");
        }
        User party = userService.findByUserName(username);
        if (null == party) {
            throw new YamiShopBindException("用户名不存在");
            throw new YamiShopBindException("Username does not exist");
        }
        // 根据验证类型获取验证key verifcode_type: 1/手机;2/邮箱;3/谷歌验证器;
        String key = "";
@@ -365,7 +410,7 @@
        // 如果是演示用户,则不判断验证码
        if (!"GUEST".contentEquals(party.getRoleName())) {
            if (!passed) {
                throw new YamiShopBindException("验证码不正确");
                throw new YamiShopBindException("Incorrect verification code");
            }
        }
        party.setLoginPassword(passwordEncoder.encode(password));
@@ -382,11 +427,11 @@
        Map<String, Object> data = new HashMap<>();
        if (StringUtils.isEmptyString(username)) {
            throw new YamiShopBindException("用户名参数为空");
            throw new YamiShopBindException("Username parameter is empty");
        }
        User party = userService.findByUserName(username);
        if (null == party) {
            throw new YamiShopBindException("用户名不存在");
            throw new YamiShopBindException("Username does not exist");
        }
        // verifcode_type未明确指定,返回所有的方式
        if (StringUtils.isEmptyString(verifcode_type) || !Arrays.asList("1", "2", "3").contains(verifcode_type)) {
@@ -484,6 +529,7 @@
                }
            }
        }
        map.put("partyId", party.getUserId());
        map.put("username", party.getUserName());
        map.put("userrole", party.getRoleName());
        map.put("usercode", party.getUserCode());
@@ -497,8 +543,9 @@
        map.put("advancedverif", party.isHighlevelAuthority());
        map.put("lastlogintime", party.getUserLasttime());
        map.put("lastloginip", party.getUserLastip());
        map.put("creditScore", party.getCreditScore());
        // 实名认证通过返回真实姓名
        if (party.isRealNameAuthority()) {
        if (party.isRealNameAuthority() && kyc != null) {
            map.put("name", kyc.getName());
        }
        if (null != kyc) {
@@ -560,16 +607,16 @@
                             String usercode) {
//         if (StringUtils.isEmptyString(phone) || !Strings.isNumber(phone) || phone.length() > 15) {
        if (StringUtils.isEmptyString(phone) || phone.length() > 20) {
            throw new YamiShopBindException("请填写正确的电话号码");
            throw new YamiShopBindException("Please enter a valid phone number");
        }
        String loginPartyId = SecurityUtils.getUser().getUserId();
        User party = userService.getById(loginPartyId);
        if (null != party.getUserMobile() && party.getUserMobile().equals(phone) && true == party.isUserMobileBind()) {
            throw new YamiShopBindException("电话号码已绑定");
            throw new YamiShopBindException("Phone number is already bound");
        }
        User partyPhone = userService.findPartyByVerifiedPhone(phone);
        if (null != partyPhone && !partyPhone.getUserId().toString().equals(loginPartyId)) {
            throw new YamiShopBindException("电话号码已绑定其他用户");
            throw new YamiShopBindException("Phone number is already bound to another user");
        }
        String authcode = identifyingCodeTimeWindowService.getAuthCode(phone);
        String bind_phone_email_ver = this.sysparaService.find("bind_phone_email_ver").getSvalue();
@@ -578,19 +625,19 @@
        if (!"GUEST".contentEquals(party.getRoleName())) {
            if ("1".contentEquals(bind_phone_email_ver)) {
                if (StringUtils.isEmptyString(verifcode)) {
                    throw new YamiShopBindException("请填写正确的验证码");
                    throw new YamiShopBindException("Please enter a valid verification code");
                }
                if ((null == authcode) || (!authcode.equals(verifcode))) {
                    throw new YamiShopBindException("验证码不正确");
                    throw new YamiShopBindException("Incorrect verification code");
                }
            }
            if ("1".contentEquals(bind_usercode)) {
                if (StringUtils.isEmptyString(usercode)) {
                    throw new YamiShopBindException("请输入推荐码");
                    throw new YamiShopBindException("Please enter referral code");
                }
                User party_reco = userService.findUserByUserCode(usercode);
                if (null == party_reco || party_reco.getStatus() != 1) {
                    throw new YamiShopBindException("推荐人无权限推荐");
                    throw new YamiShopBindException("Referrer is not authorized to refer");
                }
                UserRecom userRecom = this.userRecomService.findByPartyId(party.getUserId());
                if (null == userRecom) {
@@ -625,16 +672,16 @@
    public Result<?> save_email(String email, String verifcode) {
        if (StringUtils.isEmptyString(email) || !Strings.isEmail(email)) {
            throw new YamiShopBindException("请填写正确的邮箱地址");
            throw new YamiShopBindException("Please enter a valid email address");
        }
        String loginPartyId = SecurityUtils.getUser().getUserId();
        User party = userService.getById(loginPartyId);
        if (null != party.getUserMail() && party.getUserMail().equals(email) && true == party.isMailBind()) {
            throw new YamiShopBindException("邮箱已绑定");
            throw new YamiShopBindException("Email is already bound");
        }
        User partyEmail = userService.findPartyByVerifiedEmail(email);
        if (null != partyEmail && !partyEmail.getUserId().toString().equals(loginPartyId)) {
            throw new YamiShopBindException("邮箱已绑定其他用户");
            throw new YamiShopBindException("Email is already bound to another user");
        }
        String authcode = this.identifyingCodeTimeWindowService.getAuthCode(email);
        String bind_phone_email_ver = sysparaService.find("bind_phone_email_ver").getSvalue();
@@ -642,10 +689,10 @@
        if (!"GUEST".contentEquals(party.getRoleName())) {
            if ("1".contentEquals(bind_phone_email_ver)) {
                if (StringUtils.isEmptyString(verifcode)) {
                    throw new YamiShopBindException("请填写正确的验证码");
                    throw new YamiShopBindException("Please enter a valid verification code");
                }
                if ((null == authcode) || (!authcode.equals(verifcode))) {
                    throw new YamiShopBindException("验证码不正确");
                    throw new YamiShopBindException("Incorrect verification code");
                }
            }
        }
@@ -739,23 +786,23 @@
    public Result updateOldAndNewPsw(String old_password, String password, String re_password) {
        if (StringUtils.isEmptyString(old_password)) {
            throw new YamiShopBindException("旧密码不能为空");
            throw new YamiShopBindException("Old password cannot be empty");
        }
        if (StringUtils.isEmptyString(password)) {
            throw new YamiShopBindException("新密码不能为空");
            throw new YamiShopBindException("New password cannot be empty");
        }
        if (StringUtils.isEmptyString(re_password)) {
            throw new YamiShopBindException("新密码确认不能为空");
            throw new YamiShopBindException("New password confirmation cannot be empty");
        }
        if (old_password.length() < 6 || old_password.length() > 12 || password.length() < 6 || password.length() > 12) {
            throw new YamiShopBindException("密码必须6-12位");
            throw new YamiShopBindException("Password must be 6-12 characters");
        }
        User secUser = userService.getById(SecurityUtils.getUser().getUserId());
        if (!passwordEncoder.matches(old_password, secUser.getLoginPassword())) {
            throw new YamiShopBindException("旧密码不正确!");
            throw new YamiShopBindException("Incorrect old password!");
        }
        if (!password.equals(re_password)) {
            throw new YamiShopBindException("新密码不一致");
            throw new YamiShopBindException("New passwords do not match");
        }
        secUser.setLoginPassword(passwordEncoder.encode(re_password));
        userService.updateById(secUser);
@@ -770,16 +817,16 @@
    public Result setSafeword(String safeword, String verifcode_type, String verifcode) {
        if (StringUtils.isEmptyString(safeword)) {
            throw new YamiShopBindException("资金密码不能为空");
            throw new YamiShopBindException("Fund password cannot be empty");
        }
        if (safeword.length() != 6 || !Strings.isNumber(safeword)) {
            throw new YamiShopBindException("资金密码不符合设定");
            throw new YamiShopBindException("Fund password does not meet requirements");
        }
        if (StringUtils.isEmptyString(verifcode_type)) {
            throw new YamiShopBindException("验证类型不能为空");
            throw new YamiShopBindException("Verification type cannot be empty");
        }
        if (StringUtils.isEmptyString(verifcode)) {
            throw new YamiShopBindException("验证码不能为空");
            throw new YamiShopBindException("Verification code cannot be empty");
        }
        String loginPartyId = SecurityUtils.getUser().getUserId();
        User party = userService.getById(loginPartyId);
@@ -819,12 +866,40 @@
        // 如果是演示用户,则不判断验证码
        if (!"GUEST".contentEquals(party.getRoleName())) {
            if (!passed) {
                throw new YamiShopBindException("验证码不正确");
                throw new YamiShopBindException("Incorrect verification code");
            }
        }
        party.setSafePassword(passwordEncoder.encode(safeword));
        // 更新密码
        userService.updateById(party);
        return Result.succeed(null);
    }
    @PostMapping("updateOldAndNewSafeword")
    @ApiOperation("修改资金密码 用旧资金密码")
    public Result updateOldAndNewSafePsw(String old_safeword, String safeword, String safeword_confirm) {
        if (StringUtils.isEmptyString(old_safeword)) {
            throw new YamiShopBindException("Old fund password cannot be empty");
        }
        if (StringUtils.isEmptyString(safeword)) {
            throw new YamiShopBindException("New fund password cannot be empty");
        }
        if (StringUtils.isEmptyString(safeword_confirm)) {
            throw new YamiShopBindException("New fund password confirmation cannot be empty");
        }
        if (old_safeword.length() < 6 || old_safeword.length() > 12 || safeword.length() < 6 || safeword.length() > 12) {
            throw new YamiShopBindException("Password must be 6-12 characters");
        }
        User secUser = userService.getById(SecurityUtils.getUser().getUserId());
        if (!passwordEncoder.matches(old_safeword, secUser.getSafePassword())) {
            throw new YamiShopBindException("Incorrect old password!");
        }
        if (!safeword.equals(safeword_confirm)) {
            throw new YamiShopBindException("New passwords do not match");
        }
        secUser.setSafePassword(passwordEncoder.encode(safeword_confirm));
        userService.updateById(secUser);
        return Result.succeed(null);
    }
@@ -839,18 +914,18 @@
                                     String remark) {
        if (StringUtils.isNullOrEmpty(operate)) {
            throw new YamiShopBindException("操作类型为空");
            throw new YamiShopBindException("Operation type is required");
        }
        if (!StringUtils.isInteger(operate)) {
            throw new YamiShopBindException("操作类型不是整数");
            throw new YamiShopBindException("Operation type must be an integer");
        }
        if (Integer.valueOf(operate).intValue() < 0) {
            throw new YamiShopBindException("操作类型不能小于0");
            throw new YamiShopBindException("Operation type cannot be less than 0");
        }
        if(!StrUtil.isEmpty(remark)){
            if (remark.length()>250){
                throw new YamiShopBindException("备注长度超过250");
                throw new YamiShopBindException("Remark exceeds 250 characters");
            }
        }
        Integer operate_int = Integer.valueOf(operate);
@@ -892,10 +967,10 @@
                return Result.failed(error);
            }
            if (StringUtils.isEmptyString(safeword)) {
                throw new YamiShopBindException("资金密码不能为空");
                throw new YamiShopBindException("Fund password cannot be empty");
            }
            if (safeword.length() != 6 || !Strings.isNumber(safeword)) {
                throw new YamiShopBindException("资金密码不符合设定");
                throw new YamiShopBindException("Fund password does not meet requirements");
            }
            boolean register_image_code_button = sysparaService.find("register_image_code_button").getBoolean();
            if (register_image_code_button) {