| | |
| | | import cn.dev33.satoken.stp.StpUtil; |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import me.zhyd.oauth.model.AuthUser; |
| | |
| | | import org.dromara.common.core.domain.model.LoginUser; |
| | | import org.dromara.common.core.enums.LoginType; |
| | | import org.dromara.common.core.enums.TenantStatus; |
| | | import org.dromara.common.core.enums.UserStatus; |
| | | import org.dromara.common.core.exception.user.UserException; |
| | | import org.dromara.common.core.utils.DateUtils; |
| | | import org.dromara.common.core.utils.MessageUtils; |
| | |
| | | import org.dromara.common.tenant.helper.TenantHelper; |
| | | import org.dromara.system.domain.SysUser; |
| | | import org.dromara.system.domain.bo.SysSocialBo; |
| | | import org.dromara.system.domain.vo.SysSocialVo; |
| | | import org.dromara.system.domain.vo.SysTenantVo; |
| | | import org.dromara.system.domain.vo.SysUserVo; |
| | | import org.dromara.system.mapper.SysUserMapper; |
| | | import org.dromara.system.service.ISysPermissionService; |
| | | import org.dromara.system.service.ISysSocialService; |
| | | import org.dromara.system.service.ISysTenantService; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | |
| | | * @return 统一响应实体 |
| | | */ |
| | | public void socialRegister(AuthUser authUserData) { |
| | | SysSocialBo bo = new SysSocialBo(); |
| | | String authId = authUserData.getSource() + authUserData.getUuid(); |
| | | // 第三方用户信息 |
| | | SysSocialBo bo = BeanUtil.toBean(authUserData, SysSocialBo.class); |
| | | BeanUtil.copyProperties(authUserData.getToken(), bo); |
| | | bo.setUserId(LoginHelper.getUserId()); |
| | | bo.setAuthId(authUserData.getSource() + authUserData.getUuid()); |
| | | bo.setAuthId(authId); |
| | | bo.setOpenId(authUserData.getUuid()); |
| | | bo.setUserName(authUserData.getUsername()); |
| | | BeanUtils.copyProperties(authUserData, bo); |
| | | BeanUtils.copyProperties(authUserData.getToken(), bo); |
| | | sysSocialService.insertByBo(bo); |
| | | bo.setNickName(authUserData.getNickname()); |
| | | // 查询是否已经绑定用户 |
| | | SysSocialVo vo = sysSocialService.selectByAuthId(authId); |
| | | if (ObjectUtil.isEmpty(vo)) { |
| | | // 没有绑定用户, 新增用户信息 |
| | | sysSocialService.insertByBo(bo); |
| | | } else { |
| | | // 更新用户信息 |
| | | bo.setId(vo.getId()); |
| | | sysSocialService.updateByBo(bo); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | SpringUtils.context().publishEvent(logininforEvent); |
| | | } |
| | | |
| | | |
| | | private SysUserVo loadUserByUsername(String tenantId, String username) { |
| | | SysUser user = userMapper.selectOne(new LambdaQueryWrapper<SysUser>() |
| | | .select(SysUser::getUserName, SysUser::getStatus) |
| | | .eq(TenantHelper.isEnable(), SysUser::getTenantId, tenantId) |
| | | .eq(SysUser::getUserName, username)); |
| | | if (ObjectUtil.isNull(user)) { |
| | | log.info("登录用户:{} 不存在.", username); |
| | | throw new UserException("user.not.exists", username); |
| | | } else if (UserStatus.DISABLE.getCode().equals(user.getStatus())) { |
| | | log.info("登录用户:{} 已被停用.", username); |
| | | throw new UserException("user.blocked", username); |
| | | } |
| | | if (TenantHelper.isEnable()) { |
| | | return userMapper.selectTenantUserByUserName(username, tenantId); |
| | | } |
| | | return userMapper.selectUserByUserName(username); |
| | | } |
| | | |
| | | /** |
| | | * 构建登录用户 |