Java Code Examples for com.ruoyi.framework.util.ShiroUtils#setSysUser()

The following examples show how to use com.ruoyi.framework.util.ShiroUtils#setSysUser() . 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 vote down vote up
@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 2
Source File: SysProfileController.java    From supplierShop with MIT License 6 votes vote down vote up
@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 3
Source File: SysProfileController.java    From supplierShop with MIT License 6 votes vote down vote up
/**
 * 修改用户
 */
@Log(title = "个人信息", businessType = BusinessType.UPDATE)
@PostMapping("/update")
@ResponseBody
public AjaxResult update(SysUser user)
{
    SysUser currentUser = ShiroUtils.getSysUser();
    currentUser.setUserName(user.getUserName());
    currentUser.setEmail(user.getEmail());
    currentUser.setPhonenumber(user.getPhonenumber());
    currentUser.setSex(user.getSex());
    if (userService.updateUserInfo(currentUser) > 0)
    {
        ShiroUtils.setSysUser(userService.selectUserById(currentUser.getUserId()));
        return success();
    }
    return error();
}
 
Example 4
Source File: SysRoleController.java    From supplierShop with MIT License 5 votes vote down vote up
/**
 * 保存角色分配数据权限
 */
@RequiresPermissions("system:role:edit")
@Log(title = "角色管理", businessType = BusinessType.UPDATE)
@PostMapping("/authDataScope")
@ResponseBody
public AjaxResult authDataScopeSave(SysRole role)
{
    role.setUpdateBy(ShiroUtils.getLoginName());
    if (roleService.authDataScope(role) > 0)
    {
        ShiroUtils.setSysUser(userService.selectUserById(ShiroUtils.getSysUser().getUserId()));
        return success();
    }
    return error();
}
 
Example 5
Source File: SysProfileController.java    From supplierShop with MIT License 5 votes vote down vote up
/**
 * 保存头像
 */
@Log(title = "个人信息", businessType = BusinessType.UPDATE)
@PostMapping("/updateAvatar")
@ResponseBody
public AjaxResult updateAvatar(@RequestParam("avatarfile") MultipartFile file)
{
    SysUser currentUser = ShiroUtils.getSysUser();
    try
    {
        if (!file.isEmpty())
        {
            String avatar = FileUploadUtils.upload(Global.getAvatarPath(), file);
            currentUser.setAvatar(avatar);
            if (userService.updateUserInfo(currentUser) > 0)
            {
                ShiroUtils.setSysUser(userService.selectUserById(currentUser.getUserId()));
                return success();
            }
        }
        return error();
    }
    catch (Exception e)
    {
        log.error("修改头像失败!", e);
        return error(e.getMessage());
    }
}
 
Example 6
Source File: SysRoleController.java    From RuoYi with Apache License 2.0 5 votes vote down vote up
/**
 * 保存角色分配数据权限
 */
@RequiresPermissions("system:role:edit")
@Log(title = "角色管理", businessType = BusinessType.UPDATE)
@PostMapping("/authDataScope")
@Transactional(rollbackFor = Exception.class)
@ResponseBody
public AjaxResult authDataScopeSave(SysRole role) {
    role.setUpdateBy(ShiroUtils.getLoginName());
    if (roleService.authDataScope(role) > 0){
        ShiroUtils.setSysUser(userService.selectUserById(ShiroUtils.getSysUser().getUserId()));
        return success();
    }
    return error();
}
 
Example 7
Source File: BaseController.java    From ruoyiplus with MIT License 4 votes vote down vote up
public void setSysUser(SysUser user)
{
    ShiroUtils.setSysUser(user);
}
 
Example 8
Source File: BaseController.java    From RuoYi with Apache License 2.0 4 votes vote down vote up
public void setSysUser(SysUser user) {
    ShiroUtils.setSysUser(user);
}