Search in sources :

Example 16 with SysUser

use of com.ruoyi.system.api.domain.SysUser in project RuoYi-Cloud-Oracle by yangzongzhuan.

the class SysLoginService method login.

/**
 * 登录
 */
public LoginUser login(String username, String password) {
    // 用户名或密码为空 错误
    if (StringUtils.isAnyBlank(username, password)) {
        recordLogininfor(username, Constants.LOGIN_FAIL, "用户/密码必须填写");
        throw new ServiceException("用户/密码必须填写");
    }
    // 密码如果不在指定范围内 错误
    if (password.length() < UserConstants.PASSWORD_MIN_LENGTH || password.length() > UserConstants.PASSWORD_MAX_LENGTH) {
        recordLogininfor(username, Constants.LOGIN_FAIL, "用户密码不在指定范围");
        throw new ServiceException("用户密码不在指定范围");
    }
    // 用户名不在指定范围内 错误
    if (username.length() < UserConstants.USERNAME_MIN_LENGTH || username.length() > UserConstants.USERNAME_MAX_LENGTH) {
        recordLogininfor(username, Constants.LOGIN_FAIL, "用户名不在指定范围");
        throw new ServiceException("用户名不在指定范围");
    }
    // 查询用户信息
    R<LoginUser> userResult = remoteUserService.getUserInfo(username, SecurityConstants.INNER);
    if (R.FAIL == userResult.getCode()) {
        throw new ServiceException(userResult.getMsg());
    }
    if (StringUtils.isNull(userResult) || StringUtils.isNull(userResult.getData())) {
        recordLogininfor(username, Constants.LOGIN_FAIL, "登录用户不存在");
        throw new ServiceException("登录用户:" + username + " 不存在");
    }
    LoginUser userInfo = userResult.getData();
    SysUser user = userResult.getData().getSysUser();
    if (UserStatus.DELETED.getCode().equals(user.getDelFlag())) {
        recordLogininfor(username, Constants.LOGIN_FAIL, "对不起,您的账号已被删除");
        throw new ServiceException("对不起,您的账号:" + username + " 已被删除");
    }
    if (UserStatus.DISABLE.getCode().equals(user.getStatus())) {
        recordLogininfor(username, Constants.LOGIN_FAIL, "用户已停用,请联系管理员");
        throw new ServiceException("对不起,您的账号:" + username + " 已停用");
    }
    if (!SecurityUtils.matchesPassword(password, user.getPassword())) {
        recordLogininfor(username, Constants.LOGIN_FAIL, "用户密码错误");
        throw new ServiceException("用户不存在/密码错误");
    }
    recordLogininfor(username, Constants.LOGIN_SUCCESS, "登录成功");
    return userInfo;
}
Also used : ServiceException(com.ruoyi.common.core.exception.ServiceException) SysUser(com.ruoyi.system.api.domain.SysUser) LoginUser(com.ruoyi.system.api.model.LoginUser)

Example 17 with SysUser

use of com.ruoyi.system.api.domain.SysUser in project RuoYi-Cloud-Oracle by yangzongzhuan.

the class SysProfileController method updateProfile.

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

Example 18 with SysUser

use of com.ruoyi.system.api.domain.SysUser in project RuoYi-Cloud-Oracle by yangzongzhuan.

the class SysUserController method info.

/**
 * 获取当前用户信息
 */
@InnerAuth
@GetMapping("/info/{username}")
public R<LoginUser> info(@PathVariable("username") String username) {
    SysUser sysUser = userService.selectUserByUserName(username);
    if (StringUtils.isNull(sysUser)) {
        return R.fail("用户名或密码错误");
    }
    // 角色集合
    Set<String> roles = permissionService.getRolePermission(sysUser.getUserId());
    // 权限集合
    Set<String> permissions = permissionService.getMenuPermission(sysUser.getUserId());
    LoginUser sysUserVo = new LoginUser();
    sysUserVo.setSysUser(sysUser);
    sysUserVo.setRoles(roles);
    sysUserVo.setPermissions(permissions);
    return R.ok(sysUserVo);
}
Also used : SysUser(com.ruoyi.system.api.domain.SysUser) LoginUser(com.ruoyi.system.api.model.LoginUser) GetMapping(org.springframework.web.bind.annotation.GetMapping) InnerAuth(com.ruoyi.common.security.annotation.InnerAuth)

Example 19 with SysUser

use of com.ruoyi.system.api.domain.SysUser in project RuoYi-Cloud-Oracle by yangzongzhuan.

the class SysUserController method getInfo.

/**
 * 根据用户编号获取详细信息
 */
@RequiresPermissions("system:user:query")
@GetMapping(value = { "/", "/{userId}" })
public AjaxResult getInfo(@PathVariable(value = "userId", required = false) Long userId) {
    userService.checkUserDataScope(userId);
    AjaxResult ajax = AjaxResult.success();
    List<SysRole> roles = roleService.selectRoleAll();
    ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList()));
    ajax.put("posts", postService.selectPostAll());
    if (StringUtils.isNotNull(userId)) {
        SysUser sysUser = userService.selectUserById(userId);
        ajax.put(AjaxResult.DATA_TAG, sysUser);
        ajax.put("postIds", postService.selectPostListByUserId(userId));
        ajax.put("roleIds", sysUser.getRoles().stream().map(SysRole::getRoleId).collect(Collectors.toList()));
    }
    return ajax;
}
Also used : R(com.ruoyi.common.core.domain.R) PathVariable(org.springframework.web.bind.annotation.PathVariable) Log(com.ruoyi.common.log.annotation.Log) SysRole(com.ruoyi.system.api.domain.SysRole) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ArrayUtils(org.apache.commons.lang3.ArrayUtils) InnerAuth(com.ruoyi.common.security.annotation.InnerAuth) TableDataInfo(com.ruoyi.common.core.web.page.TableDataInfo) RequiresPermissions(com.ruoyi.common.security.annotation.RequiresPermissions) RequestBody(org.springframework.web.bind.annotation.RequestBody) ISysConfigService(com.ruoyi.system.service.ISysConfigService) BaseController(com.ruoyi.common.core.web.controller.BaseController) PutMapping(org.springframework.web.bind.annotation.PutMapping) ISysRoleService(com.ruoyi.system.service.ISysRoleService) GetMapping(org.springframework.web.bind.annotation.GetMapping) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) BusinessType(com.ruoyi.common.log.enums.BusinessType) LoginUser(com.ruoyi.system.api.model.LoginUser) ISysPermissionService(com.ruoyi.system.service.ISysPermissionService) PostMapping(org.springframework.web.bind.annotation.PostMapping) Validated(org.springframework.validation.annotation.Validated) HttpServletResponse(javax.servlet.http.HttpServletResponse) Set(java.util.Set) IOException(java.io.IOException) AjaxResult(com.ruoyi.common.core.web.domain.AjaxResult) StringUtils(com.ruoyi.common.core.utils.StringUtils) SysUser(com.ruoyi.system.api.domain.SysUser) Collectors(java.util.stream.Collectors) RestController(org.springframework.web.bind.annotation.RestController) List(java.util.List) ISysUserService(com.ruoyi.system.service.ISysUserService) MultipartFile(org.springframework.web.multipart.MultipartFile) UserConstants(com.ruoyi.common.core.constant.UserConstants) ExcelUtil(com.ruoyi.common.core.utils.poi.ExcelUtil) ISysPostService(com.ruoyi.system.service.ISysPostService) SecurityUtils(com.ruoyi.common.security.utils.SecurityUtils) AjaxResult(com.ruoyi.common.core.web.domain.AjaxResult) SysUser(com.ruoyi.system.api.domain.SysUser) SysRole(com.ruoyi.system.api.domain.SysRole) RequiresPermissions(com.ruoyi.common.security.annotation.RequiresPermissions) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 20 with SysUser

use of com.ruoyi.system.api.domain.SysUser in project RuoYi-Cloud by yangzongzhuan.

the class SysProfileController method updateProfile.

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

Aggregations

SysUser (com.ruoyi.system.api.domain.SysUser)37 LoginUser (com.ruoyi.system.api.model.LoginUser)13 Log (com.ruoyi.common.log.annotation.Log)12 ServiceException (com.ruoyi.common.core.exception.ServiceException)10 GetMapping (org.springframework.web.bind.annotation.GetMapping)8 PutMapping (org.springframework.web.bind.annotation.PutMapping)8 UserConstants (com.ruoyi.common.core.constant.UserConstants)6 R (com.ruoyi.common.core.domain.R)6 StringUtils (com.ruoyi.common.core.utils.StringUtils)6 BaseController (com.ruoyi.common.core.web.controller.BaseController)6 AjaxResult (com.ruoyi.common.core.web.domain.AjaxResult)6 BusinessType (com.ruoyi.common.log.enums.BusinessType)6 InnerAuth (com.ruoyi.common.security.annotation.InnerAuth)6 SysRole (com.ruoyi.system.api.domain.SysRole)6 ISysPermissionService (com.ruoyi.system.service.ISysPermissionService)6 ISysPostService (com.ruoyi.system.service.ISysPostService)6 ISysRoleService (com.ruoyi.system.service.ISysRoleService)6 ISysUserService (com.ruoyi.system.service.ISysUserService)6 IOException (java.io.IOException)6 Collectors (java.util.stream.Collectors)6