Search in sources :

Example 6 with SysUser

use of com.jun.plugin.system.entity.SysUser in project jun_springboot_api_service by wujun728.

the class UserServiceImpl method updateUserInfo.

@Override
public void updateUserInfo(SysUser vo) {
    SysUser sysUser = sysUserMapper.selectById(vo.getId());
    if (null == sysUser) {
        throw new BusinessException(BaseResponseCode.DATA_ERROR);
    }
    // 如果用户名变更
    if (!sysUser.getUsername().equals(vo.getUsername())) {
        SysUser sysUserOne = sysUserMapper.selectOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUsername, vo.getUsername()));
        if (sysUserOne != null) {
            throw new BusinessException("用户名已存在!");
        }
    }
    // 如果用户名、密码、状态 变更,删除redis中用户绑定的角色跟权限
    if (!sysUser.getUsername().equals(vo.getUsername()) || (!StringUtils.isEmpty(vo.getPassword()) && !sysUser.getPassword().equals(PasswordUtils.encode(vo.getPassword(), sysUser.getSalt()))) || !sysUser.getStatus().equals(vo.getStatus())) {
        httpSessionService.abortUserById(vo.getId());
    }
    if (!StringUtils.isEmpty(vo.getPassword())) {
        String newPassword = PasswordUtils.encode(vo.getPassword(), sysUser.getSalt());
        vo.setPassword(newPassword);
    } else {
        vo.setPassword(null);
    }
    vo.setUpdateId(httpSessionService.getCurrentUserId());
    sysUserMapper.updateById(vo);
}
Also used : BusinessException(com.jun.plugin.system.common.exception.BusinessException) SysUser(com.jun.plugin.system.entity.SysUser)

Example 7 with SysUser

use of com.jun.plugin.system.entity.SysUser in project jun_springboot_api_service by wujun728.

the class UserServiceImpl method addUser.

@Override
public void addUser(SysUser vo) {
    SysUser sysUserOne = sysUserMapper.selectOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUsername, vo.getUsername()));
    if (sysUserOne != null) {
        throw new BusinessException("用户已存在,请勿重复添加!");
    }
    vo.setSalt(PasswordUtils.getSalt());
    String encode = PasswordUtils.encode(vo.getPassword(), vo.getSalt());
    vo.setPassword(encode);
    vo.setStatus(1);
    vo.setCreateWhere(1);
    sysUserMapper.insert(vo);
    if (!CollectionUtils.isEmpty(vo.getRoleIds())) {
        UserRoleOperationReqVO reqVO = new UserRoleOperationReqVO();
        reqVO.setUserId(vo.getId());
        reqVO.setRoleIds(vo.getRoleIds());
        userRoleService.addUserRoleInfo(reqVO);
    }
}
Also used : UserRoleOperationReqVO(com.jun.plugin.system.vo.req.UserRoleOperationReqVO) BusinessException(com.jun.plugin.system.common.exception.BusinessException) SysUser(com.jun.plugin.system.entity.SysUser)

Example 8 with SysUser

use of com.jun.plugin.system.entity.SysUser in project jun_springboot_api_service by wujun728.

the class UserServiceImpl method register.

@Override
public void register(SysUser sysUser) {
    SysUser sysUserOne = sysUserMapper.selectOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUsername, sysUser.getUsername()));
    if (sysUserOne != null) {
        throw new BusinessException("用户名已存在!");
    }
    sysUser.setSalt(PasswordUtils.getSalt());
    String encode = PasswordUtils.encode(sysUser.getPassword(), sysUser.getSalt());
    sysUser.setPassword(encode);
    sysUserMapper.insert(sysUser);
}
Also used : BusinessException(com.jun.plugin.system.common.exception.BusinessException) SysUser(com.jun.plugin.system.entity.SysUser)

Example 9 with SysUser

use of com.jun.plugin.system.entity.SysUser in project jun_springboot_api_service by wujun728.

the class UserServiceImpl method login.

@Override
public LoginRespVO login(SysUser vo) {
    SysUser sysUser = sysUserMapper.selectOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUsername, vo.getUsername()));
    if (null == sysUser) {
        throw new BusinessException(BaseResponseCode.NOT_ACCOUNT);
    }
    if (sysUser.getStatus() == 2) {
        throw new BusinessException(BaseResponseCode.USER_LOCK);
    }
    if (!PasswordUtils.matches(sysUser.getSalt(), vo.getPassword(), sysUser.getPassword())) {
        throw new BusinessException(BaseResponseCode.PASSWORD_ERROR);
    }
    LoginRespVO respVO = new LoginRespVO();
    BeanUtils.copyProperties(sysUser, respVO);
    // true:允许多处登陆; false:只能单处登陆,顶掉之前登陆
    if (!allowMultipleLogin) {
        httpSessionService.abortUserById(sysUser.getId());
    }
    if (StringUtils.isNotBlank(sysUser.getDeptId())) {
        SysDept sysDept = sysDeptMapper.selectById(sysUser.getDeptId());
        if (sysDept != null) {
            sysUser.setDeptNo(sysDept.getDeptNo());
        }
    }
    String token = httpSessionService.createTokenAndUser(sysUser, roleService.getRoleNames(sysUser.getId()), permissionService.getPermissionsByUserId(sysUser.getId()));
    respVO.setAccessToken(token);
    respVO.setJwtToken(JwtUtil.sign(vo.getUsername()));
    return respVO;
}
Also used : BusinessException(com.jun.plugin.system.common.exception.BusinessException) LoginRespVO(com.jun.plugin.system.vo.resp.LoginRespVO) SysUser(com.jun.plugin.system.entity.SysUser) SysDept(com.jun.plugin.system.entity.SysDept)

Aggregations

SysUser (com.jun.plugin.system.entity.SysUser)9 BusinessException (com.jun.plugin.system.common.exception.BusinessException)7 SysDept (com.jun.plugin.system.entity.SysDept)4 IPage (com.baomidou.mybatisplus.core.metadata.IPage)1 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)1 UserRoleOperationReqVO (com.jun.plugin.system.vo.req.UserRoleOperationReqVO)1 HomeRespVO (com.jun.plugin.system.vo.resp.HomeRespVO)1 LoginRespVO (com.jun.plugin.system.vo.resp.LoginRespVO)1 PermissionRespNode (com.jun.plugin.system.vo.resp.PermissionRespNode)1 UserInfoRespVO (com.jun.plugin.system.vo.resp.UserInfoRespVO)1