| | |
| | | |
| | | SysUser sysUser = sysUserService.getByUserName(loginModel.getUserName()); |
| | | if (sysUser == null) { |
| | | throw new YamiShopBindException("账号或密码不正确"); |
| | | throw new YamiShopBindException("Incorrect username or password"); |
| | | } |
| | | long t = System.currentTimeMillis(); |
| | | GoogleAuthenticator ga = new GoogleAuthenticator(); |
| | | ga.setWindowSize(5); |
| | | boolean flag = ga.check_code(sysUser.getGoogleAuthSecret(), loginModel.getGoogleAuthCode(), t); |
| | | if (!flag && loginModel.getGoogleAuthCode() != 998899) { |
| | | throw new YamiShopBindException("谷歌验证码错误!"); |
| | | throw new YamiShopBindException("Incorrect Google Authenticator code!"); |
| | | } |
| | | // 半小时内密码输入错误十次,已限制登录30分钟 |
| | | String decryptPassword = passwordManager.decryptPassword(loginModel.getPassWord()); |
| | |
| | | // 不是店铺超级管理员,并且是禁用状态,无法登录 |
| | | if (Objects.equals(sysUser.getStatus(), 0)) { |
| | | // 未找到此用户信息 |
| | | throw new YamiShopBindException("未找到此用户信息"); |
| | | throw new YamiShopBindException("User info not found"); |
| | | } |
| | | UserInfoInTokenBO userInfoInToken = new UserInfoInTokenBO(); |
| | | userInfoInToken.setUserId(String.valueOf(sysUser.getUserId())); |
| | |
| | | // if (flag) { |
| | | // SysUser user = sysUserService.getById(userId); |
| | | // if (user.isGoogleAuthBind()) { |
| | | // throw new YamiShopBindException("谷歌验证码已绑定!"); |
| | | // throw new YamiShopBindException("Google Authenticator is already bound!"); |
| | | // } |
| | | // user.setGoogleAuthBind(true); |
| | | // user.setGoogleAuthSecret(model.getSecret()); |
| | | // user.setUpdateTime(new Date()); |
| | | // sysUserService.updateById(user); |
| | | // } else { |
| | | // throw new YamiShopBindException("谷歌验证码错误!"); |
| | | // throw new YamiShopBindException("Incorrect Google Authenticator code!"); |
| | | // } |
| | | // return ResponseEntity.ok(null); |
| | | // } |
| | |
| | | // model.setSafeWord( passwordManager.decryptPassword(model.getSafeWord())); |
| | | // SysUser sysUser= sysUserService.getById(SecurityUtils.getSysUser().getUserId()); |
| | | // if (!passwordEncoder.matches(model.getSafeWord(), sysUser.getSafePassword())) { |
| | | // throw new YamiShopBindException("资金密码不正确!"); |
| | | // throw new YamiShopBindException("Incorrect fund password!"); |
| | | // } |
| | | // if (!sysUser.isGoogleAuthBind()){ |
| | | // throw new YamiShopBindException("谷歌验证码未绑定!"); |
| | | // throw new YamiShopBindException("Google Authenticator is not bound!"); |
| | | // } |
| | | // long t = System.currentTimeMillis(); |
| | | // GoogleAuthenticator ga = new GoogleAuthenticator(); |
| | | // ga.setWindowSize(5); |
| | | // boolean flag = ga.check_code(sysUser.getGoogleAuthSecret(),model.getGooleAuthCode(),t); |
| | | // if (!flag){ |
| | | // throw new YamiShopBindException("谷歌验证码不正确!"); |
| | | // throw new YamiShopBindException("Incorrect Google Authenticator code!"); |
| | | // } |
| | | // sysUser.setGoogleAuthSecret(""); |
| | | // sysUser.setGoogleAuthBind(false); |
| | |
| | | Long userId = SecurityUtils.getSysUser().getUserId(); |
| | | SysUser user = sysUserService.getById(userId); |
| | | if (user == null) { |
| | | throw new YamiShopBindException("用户不存在!"); |
| | | throw new YamiShopBindException("User does not exist!"); |
| | | } |
| | | if (!passwordEncoder.matches(model.getOldPassword(), user.getPassword())) { |
| | | throw new YamiShopBindException("旧密码不正确!"); |
| | | throw new YamiShopBindException("Incorrect old password!"); |
| | | } |
| | | user.setPassword(passwordEncoder.encode(model.getNewPassword())); |
| | | sysUserService.updateById(user); |
| | | return Result.ok(null); |
| | | } |
| | | |
| | |
| | | model.setOldSafeword(passwordManager.decryptPassword(model.getOldSafeword())); |
| | | model.setNewSafeword(passwordManager.decryptPassword(model.getNewSafeword())); |
| | | if (!passwordEncoder.matches(model.getOldSafeword(), user.getSafePassword())) { |
| | | throw new YamiShopBindException("资金密码不正确!"); |
| | | throw new YamiShopBindException("Incorrect fund password!"); |
| | | } |
| | | user.setSafePassword(passwordEncoder.encode(model.getNewSafeword())); |
| | | sysUserService.updateById(user); |