mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-27 01:32:03 +08:00
1. 优化前端的社交登陆的枚举
2. 将三方登陆,统一改成社交登陆
This commit is contained in:
parent
7b3a283074
commit
a0a5d3a357
@ -105,7 +105,7 @@ public class SysAuthController {
|
||||
@GetMapping("/social-login-redirect")
|
||||
@ApiOperation("社交登陆的跳转")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "type", value = "三方类型", required = true, dataTypeClass = Integer.class),
|
||||
@ApiImplicitParam(name = "type", value = "社交类型", required = true, dataTypeClass = Integer.class),
|
||||
@ApiImplicitParam(name = "redirectUri", value = "回调路径", dataTypeClass = String.class)
|
||||
})
|
||||
public CommonResult<String> socialLoginRedirect(@RequestParam("type") Integer type,
|
||||
|
@ -23,7 +23,7 @@ public interface SysRedisKeyConstants {
|
||||
"captcha_code:%s", // 参数为 uuid
|
||||
STRING, String.class, RedisKeyDefine.TimeoutTypeEnum.DYNAMIC);
|
||||
|
||||
RedisKeyDefine AUTH_SOCIAL_USER = new RedisKeyDefine("认证的三方用户",
|
||||
RedisKeyDefine AUTH_SOCIAL_USER = new RedisKeyDefine("认证的社交用户",
|
||||
"auth_social_user:%d:%s", // 参数为 type,code
|
||||
STRING, AuthUser.class, Duration.ofDays(1));
|
||||
|
||||
|
@ -17,7 +17,7 @@ public interface SysErrorCodeConstants {
|
||||
ErrorCode AUTH_LOGIN_CAPTCHA_NOT_FOUND = new ErrorCode(1002000003, "验证码不存在");
|
||||
ErrorCode AUTH_LOGIN_CAPTCHA_CODE_ERROR = new ErrorCode(1002000004, "验证码不正确");
|
||||
ErrorCode AUTH_THIRD_LOGIN_NOT_BIND = new ErrorCode(1002000005, "未绑定账号,需要进行绑定");
|
||||
ErrorCode AUTH_THIRD_OAUTH_FAILURE = new ErrorCode(1002000006, "三方授权失败,原因是:{}");
|
||||
ErrorCode AUTH_THIRD_OAUTH_FAILURE = new ErrorCode(1002000006, "社交授权失败,原因是:{}");
|
||||
|
||||
// ========== TOKEN 模块 1002001000 ==========
|
||||
ErrorCode TOKEN_EXPIRED = new ErrorCode(1002001000, "Token 已经过期");
|
||||
|
@ -258,7 +258,7 @@ public class SysAuthServiceImpl implements SysAuthService {
|
||||
private AuthUser obtainAuthUser(Integer type, AuthCallback authCallback) {
|
||||
AuthRequest authRequest = authRequestFactory.get(SysSocialTypeEnum.valueOfType(type).getSource());
|
||||
AuthResponse<?> authResponse = authRequest.login(authCallback);
|
||||
log.info("[obtainAuthUser][请求三方平台 type({}) request({}) response({})]", type, JsonUtils.toJsonString(authCallback),
|
||||
log.info("[obtainAuthUser][请求社交平台 type({}) request({}) response({})]", type, JsonUtils.toJsonString(authCallback),
|
||||
JsonUtils.toJsonString(authResponse));
|
||||
if (!authResponse.ok()) {
|
||||
throw exception(AUTH_THIRD_OAUTH_FAILURE, authResponse.getMsg());
|
||||
|
@ -34,14 +34,6 @@ public interface SysUserService {
|
||||
*/
|
||||
Long createUser(SysUserCreateReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 绑定第三方用户
|
||||
* @param sysUserId 系统用户ID
|
||||
* @param socialUSerId 第三方唯一标识
|
||||
* @return
|
||||
*/
|
||||
Long bindSocialUSer(Long sysUserId, String socialUSerId);
|
||||
|
||||
/**
|
||||
* 修改用户
|
||||
*
|
||||
|
@ -4,11 +4,6 @@ import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysSocialUserDO;
|
||||
import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.social.SysUserSocialMapper;
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.exception.ServiceException;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.adminserver.modules.infra.service.file.InfFileService;
|
||||
import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.profile.SysUserProfileUpdatePasswordReqVO;
|
||||
import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.profile.SysUserProfileUpdateReqVO;
|
||||
@ -17,10 +12,14 @@ import cn.iocoder.yudao.adminserver.modules.system.convert.user.SysUserConvert;
|
||||
import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dept.SysDeptDO;
|
||||
import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dept.SysPostDO;
|
||||
import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO;
|
||||
import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.social.SysUserSocialMapper;
|
||||
import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.user.SysUserMapper;
|
||||
import cn.iocoder.yudao.adminserver.modules.system.service.dept.SysDeptService;
|
||||
import cn.iocoder.yudao.adminserver.modules.system.service.dept.SysPostService;
|
||||
import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysPermissionService;
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.exception.ServiceException;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -33,9 +32,8 @@ import javax.annotation.Resource;
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.*;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
|
||||
/**
|
||||
* 用户 Service 实现类
|
||||
@ -78,15 +76,6 @@ public class SysUserServiceImpl implements SysUserService {
|
||||
return user.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long bindSocialUSer(Long sysUserId, String socialUSerId) {
|
||||
SysSocialUserDO userSocialDO = new SysSocialUserDO();
|
||||
userSocialDO.setUserId(sysUserId);
|
||||
// userSocialDO.setSocialUserId(socialUSerId);
|
||||
userSocialMapper.insert(userSocialDO);
|
||||
return userSocialDO.getUserId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUser(SysUserUpdateReqVO reqVO) {
|
||||
// 校验正确性
|
||||
|
@ -68,9 +68,25 @@ export const InfApiErrorLogProcessStatusEnum = {
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户的三方平台的类型枚举
|
||||
* 用户的社交平台的类型枚举
|
||||
*/
|
||||
export const SysUserSocialTypeEnum = {
|
||||
GITEE: 10,
|
||||
DINGTALK: 20,
|
||||
// GITEE: {
|
||||
// title: "码云",
|
||||
// type: 10,
|
||||
// source: "gitee",
|
||||
// img: "https://cdn.jsdelivr.net/gh/justauth/justauth-oauth-logo@1.11/gitee.png",
|
||||
// },
|
||||
DINGTALK: {
|
||||
title: "钉钉",
|
||||
type: 20,
|
||||
source: "dingtalk",
|
||||
img: "https://cdn.jsdelivr.net/gh/justauth/justauth-oauth-logo@1.11/dingtalk.png",
|
||||
},
|
||||
WECHAT_ENTERPRISE: {
|
||||
title: "企业微信",
|
||||
type: 30,
|
||||
source: "wechat_enterprise",
|
||||
img: "https://cdn.jsdelivr.net/gh/justauth/justauth-oauth-logo@1.11/wechat_enterprise.png",
|
||||
}
|
||||
}
|
||||
|
@ -30,8 +30,8 @@
|
||||
|
||||
<el-form-item style="width:100%;">
|
||||
<div class="oauth-login" style="display:flex">
|
||||
<div class="oauth-login-item" v-for="item in oauthProviders" :key="item.code" @click="doAuth2Login(item)">
|
||||
<img :src=item.img height="25px" width="25px" alt="登录" >
|
||||
<div class="oauth-login-item" v-for="item in SysUserSocialTypeEnum" :key="item.type" @click="doSocialLogin(item)">
|
||||
<img :src="item.img" height="25px" width="25px" alt="登录" >
|
||||
<span>{{item.title}}</span>
|
||||
</div>
|
||||
</div>
|
||||
@ -48,6 +48,7 @@
|
||||
import { getCodeImg,socialLoginRedirect } from "@/api/login";
|
||||
import Cookies from "js-cookie";
|
||||
import { encrypt, decrypt } from '@/utils/jsencrypt'
|
||||
import {InfApiErrorLogProcessStatusEnum, SysUserSocialTypeEnum} from "@/utils/constants";
|
||||
|
||||
export default {
|
||||
name: "Login",
|
||||
@ -61,23 +62,6 @@ export default {
|
||||
code: "",
|
||||
uuid: ""
|
||||
},
|
||||
oauthProviders: [{
|
||||
img: "https://cdn.jsdelivr.net/gh/justauth/justauth-oauth-logo@1.2/gitee.png",
|
||||
title: "码云",
|
||||
source: "gitee",
|
||||
type: 10
|
||||
}, {
|
||||
img: "https://cdn.jsdelivr.net/gh/justauth/justauth-oauth-logo@1.2/dingtalk.png",
|
||||
title: "钉钉",
|
||||
source: "dingtalk",
|
||||
type: 20
|
||||
} , {
|
||||
img: "https://cdn.jsdelivr.net/gh/justauth/justauth-oauth-logo@1.2/wechat_enterprise.png",
|
||||
title: "企业微信",
|
||||
source: "wechat_enterprise",
|
||||
type: 30
|
||||
}
|
||||
],
|
||||
loginRules: {
|
||||
username: [
|
||||
{ required: true, trigger: "blur", message: "用户名不能为空" }
|
||||
@ -88,18 +72,22 @@ export default {
|
||||
code: [{ required: true, trigger: "change", message: "验证码不能为空" }]
|
||||
},
|
||||
loading: false,
|
||||
redirect: undefined
|
||||
redirect: undefined,
|
||||
// 枚举
|
||||
SysUserSocialTypeEnum: SysUserSocialTypeEnum,
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
$route: {
|
||||
handler: function(route) {
|
||||
this.redirect = route.query && route.query.redirect;
|
||||
},
|
||||
immediate: true
|
||||
}
|
||||
},
|
||||
// watch: {
|
||||
// $route: {
|
||||
// handler: function(route) {
|
||||
// this.redirect = route.query && route.query.redirect;
|
||||
// },
|
||||
// immediate: true
|
||||
// }
|
||||
// },
|
||||
created() {
|
||||
// 重定向地址
|
||||
this.redirect = this.$route.query.redirect;
|
||||
this.getCode();
|
||||
this.getCookie();
|
||||
},
|
||||
@ -143,16 +131,16 @@ export default {
|
||||
}
|
||||
});
|
||||
},
|
||||
doAuth2Login(provider) {
|
||||
// console.log("开始Oauth登录...%o", provider.code);
|
||||
doSocialLogin(socialTypeEnum) {
|
||||
// console.log("开始Oauth登录...%o", socialTypeEnum.code);
|
||||
// 设置登陆中
|
||||
this.loading = true;
|
||||
// 计算 redirectUri
|
||||
// const redirectUri = location.origin + '/social-login';
|
||||
const redirectUri = 'http://127.0.0.1:48080/api/gitee/callback';
|
||||
const redirectUri = location.origin + '/social-login?type=' + socialTypeEnum.type + '&redirect=' + (this.redirect || "/"); // 重定向不能丢
|
||||
// const redirectUri = 'http://127.0.0.1:48080/api/gitee/callback';
|
||||
// const redirectUri = 'http://127.0.0.1:48080/api/dingtalk/callback';
|
||||
// 进行跳转
|
||||
socialLoginRedirect(provider.type, redirectUri).then((res) => {
|
||||
socialLoginRedirect(socialTypeEnum.type, encodeURIComponent(redirectUri)).then((res) => {
|
||||
// console.log(res.url);
|
||||
window.location.href = res.data;
|
||||
});
|
||||
|
@ -51,24 +51,27 @@ export default {
|
||||
},
|
||||
loading: false,
|
||||
redirect: undefined,
|
||||
// 三方登陆相关
|
||||
// 社交登陆相关
|
||||
type: undefined,
|
||||
code: undefined,
|
||||
state: undefined,
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
$route: {
|
||||
handler: function(route) {
|
||||
this.redirect = route.query && route.query.redirect;
|
||||
},
|
||||
immediate: true
|
||||
}
|
||||
},
|
||||
// watch: {
|
||||
// $route: {
|
||||
// handler: function(route) {
|
||||
// this.redirect = route.query && route.query.redirect;
|
||||
// },
|
||||
// immediate: true
|
||||
// }
|
||||
// },
|
||||
created() {
|
||||
this.getCookie();
|
||||
// 三方登陆相关
|
||||
this.type = 10; // TODO 芋艿:需要改
|
||||
// 重定向地址
|
||||
this.redirect = this.$route.query.redirect;
|
||||
debugger
|
||||
// 社交登陆相关
|
||||
this.type = this.$route.query.type;
|
||||
this.code = this.$route.query.code;
|
||||
this.state = this.$route.query.state;
|
||||
this.$store.dispatch("SocialLogin", {
|
||||
|
Loading…
Reference in New Issue
Block a user