Search in sources :

Example 61 with LoginUser

use of com.ruoyi.common.core.domain.model.LoginUser in project hocassian-media-matrix by hokaso.

the class SysLoginController method getInfo.

/**
 * 获取用户信息
 *
 * @return 用户信息
 */
@GetMapping("getInfo")
public AjaxResult getInfo() {
    LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
    SysUser user = loginUser.getUser();
    // 角色集合
    Set<String> roles = permissionService.getRolePermission(user);
    // 权限集合
    Set<String> permissions = permissionService.getMenuPermission(user);
    AjaxResult ajax = AjaxResult.success();
    ajax.put("user", user);
    ajax.put("roles", roles);
    ajax.put("permissions", permissions);
    return ajax;
}
Also used : AjaxResult(com.ruoyi.common.core.domain.AjaxResult) SysUser(com.ruoyi.common.core.domain.entity.SysUser) LoginUser(com.ruoyi.common.core.domain.model.LoginUser) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 62 with LoginUser

use of com.ruoyi.common.core.domain.model.LoginUser in project hocassian-media-matrix by hokaso.

the class SysMenuController method list.

/**
 * 获取菜单列表
 */
@PreAuthorize("@ss.hasPermi('system:menu:list')")
@GetMapping("/list")
public AjaxResult list(SysMenu menu) {
    LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
    Long userId = loginUser.getUser().getUserId();
    List<SysMenu> menus = menuService.selectMenuList(menu, userId);
    return AjaxResult.success(menus);
}
Also used : SysMenu(com.ruoyi.common.core.domain.entity.SysMenu) LoginUser(com.ruoyi.common.core.domain.model.LoginUser) GetMapping(org.springframework.web.bind.annotation.GetMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 63 with LoginUser

use of com.ruoyi.common.core.domain.model.LoginUser in project hocassian-media-matrix by hokaso.

the class SysProfileController method avatar.

/**
 * 头像上传
 */
@Log(title = "用户头像", businessType = BusinessType.UPDATE)
@PostMapping("/avatar")
public AjaxResult avatar(@RequestParam("avatarfile") MultipartFile file) throws IOException {
    if (!file.isEmpty()) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        String avatar = FileUploadUtils.upload(RuoYiConfig.getAvatarPath(), file);
        if (userService.updateUserAvatar(loginUser.getUsername(), avatar)) {
            AjaxResult ajax = AjaxResult.success();
            ajax.put("imgUrl", avatar);
            // 更新缓存用户头像
            loginUser.getUser().setAvatar(avatar);
            tokenService.setLoginUser(loginUser);
            return ajax;
        }
    }
    return AjaxResult.error("上传图片异常,请联系管理员");
}
Also used : AjaxResult(com.ruoyi.common.core.domain.AjaxResult) LoginUser(com.ruoyi.common.core.domain.model.LoginUser) PostMapping(org.springframework.web.bind.annotation.PostMapping) Log(com.ruoyi.common.annotation.Log)

Example 64 with LoginUser

use of com.ruoyi.common.core.domain.model.LoginUser in project hocassian-media-matrix by hokaso.

the class SysProfileController method updateProfile.

/**
 * 修改用户
 */
@Log(title = "个人信息", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult updateProfile(@RequestBody SysUser user) {
    if (StringUtils.isNotEmpty(user.getPhonenumber()) && UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) {
        return AjaxResult.error("修改用户'" + user.getUserName() + "'失败,手机号码已存在");
    }
    if (StringUtils.isNotEmpty(user.getEmail()) && UserConstants.NOT_UNIQUE.equals(userService.checkEmailUnique(user))) {
        return AjaxResult.error("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在");
    }
    if (userService.updateUserProfile(user) > 0) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        // 更新缓存用户信息
        loginUser.getUser().setNickName(user.getNickName());
        loginUser.getUser().setPhonenumber(user.getPhonenumber());
        loginUser.getUser().setEmail(user.getEmail());
        loginUser.getUser().setSex(user.getSex());
        tokenService.setLoginUser(loginUser);
        return AjaxResult.success();
    }
    return AjaxResult.error("修改个人信息异常,请联系管理员");
}
Also used : LoginUser(com.ruoyi.common.core.domain.model.LoginUser) Log(com.ruoyi.common.annotation.Log) PutMapping(org.springframework.web.bind.annotation.PutMapping)

Example 65 with LoginUser

use of com.ruoyi.common.core.domain.model.LoginUser in project hocassian-media-matrix by hokaso.

the class SysProfileController method updatePwd.

/**
 * 重置密码
 */
@Log(title = "个人信息", businessType = BusinessType.UPDATE)
@PutMapping("/updatePwd")
public AjaxResult updatePwd(String oldPassword, String newPassword) {
    LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
    String userName = loginUser.getUsername();
    String password = loginUser.getPassword();
    if (!SecurityUtils.matchesPassword(oldPassword, password)) {
        return AjaxResult.error("修改密码失败,旧密码错误");
    }
    if (SecurityUtils.matchesPassword(newPassword, password)) {
        return AjaxResult.error("新密码不能与旧密码相同");
    }
    if (userService.resetUserPwd(userName, SecurityUtils.encryptPassword(newPassword)) > 0) {
        // 更新缓存用户密码
        loginUser.getUser().setPassword(SecurityUtils.encryptPassword(newPassword));
        tokenService.setLoginUser(loginUser);
        return AjaxResult.success();
    }
    return AjaxResult.error("修改密码异常,请联系管理员");
}
Also used : LoginUser(com.ruoyi.common.core.domain.model.LoginUser) Log(com.ruoyi.common.annotation.Log) PutMapping(org.springframework.web.bind.annotation.PutMapping)

Aggregations

LoginUser (com.ruoyi.common.core.domain.model.LoginUser)65 Log (com.ruoyi.common.annotation.Log)16 SysUser (com.ruoyi.common.core.domain.entity.SysUser)13 GetMapping (org.springframework.web.bind.annotation.GetMapping)10 AjaxResult (com.ruoyi.common.core.domain.AjaxResult)9 UserType (com.ruoyi.common.enums.UserType)8 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)8 ServiceException (com.ruoyi.common.exception.ServiceException)7 ArrayList (java.util.ArrayList)7 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)7 PutMapping (org.springframework.web.bind.annotation.PutMapping)7 UserPasswordNotMatchException (com.ruoyi.common.exception.user.UserPasswordNotMatchException)5 DataColumn (com.ruoyi.common.annotation.DataColumn)4 RoleDTO (com.ruoyi.common.core.domain.dto.RoleDTO)4 SysMenu (com.ruoyi.common.core.domain.entity.SysMenu)4 CaptchaException (com.ruoyi.common.exception.user.CaptchaException)4 CaptchaExpireException (com.ruoyi.common.exception.user.CaptchaExpireException)4 Claims (io.jsonwebtoken.Claims)4 BadCredentialsException (org.springframework.security.authentication.BadCredentialsException)4 Authentication (org.springframework.security.core.Authentication)4