Search in sources :

Example 51 with SysUser

use of com.ruoyi.common.core.domain.entity.SysUser in project RuoYi-Vue-Plus by JavaLionLi.

the class SysLoginController method getInfo.

/**
 * 获取用户信息
 *
 * @return 用户信息
 */
@ApiOperation("获取用户信息")
@GetMapping("getInfo")
public R<Map<String, Object>> getInfo() {
    SysUser user = userService.selectUserById(LoginHelper.getUserId());
    // 角色集合
    Set<String> roles = permissionService.getRolePermission(user);
    // 权限集合
    Set<String> permissions = permissionService.getMenuPermission(user);
    Map<String, Object> ajax = new HashMap<>();
    ajax.put("user", user);
    ajax.put("roles", roles);
    ajax.put("permissions", permissions);
    return R.ok(ajax);
}
Also used : SysUser(com.ruoyi.common.core.domain.entity.SysUser) HashMap(java.util.HashMap) GetMapping(org.springframework.web.bind.annotation.GetMapping) ApiOperation(io.swagger.annotations.ApiOperation)

Example 52 with SysUser

use of com.ruoyi.common.core.domain.entity.SysUser in project RuoYi-Vue-Plus by JavaLionLi.

the class SysUserServiceImpl method deleteUserByIds.

/**
 * 批量删除用户信息
 *
 * @param userIds 需要删除的用户ID
 * @return 结果
 */
@Override
@Transactional(rollbackFor = Exception.class)
public int deleteUserByIds(Long[] userIds) {
    for (Long userId : userIds) {
        checkUserAllowed(new SysUser(userId));
        checkUserDataScope(userId);
    }
    List<Long> ids = Arrays.asList(userIds);
    // 删除用户与角色关联
    userRoleMapper.delete(new LambdaQueryWrapper<SysUserRole>().in(SysUserRole::getUserId, ids));
    // 删除用户与岗位表
    userPostMapper.delete(new LambdaQueryWrapper<SysUserPost>().in(SysUserPost::getUserId, ids));
    return baseMapper.deleteBatchIds(ids);
}
Also used : SysUser(com.ruoyi.common.core.domain.entity.SysUser) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) Transactional(org.springframework.transaction.annotation.Transactional)

Example 53 with SysUser

use of com.ruoyi.common.core.domain.entity.SysUser in project RuoYi-Vue-Plus by JavaLionLi.

the class SysRegisterService method register.

/**
 * 注册
 */
public void register(RegisterBody registerBody) {
    HttpServletRequest request = ServletUtils.getRequest();
    String username = registerBody.getUsername();
    String password = registerBody.getPassword();
    // 校验用户类型是否存在
    String userType = UserType.getUserType(registerBody.getUserType()).getUserType();
    boolean captchaOnOff = configService.selectCaptchaOnOff();
    // 验证码开关
    if (captchaOnOff) {
        validateCaptcha(username, registerBody.getCode(), registerBody.getUuid(), request);
    }
    if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(username))) {
        throw new UserException("user.register.save.error", username);
    }
    SysUser sysUser = new SysUser();
    sysUser.setUserName(username);
    sysUser.setNickName(username);
    sysUser.setPassword(BCrypt.hashpw(password));
    sysUser.setUserType(userType);
    boolean regFlag = userService.registerUser(sysUser);
    if (!regFlag) {
        throw new UserException("user.register.error");
    }
    asyncService.recordLogininfor(username, Constants.REGISTER, MessageUtils.message("user.register.success"), request);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SysUser(com.ruoyi.common.core.domain.entity.SysUser) UserException(com.ruoyi.common.exception.user.UserException)

Example 54 with SysUser

use of com.ruoyi.common.core.domain.entity.SysUser in project RuoYi-Vue-Plus by JavaLionLi.

the class SysUserImportListener method invoke.

@Override
public void invoke(SysUserImportVo userVo, AnalysisContext context) {
    SysUser user = this.userService.selectUserByUserName(userVo.getUserName());
    try {
        // 验证是否存在这个用户
        if (ObjectUtil.isNull(user)) {
            user = BeanUtil.toBean(userVo, SysUser.class);
            ValidatorUtils.validate(user);
            user.setPassword(password);
            user.setCreateBy(operName);
            userService.insertUser(user);
            successNum++;
            successMsg.append("<br/>").append(successNum).append("、账号 ").append(user.getUserName()).append(" 导入成功");
        } else if (isUpdateSupport) {
            ValidatorUtils.validate(user);
            user.setUpdateBy(operName);
            userService.updateUser(user);
            successNum++;
            successMsg.append("<br/>").append(successNum).append("、账号 ").append(user.getUserName()).append(" 更新成功");
        } else {
            failureNum++;
            failureMsg.append("<br/>").append(failureNum).append("、账号 ").append(user.getUserName()).append(" 已存在");
        }
    } catch (Exception e) {
        failureNum++;
        String msg = "<br/>" + failureNum + "、账号 " + user.getUserName() + " 导入失败:";
        failureMsg.append(msg).append(e.getMessage());
        log.error(msg, e);
    }
}
Also used : SysUser(com.ruoyi.common.core.domain.entity.SysUser) ServiceException(com.ruoyi.common.exception.ServiceException)

Example 55 with SysUser

use of com.ruoyi.common.core.domain.entity.SysUser in project RuoYi-Flowable-Plus by KonBAI-Q.

the class SysProfileController method updatePwd.

/**
 * 重置密码
 */
@ApiOperation("重置密码")
@ApiImplicitParams({ @ApiImplicitParam(name = "oldPassword", value = "旧密码", paramType = "query", dataTypeClass = String.class), @ApiImplicitParam(name = "newPassword", value = "新密码", paramType = "query", dataTypeClass = String.class) })
@Log(title = "个人信息", businessType = BusinessType.UPDATE)
@PutMapping("/updatePwd")
public R<Void> updatePwd(String oldPassword, String newPassword) {
    SysUser user = userService.selectUserById(LoginHelper.getUserId());
    String userName = user.getUserName();
    String password = user.getPassword();
    if (!BCrypt.checkpw(oldPassword, password)) {
        return R.fail("修改密码失败,旧密码错误");
    }
    if (BCrypt.checkpw(newPassword, password)) {
        return R.fail("新密码不能与旧密码相同");
    }
    if (userService.resetUserPwd(userName, BCrypt.hashpw(newPassword)) > 0) {
        return R.ok();
    }
    return R.fail("修改密码异常,请联系管理员");
}
Also used : SysUser(com.ruoyi.common.core.domain.entity.SysUser) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) Log(com.ruoyi.common.annotation.Log) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

SysUser (com.ruoyi.common.core.domain.entity.SysUser)78 Log (com.ruoyi.common.annotation.Log)16 SysRole (com.ruoyi.common.core.domain.entity.SysRole)13 LoginUser (com.ruoyi.common.core.domain.model.LoginUser)13 GetMapping (org.springframework.web.bind.annotation.GetMapping)11 AjaxResult (com.ruoyi.common.core.domain.AjaxResult)10 ServiceException (com.ruoyi.common.exception.ServiceException)10 SaCheckPermission (cn.dev33.satoken.annotation.SaCheckPermission)8 ExcelUtil (com.ruoyi.common.utils.poi.ExcelUtil)8 Transactional (org.springframework.transaction.annotation.Transactional)8 UserConstants (com.ruoyi.common.constant.UserConstants)7 BaseController (com.ruoyi.common.core.controller.BaseController)7 TableDataInfo (com.ruoyi.common.core.page.TableDataInfo)7 BusinessType (com.ruoyi.common.enums.BusinessType)7 StringUtils (com.ruoyi.common.utils.StringUtils)7 ISysPostService (com.ruoyi.system.service.ISysPostService)7 ISysRoleService (com.ruoyi.system.service.ISysRoleService)7 ISysUserService (com.ruoyi.system.service.ISysUserService)7 List (java.util.List)7 Collectors (java.util.stream.Collectors)7