| | |
| | | |
| | | import cn.dev33.satoken.stp.SaLoginModel; |
| | | import cn.dev33.satoken.stp.StpUtil; |
| | | import cn.hutool.core.map.MapUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.http.HttpUtil; |
| | | import cn.hutool.http.Method; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | throw new ServiceException(response.getMsg()); |
| | | } |
| | | AuthUser authUserData = response.getData(); |
| | | if ("GITEE".equals(authUserData.getSource())) { |
| | | // 如用户使用 gitee 登录顺手 star 给作者一点支持 拒绝白嫖 |
| | | HttpUtil.createRequest(Method.PUT, "https://gitee.com/api/v5/user/starred/dromara/RuoYi-Vue-Plus") |
| | | .formStr(MapUtil.of("access_token", authUserData.getToken().getAccessToken())) |
| | | .executeAsync(); |
| | | HttpUtil.createRequest(Method.PUT, "https://gitee.com/api/v5/user/starred/dromara/RuoYi-Cloud-Plus") |
| | | .formStr(MapUtil.of("access_token", authUserData.getToken().getAccessToken())) |
| | | .executeAsync(); |
| | | } |
| | | |
| | | SysSocialVo social = sysSocialService.selectByAuthId(authUserData.getSource() + authUserData.getUuid()); |
| | | if (!ObjectUtil.isNotNull(social)) { |
| | | throw new ServiceException("你还没有绑定第三方账号,绑定后才可以登录!"); |
| | |
| | | |
| | | // 此处可根据登录用户的数据不同 自行创建 loginUser 属性不够用继承扩展就行了 |
| | | LoginUser loginUser = loginService.buildLoginUser(user); |
| | | loginUser.setClientKey(client.getClientKey()); |
| | | loginUser.setDeviceType(client.getDeviceType()); |
| | | SaLoginModel model = new SaLoginModel(); |
| | | model.setDevice(client.getDeviceType()); |
| | | // 自定义分配 不同用户体系 不同 token 授权时间 不设置默认走全局 yml 配置 |
| | | // 例如: 后台用户30分钟过期 app用户1天过期 |
| | | model.setTimeout(client.getTimeout()); |
| | | model.setActiveTimeout(client.getActiveTimeout()); |
| | | model.setExtra(LoginHelper.CLIENT_KEY, clientId); |
| | | // 生成token |
| | | LoginHelper.login(loginUser, model); |
| | | |
| | | loginService.recordLogininfor(loginUser.getTenantId(), user.getUserName(), Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")); |
| | | loginService.recordLoginInfo(user.getUserId()); |
| | | |
| | | LoginVo loginVo = new LoginVo(); |
| | | loginVo.setAccessToken(StpUtil.getTokenValue()); |
| | | loginVo.setExpireIn(StpUtil.getTokenTimeout()); |
| | | loginVo.setClientId(clientId); |
| | | return loginVo; |
| | | } |
| | | |