Java Code Examples for com.ruoyi.system.domain.SysUser#setPassword()
The following examples show how to use
com.ruoyi.system.domain.SysUser#setPassword() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SysUserController.java From supplierShop with MIT License | 6 votes |
/** * 新增保存用户 */ @RequiresPermissions("system:user:add") @Log(title = "用户管理", businessType = BusinessType.INSERT) @PostMapping("/add") @ResponseBody public AjaxResult addSave(@Validated SysUser user) { if (UserConstants.USER_NAME_NOT_UNIQUE.equals(userService.checkLoginNameUnique(user.getLoginName()))) { return error("新增用户'" + user.getLoginName() + "'失败,登录账号已存在"); } else if (UserConstants.USER_PHONE_NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) { return error("新增用户'" + user.getLoginName() + "'失败,手机号码已存在"); } else if (UserConstants.USER_EMAIL_NOT_UNIQUE.equals(userService.checkEmailUnique(user))) { return error("新增用户'" + user.getLoginName() + "'失败,邮箱账号已存在"); } user.setSalt(ShiroUtils.randomSalt()); user.setPassword(passwordService.encryptPassword(user.getLoginName(), user.getPassword(), user.getSalt())); user.setCreateBy(ShiroUtils.getLoginName()); return toAjax(userService.insertUser(user)); }
Example 2
Source File: SysUserController.java From supplierShop with MIT License | 6 votes |
@RequiresPermissions("system:user:resetPwd") @Log(title = "重置密码", businessType = BusinessType.UPDATE) @PostMapping("/resetPwd") @ResponseBody public AjaxResult resetPwdSave(SysUser user) { user.setSalt(ShiroUtils.randomSalt()); user.setPassword(passwordService.encryptPassword(user.getLoginName(), user.getPassword(), user.getSalt())); if (userService.resetUserPwd(user) > 0) { if (ShiroUtils.getUserId() == user.getUserId()) { ShiroUtils.setSysUser(userService.selectUserById(user.getUserId())); } return success(); } return error(); }
Example 3
Source File: SysProfileController.java From supplierShop with MIT License | 6 votes |
@Log(title = "重置密码", businessType = BusinessType.UPDATE) @PostMapping("/resetPwd") @ResponseBody public AjaxResult resetPwd(String oldPassword, String newPassword) { SysUser user = ShiroUtils.getSysUser(); if (StringUtils.isNotEmpty(newPassword) && passwordService.matches(user, oldPassword)) { user.setSalt(ShiroUtils.randomSalt()); user.setPassword(passwordService.encryptPassword(user.getLoginName(), newPassword, user.getSalt())); if (userService.resetUserPwd(user) > 0) { ShiroUtils.setSysUser(userService.selectUserById(user.getUserId())); return success(); } return error(); } else { return error("修改密码失败,旧密码错误"); } }
Example 4
Source File: SysUserController.java From ruoyiplus with MIT License | 6 votes |
/** * 新增保存用户 */ @RequiresPermissions("system:user:add") @Log(title = "用户管理", businessType = BusinessType.INSERT) @PostMapping("/add") @Transactional(rollbackFor = Exception.class) @ResponseBody public AjaxResult addSave(SysUser user) { if (StringUtils.isNotNull(user.getUserId()) && SysUser.isAdmin(user.getUserId())) { return error("不允许修改超级管理员用户"); } user.setSalt(ShiroUtils.randomSalt()); user.setPassword(passwordService.encryptPassword(user.getLoginName(), user.getPassword(), user.getSalt())); user.setCreateBy(ShiroUtils.getLoginName()); return toAjax(userService.insertUser(user)); }
Example 5
Source File: SysProfileController.java From ruoyiplus with MIT License | 6 votes |
@Log(title = "重置密码", businessType = BusinessType.UPDATE) @PostMapping("/resetPwd") @ResponseBody public AjaxResult resetPwd(String oldPassword, String newPassword) { SysUser user = getSysUser(); if (StringUtils.isNotEmpty(newPassword) && passwordService.matches(user, oldPassword)) { user.setSalt(ShiroUtils.randomSalt()); user.setPassword(passwordService.encryptPassword(user.getLoginName(), newPassword, user.getSalt())); if (userService.resetUserPwd(user) > 0) { setSysUser(userService.selectUserById(user.getUserId())); return success(); } return error(); } else { return error("修改密码失败,旧密码错误"); } }
Example 6
Source File: SysUserController.java From RuoYi with Apache License 2.0 | 6 votes |
@ApiOperation("新增用户") @ApiImplicitParam(name = "user", value = "新增用户信息", dataType = "SysUser") @RequiresPermissions("system:user:add") @Log(title = "用户管理", businessType = BusinessType.INSERT) @PostMapping("/add") @Transactional(rollbackFor = Exception.class) @ResponseBody public AjaxResult addSave(SysUser user) { if (ObjectUtil.isNotNull(user.getUserId()) && SysUser.isAdmin(user.getUserId())) { return error("不允许修改超级管理员用户"); } if (UserConstants.USER_NAME_NOT_UNIQUE.equals(userService.checkLoginNameUnique(user.getLoginName()))){ return error("保存用户'" + user.getLoginName() + "'失败,账号已存在"); } user.setSalt(ShiroUtils.randomSalt()); user.setPassword(passwordService.encryptPassword(user.getLoginName(), user.getPassword(), user.getSalt())); user.setCreateBy(ShiroUtils.getLoginName()); return toAjax(userService.insertUser(user)); }
Example 7
Source File: SysUserController.java From ruoyiplus with MIT License | 5 votes |
@RequiresPermissions("system:user:resetPwd") @Log(title = "重置密码", businessType = BusinessType.UPDATE) @PostMapping("/resetPwd") @ResponseBody public AjaxResult resetPwdSave(SysUser user) { user.setSalt(ShiroUtils.randomSalt()); user.setPassword(passwordService.encryptPassword(user.getLoginName(), user.getPassword(), user.getSalt())); return toAjax(userService.resetUserPwd(user)); }
Example 8
Source File: SysUserController.java From RuoYi with Apache License 2.0 | 5 votes |
@ApiOperation("重置密码") @ApiImplicitParam(name = "user", value = "修改用户信息", dataType = "SysUser") @RequiresPermissions("system:user:resetPwd") @Log(title = "重置密码", businessType = BusinessType.UPDATE) @PostMapping("/resetPwd") @ResponseBody public AjaxResult resetPwdSave(SysUser user) { user.setSalt(ShiroUtils.randomSalt()); user.setPassword(passwordService.encryptPassword(user.getLoginName(), user.getPassword(), user.getSalt())); return toAjax(userService.resetUserPwd(user)); }
Example 9
Source File: SysProfileController.java From RuoYi with Apache License 2.0 | 5 votes |
@Log(title = "重置密码", businessType = BusinessType.UPDATE) @PostMapping("/resetPwd") @ResponseBody public AjaxResult resetPwd(String oldPassword, String newPassword, SysUser user) { if(StrUtil.isNotEmpty(newPassword) && passwordService.matches(user, oldPassword)){ user.setSalt(ShiroUtils.randomSalt()); user.setPassword(passwordService.encryptPassword(user.getLoginName(), newPassword, user.getSalt())); if (userService.resetUserPwd(user) > 0) { setSysUser(userService.selectUserById(user.getUserId())); return success(); } return error(); } return error("修改密码失败,旧密码错误"); }
Example 10
Source File: SysUserServiceImpl.java From supplierShop with MIT License | 4 votes |
/** * 导入用户数据 * * @param userList 用户数据列表 * @param isUpdateSupport 是否更新支持,如果已存在,则进行更新数据 * @param operName 操作用户 * @return 结果 */ @Override public String importUser(List<SysUser> userList, Boolean isUpdateSupport, String operName) { if (StringUtils.isNull(userList) || userList.size() == 0) { throw new BusinessException("导入用户数据不能为空!"); } int successNum = 0; int failureNum = 0; StringBuilder successMsg = new StringBuilder(); StringBuilder failureMsg = new StringBuilder(); String password = configService.selectConfigByKey("sys.user.initPassword"); for (SysUser user : userList) { try { // 验证是否存在这个用户 SysUser u = userMapper.selectUserByLoginName(user.getLoginName()); if (StringUtils.isNull(u)) { user.setPassword(Md5Utils.hash(user.getLoginName() + password)); user.setCreateBy(operName); this.insertUser(user); successNum++; successMsg.append("<br/>" + successNum + "、账号 " + user.getLoginName() + " 导入成功"); } else if (isUpdateSupport) { user.setUpdateBy(operName); this.updateUser(user); successNum++; successMsg.append("<br/>" + successNum + "、账号 " + user.getLoginName() + " 更新成功"); } else { failureNum++; failureMsg.append("<br/>" + failureNum + "、账号 " + user.getLoginName() + " 已存在"); } } catch (Exception e) { failureNum++; String msg = "<br/>" + failureNum + "、账号 " + user.getLoginName() + " 导入失败:"; failureMsg.append(msg + e.getMessage()); log.error(msg, e); } } if (failureNum > 0) { failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:"); throw new BusinessException(failureMsg.toString()); } else { successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:"); } return successMsg.toString(); }
Example 11
Source File: SysUserServiceImpl.java From ruoyiplus with MIT License | 4 votes |
/** * 导入用户数据 * * @param userList 用户数据列表 * @param isUpdateSupport 是否更新支持,如果已存在,则进行更新数据 * @param operName 操作用户 * @return 结果 */ @Override public String importUser(List<SysUser> userList, Boolean isUpdateSupport, String operName) { if (StringUtils.isNull(userList) || userList.size() == 0) { throw new BusinessException("导入用户数据不能为空!"); } int successNum = 0; int failureNum = 0; StringBuilder successMsg = new StringBuilder(); StringBuilder failureMsg = new StringBuilder(); String password = configService.selectConfigByKey("sys.user.initPassword"); for (SysUser user : userList) { try { // 验证是否存在这个用户 SysUser u = userMapper.selectUserByLoginName(user.getLoginName()); if (StringUtils.isNull(u)) { user.setPassword(Md5Utils.hash(user.getLoginName() + password)); user.setCreateBy(operName); this.insertUser(user); successNum++; successMsg.append("<br/>" + successNum + "、账号 " + user.getLoginName() + " 导入成功"); } else if (isUpdateSupport) { user.setUpdateBy(operName); this.updateUser(user); successNum++; successMsg.append("<br/>" + successNum + "、账号 " + user.getLoginName() + " 更新成功"); } else { failureNum++; failureMsg.append("<br/>" + failureNum + "、账号 " + user.getLoginName() + " 已存在"); } } catch (Exception e) { failureNum++; String msg = "<br/>" + failureNum + "、账号 " + user.getLoginName() + " 导入失败:"; failureMsg.append(msg + e.getMessage()); log.error(msg, e); } } if (failureNum > 0) { failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:"); throw new BusinessException(failureMsg.toString()); } else { successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:"); } return successMsg.toString(); }