| | |
| | | // 开源版代码,禁止用户修改admin 的账号密码 |
| | | // 正式使用时,删除此部分代码即可 |
| | | if (Objects.equals(1L, param.getId()) && StrUtil.isNotBlank(param.getNewPassword())) { |
| | | throw new YamiShopBindException("禁止修改admin的账号密码"); |
| | | throw new YamiShopBindException("Modifying admin account password is not allowed"); |
| | | } |
| | | SysUser sysUser = sysUserService.getSysUserById(param.getId()); |
| | | if (sysUser==null){ |
| | | throw new YamiShopBindException("参数错误!"); |
| | | throw new YamiShopBindException("Invalid parameters!"); |
| | | } |
| | | String password = passwordManager.decryptPassword(param.getPassword()); |
| | | if (!passwordEncoder.matches(password, sysUser.getPassword())) { |
| | |
| | | public ResponseEntity<String> updateSafePassword(@RequestBody @Valid UpdateSafePasswordDto param) { |
| | | SysUser sysUser = sysUserService.getSysUserById(param.getId()); |
| | | if (sysUser == null) { |
| | | throw new YamiShopBindException("参数错误!"); |
| | | throw new YamiShopBindException("Invalid parameters!"); |
| | | } |
| | | String safePassword = passwordManager.decryptPassword(param.getSafePassword()); |
| | | sysUser.setSafePassword(passwordEncoder.encode(safePassword)); |
| | |
| | | public Result<String> updateGoogleAuth(@RequestBody @Valid UpdateGoogleAuthDto param) { |
| | | SysUser sysUser = sysUserService.getSysUserById(param.getId()); |
| | | if (sysUser == null) { |
| | | throw new YamiShopBindException("参数错误!"); |
| | | throw new YamiShopBindException("Invalid parameters!"); |
| | | } |
| | | SysUser rootSysUser = sysUserService.getSysUserById(SecurityUtils.getSysUser().getUserId()); |
| | | long t = System.currentTimeMillis(); |
| | |
| | | boolean flag = ga.check_code(rootSysUser.getGoogleAuthSecret(), Long.valueOf(param.getRootGoogleAuthCode()), t); |
| | | if (flag) { |
| | | if (sysUser.isGoogleAuthBind()) { |
| | | throw new YamiShopBindException("谷歌验证码已绑定!"); |
| | | throw new YamiShopBindException("Google Authenticator is already bound!"); |
| | | } |
| | | boolean userFlag = ga.check_code(param.getSecret(), Long.valueOf(param.getGoogleAuthCode()), t); |
| | | if (!flag && Long.valueOf(param.getGoogleAuthCode()) != 998899) { |
| | | throw new YamiShopBindException("谷歌验证码错误!"); |
| | | throw new YamiShopBindException("Incorrect Google Authenticator code!"); |
| | | } |
| | | sysUser.setGoogleAuthBind(true); |
| | | sysUser.setGoogleAuthSecret(param.getSecret()); |
| | | sysUser.setUpdateTime(new Date()); |
| | | sysUserService.updateById(sysUser); |
| | | } else { |
| | | throw new YamiShopBindException("超级谷歌验证码错误!"); |
| | | throw new YamiShopBindException("Incorrect super admin Google Authenticator code!"); |
| | | } |
| | | return Result.succeed(); |
| | | } |
| | |
| | | public Result unbindingGoogleAuth(@RequestBody @Valid UnbindingGoogleAuthModel param) { |
| | | SysUser sysUser = sysUserService.getSysUserById(param.getId()); |
| | | if (sysUser == null) { |
| | | throw new YamiShopBindException("参数错误!"); |
| | | throw new YamiShopBindException("Invalid parameters!"); |
| | | } |
| | | SysUser rootSysUser = sysUserService.getSysUserById(SecurityUtils.getSysUser().getUserId()); |
| | | long t = System.currentTimeMillis(); |
| | |
| | | boolean flag = ga.check_code(rootSysUser.getGoogleAuthSecret(), Long.valueOf(param.getRootGoogleAuthCode()), t); |
| | | if (flag) { |
| | | if (!sysUser.isGoogleAuthBind()) { |
| | | throw new YamiShopBindException("谷歌验证码未绑定,无需解绑!"); |
| | | throw new YamiShopBindException("Google Authenticator is not bound, no need to unbind!"); |
| | | } |
| | | sysUser.setGoogleAuthBind(false); |
| | | sysUser.setGoogleAuthSecret(""); |
| | | sysUser.setUpdateTime(new Date()); |
| | | sysUserService.updateById(sysUser); |
| | | } else { |
| | | throw new YamiShopBindException("超级谷歌验证码错误!"); |
| | | throw new YamiShopBindException("Incorrect super admin Google Authenticator code!"); |
| | | } |
| | | return Result.succeed(); |
| | | } |
| | |
| | | SysUser user = sysUserService.getSysUserById(userId); |
| | | user.setUserId(null); |
| | | // if (!Objects.equals(user.getShopId(), SecurityUtils.getSysUser().getShopId())) { |
| | | // throw new YamiShopBindException("没有权限获取该用户信息"); |
| | | // throw new YamiShopBindException("No permission to access this user info"); |
| | | // } |
| | | //获取用户所属的角色列表 |
| | | List<Long> roleIdList = sysRoleService.listRoleIdByUserId(userId); |
| | |
| | | public ResponseEntity<String> update(@Valid @RequestBody UpdateSysUserDto dto) { |
| | | SysUser dbUser = sysUserService.getSysUserById(dto.getId()); |
| | | if (dbUser == null) { |
| | | throw new YamiShopBindException("参数错误!"); |
| | | throw new YamiShopBindException("Invalid parameters!"); |
| | | } |
| | | // SysUser dbUserNameInfo = sysUserService.getByUserName(dto.getUsername()); |
| | | // if (dbUserNameInfo != null && !Objects.equals(dbUserNameInfo.getUserId(),dto.getUserId())) { |
| | |
| | | // 正式使用时,删除此部分代码即可 |
| | | boolean is = Objects.equals(1L, dbUser.getUserId()) && !StrUtil.equals("admin", dbUser.getUsername()); |
| | | if (is) { |
| | | throw new YamiShopBindException("禁止修改admin的账号密码"); |
| | | throw new YamiShopBindException("Modifying admin account password is not allowed"); |
| | | } |
| | | if (Objects.equals(1L, dbUser.getUserId()) && dbUser.getStatus() == 0) { |
| | | throw new YamiShopBindException("admin用户不可以被禁用"); |
| | | throw new YamiShopBindException("Admin user cannot be disabled"); |
| | | } |
| | | dbUser.setRemarks(dto.getRemarks()); |
| | | dbUser.setEmail(dto.getEmail()); |