| | |
| | | */ |
| | | @PostMapping("setSafeword") |
| | | @ApiOperation("修改资金密码 用验证码") |
| | | public Result setSafeword(String safeword, String verifcode_type, String verifcode) { |
| | | public Result setSafeword(String safeword, String verifcode_type, String verifcode, String odl_safeword) { |
| | | |
| | | if (StringUtils.isEmptyString(safeword)) { |
| | | throw new YamiShopBindException("资金密码不能为空"); |
| | |
| | | if (StringUtils.isEmptyString(verifcode_type)) { |
| | | throw new YamiShopBindException("验证类型不能为空"); |
| | | } |
| | | if (StringUtils.isEmptyString(verifcode)) { |
| | | throw new YamiShopBindException("验证码不能为空"); |
| | | if (StringUtils.isEmptyString(odl_safeword)) { |
| | | throw new YamiShopBindException("旧密码不能为空"); |
| | | } |
| | | // if (StringUtils.isEmptyString(verifcode)) { |
| | | // throw new YamiShopBindException("验证码不能为空"); |
| | | // } |
| | | String loginPartyId = SecurityUtils.getUser().getUserId(); |
| | | User party = userService.getById(loginPartyId); |
| | | // 根据验证类型获取验证key verifcode_type: 1/手机;2/邮箱;3/谷歌验证器; |
| | | String key = ""; |
| | | String errMsg = ""; |
| | | if ("1".equals(verifcode_type)) { |
| | | key = StringUtils.isEmptyString(party.getUserMobile()) || false == party.isUserMobileBind() ? "" : party.getUserMobile(); |
| | | errMsg = "未绑定手机号"; |
| | | } else if ("2".equals(verifcode_type)) { |
| | | key = StringUtils.isEmptyString(party.getUserMail()) || false == party.isMailBind() ? "" : party.getUserMail(); |
| | | errMsg = "未绑定邮箱"; |
| | | } else if ("3".equals(verifcode_type)) { |
| | | key = StringUtils.isEmptyString(party.getGoogleAuthSecret()) || false == party.isGoogleAuthBind() ? "" : party.getGoogleAuthSecret(); |
| | | errMsg = "未绑定谷歌验证器"; |
| | | } |
| | | if (StringUtils.isEmptyString(key)) { |
| | | throw new YamiShopBindException(errMsg); |
| | | } |
| | | // String key = ""; |
| | | // String errMsg = ""; |
| | | // if ("1".equals(verifcode_type)) { |
| | | // key = StringUtils.isEmptyString(party.getUserMobile()) || false == party.isUserMobileBind() ? "" : party.getUserMobile(); |
| | | // errMsg = "未绑定手机号"; |
| | | // } else if ("2".equals(verifcode_type)) { |
| | | // key = StringUtils.isEmptyString(party.getUserMail()) || false == party.isMailBind() ? "" : party.getUserMail(); |
| | | // errMsg = "未绑定邮箱"; |
| | | // } else if ("3".equals(verifcode_type)) { |
| | | // key = StringUtils.isEmptyString(party.getGoogleAuthSecret()) || false == party.isGoogleAuthBind() ? "" : party.getGoogleAuthSecret(); |
| | | // errMsg = "未绑定谷歌验证器"; |
| | | // } |
| | | // if (StringUtils.isEmptyString(key)) { |
| | | // throw new YamiShopBindException(errMsg); |
| | | // } |
| | | // 验证 |
| | | boolean passed = false; |
| | | if ("1".equals(verifcode_type) || "2".equals(verifcode_type)) { |
| | | String authcode = this.identifyingCodeTimeWindowService.getAuthCode(key); |
| | | if ((null != authcode) && (authcode.equals(verifcode))) { |
| | | passed = true; |
| | | this.identifyingCodeTimeWindowService.delAuthCode(key); |
| | | } |
| | | } else if ("3".equals(verifcode_type)) { |
| | | long t = System.currentTimeMillis(); |
| | | GoogleAuthenticator ga = new GoogleAuthenticator(); |
| | | ga.setWindowSize(5); |
| | | boolean flag = ga.check_code(party.getGoogleAuthSecret(), Long.valueOf(verifcode), t); |
| | | if (flag) { |
| | | passed = true; |
| | | } |
| | | } |
| | | // boolean passed = false; |
| | | // if ("1".equals(verifcode_type) || "2".equals(verifcode_type)) { |
| | | // String authcode = this.identifyingCodeTimeWindowService.getAuthCode(key); |
| | | // if ((null != authcode) && (authcode.equals(verifcode))) { |
| | | // passed = true; |
| | | // this.identifyingCodeTimeWindowService.delAuthCode(key); |
| | | // } |
| | | // } else if ("3".equals(verifcode_type)) { |
| | | // long t = System.currentTimeMillis(); |
| | | // GoogleAuthenticator ga = new GoogleAuthenticator(); |
| | | // ga.setWindowSize(5); |
| | | // boolean flag = ga.check_code(party.getGoogleAuthSecret(), Long.valueOf(verifcode), t); |
| | | // if (flag) { |
| | | // passed = true; |
| | | // } |
| | | // } |
| | | // 如果是演示用户,则不判断验证码 |
| | | if (!"GUEST".contentEquals(party.getRoleName())) { |
| | | if (!passed) { |
| | | throw new YamiShopBindException("验证码不正确"); |
| | | } |
| | | // if (!"GUEST".contentEquals(party.getRoleName())) { |
| | | // if (!passed) { |
| | | // throw new YamiShopBindException("验证码不正确"); |
| | | // } |
| | | // } |
| | | if(userService.checkLoginSafeword(party.getUserId(), odl_safeword)){ |
| | | party.setSafePassword(passwordEncoder.encode(safeword)); |
| | | // 更新密码 |
| | | userService.updateById(party); |
| | | return Result.succeed(null); |
| | | }else { |
| | | throw new YamiShopBindException("旧密码不正确"); |
| | | } |
| | | party.setSafePassword(passwordEncoder.encode(safeword)); |
| | | // 更新密码 |
| | | userService.updateById(party); |
| | | return Result.succeed(null); |
| | | |
| | | } |
| | | |
| | | /** |