Commit a40ae852 authored by youjie's avatar youjie

line 密钥

parent f4387953
......@@ -68,7 +68,7 @@ const router = createRouter({
]
},
{
path: "/login",
path: "/login/:type?",
name: "login",
component: () => import("../views/auth/Login.vue"),
meta: { title: "page.login" },
......
......@@ -59,19 +59,6 @@
</a-form>
</a-space>
<!-- Line登录 -->
<div v-if="loginMsg.reType==3" class="login-form-content scan-content">
<div class="qr-container">
<div class="qr-box line-qr-box">
<div class="qr-code-placeholder">
<i class="ki-outline ki-message-text"></i>
</div>
</div>
<p class="scan-instruction">{{ t('login.scanTip') }}</p>
<p class="scan-status">{{ t('login.scanWaiting') }}</p>
</div>
</div>
<div class="mt-[40px] flex items-center justify-center">
<a-divider orientation="center" class="text-[16px] text-[#EEEFEB]"></a-divider>
<span class="text-nowrap customPrimary-5 px-[14px]">{{ t('login.othenLogin') }}</span>
......@@ -152,12 +139,13 @@ const systemConfigStore = useSystemConfigStore()
const loading = ref(true)
const router = useRouter()
const { params } = router.currentRoute.value
const googleButtonContainer = ref(null);
const loginMsg = reactive({
tenantId: systemConfigStore.tenantId || null,
reType: 0,//登录方式 0账号密码 1谷歌授权 3LINE授权 7FaceBook授权
reType: 0,//登录方式 0账号密码 1谷歌授权 2微信授权 3LINE授权 7FaceBook授权
openId: "",
email: "",//2310721242@qq.com
password: '',//yj123456
......@@ -165,6 +153,7 @@ const loginMsg = reactive({
parentId: null,
redirectUri: '',
})
if(params&&params.type) loginMsg.reType = Number(params.type)
const loginMethods = ref([
{
......@@ -213,24 +202,48 @@ const rules = computed(() => ({
const openInfo = ref({} as any)
// 随机生成 state 参数
const generateState = () => {
return Math.random().toString(36).substring(2); // 简单的生成随机字符串
}
// line授权登录
const loginWithLine = () => {
const channelId = openInfo.value.appId; // 替换为你的 LINE Channel ID
const redirectUri = encodeURIComponent(openInfo.value.redirectUri || 'https://www.oytour.com/#/login/3'); // 替换为你的重定向 URI
const state = generateState(); // 防止 CSRF 攻击,生成随机的 state 参数
// 构造 LINE 授权 URL
const lineLoginUrl = `https://access.line.me/oauth2/v2.1/authorize?response_type=code&client_id=${channelId}&redirect_uri=${redirectUri}&state=${state}&scope=openid%20profile`;
// 跳转到 LINE 登录页面
window.location.href = lineLoginUrl;
}
// 微信授权登录
const loginWechat = () => {
const redirect_url = openInfo.value.redirectUri || 'https://www.oytour.com/#/login/2'
const url = `https://open.weixin.qq.com/connect/qrconnect?appid=${openInfo.value.appId}&redirect_uri=${encodeURIComponent(redirect_url)}&response_type=code&scope=snsapi_login&state=${1}&wechat_redirect=${redirect_url}`;
window.location.href = url;
}
// 获取微信登录AppID 域名 重定向页面
const getAppIdRedirectUri = async () => {
// 获取AppID 域名 重定向页面
const getAppIdRedirectUri = async (providerType: string) => {
// const { AppID, State, OpenRedirectUri } = openInfo.value;
// let redirect_uri = OpenRedirectUri;
// const url = `https://open.weixin.qq.com/connect/qrconnect?appid=${AppID}&redirect_uri=${encodeURIComponent('https://www.oytour.com/#/login')}&response_type=code&scope=snsapi_login&state=${State}&wechat_redirect=${redirect_uri}`;
// window.location.href = url;
// return
loading.value = true
try {
// 获取微信登录AppID 域名
const response = await userStore.getUserWechatAppIdAsync(loginMsg.tenantId?.toString() || '',providerTypeEnum.WECHAT.value)
// 获取微信绑定AppID 域名
const response = await userStore.getUserWechatAppIdAsync(loginMsg.tenantId?.toString() || '',providerType)
if (response.status == 'SUCCESS') {
openInfo.value = response.data[0]
const { appId, redirectUri } = openInfo.value;
const redirect_url = redirectUri?redirectUri:'https://www.oytour.com/#/login'
const url = `https://open.weixin.qq.com/connect/qrconnect?appid=${appId}&redirect_uri=${encodeURIComponent(redirect_url)}&response_type=code&scope=snsapi_login&state=${1}&wechat_redirect=${redirect_url}`;
window.location.href = url;
if(openInfo.value.appId){
if(providerType==providerTypeEnum.WECHAT.value){
loginWechat()
}else if(providerType==providerTypeEnum.GOOGLE.value){
renderGoogleButton(openInfo.value.appId)
}else if(providerType==providerTypeEnum.LINE.value){
loginWithLine()
}
}
}
}catch (error: any) {
Message.error(error.message)
......@@ -265,9 +278,10 @@ const handleClick = (path: string) => {
}
const toggleLoginType = (type: number) => {
if(type==3||type==7) return Message.error(t('login.loginTypeNotSupport'))
if(type==7) return Message.error(t('login.loginTypeNotSupport'))
loginMsg.reType = type
if(type==2) { getAppIdRedirectUri() }
if(type==3) getAppIdRedirectUri(providerTypeEnum.LINE.value)
if(type==2) getAppIdRedirectUri(providerTypeEnum.WECHAT.value)
// if(type==1) {
// loginWithGoogle()
// }
......@@ -399,17 +413,17 @@ onMounted(async () => {
})
const queryParams = query()
const code = queryParams.code
if (code) {
loginMsg.reType = 2
useWechatLogin(code)
if(loginMsg.reType==2) useWechatLogin(code)
else if(loginMsg.reType==3) {}
}
try {
await initGoogleSDK();
// 确保 SDK 加载完成后渲染按钮
await new Promise(resolve => setTimeout(resolve));
renderGoogleButton()
getAppIdRedirectUri(providerTypeEnum.GOOGLE.value)
} catch (error) {
console.error('SDK 初始化失败:', error);
......
......@@ -242,20 +242,20 @@ const generateState = () => {
// line授权
const loginWithLine = () => {
const channelId = openInfo.value.appId; // 替换为你的 LINE Channel ID
const redirectUri = encodeURIComponent(openInfo.value.redirectUri || 'https://www.oytour.com/#/login'); // 替换为你的重定向 URI
const redirectUri = encodeURIComponent(openInfo.value.redirectUri || 'https://www.oytour.com/#/login/3'); // 替换为你的重定向 URI
const state = generateState(); // 防止 CSRF 攻击,生成随机的 state 参数
// 构造 LINE 授权 URL
const lineLoginUrl = `https://access.line.me/oauth2/v2.1/authorize?response_type=code&client_id=${channelId}&redirect_uri=${redirectUri}&state=${state}&scope=openid%20profile`;
// 跳转到 LINE 登录页面
window.location.href = lineLoginUrl;
}
// 微信授权登录
// 微信授权
const loginWechat = () => {
const redirect_url = openInfo.value.redirectUri || 'https://www.oytour.com/#/login'
const url = `https://open.weixin.qq.com/connect/qrconnect?appid=${appId}&redirect_uri=${encodeURIComponent(redirect_url)}&response_type=code&scope=snsapi_login&state=${1}&wechat_redirect=${redirect_url}`;
const redirect_url = openInfo.value.redirectUri || 'https://www.oytour.com/#/login/2'
const url = `https://open.weixin.qq.com/connect/qrconnect?appid=${openInfo.value.appId}&redirect_uri=${encodeURIComponent(redirect_url)}&response_type=code&scope=snsapi_login&state=${1}&wechat_redirect=${redirect_url}`;
window.location.href = url;
}
// 获取绑定AppID 域名 重定向页面
// 获取AppID 域名 重定向页面
const getAppIdRedirectUri = async (providerType: string) => {
// const { AppID, State, OpenRedirectUri } = openInfo.value;
// let redirect_uri = OpenRedirectUri;
......@@ -267,8 +267,7 @@ const getAppIdRedirectUri = async (providerType: string) => {
const response = await userStore.getUserWechatAppIdAsync(systemConfig.tenantId?.toString() || '',providerType)
if (response.status == 'SUCCESS') {
openInfo.value = response.data[0]
if(openInfo.value?.appId){
console.log(openInfo.value,'----------')
if(openInfo.value.appId){
if(providerType==providerTypeEnum.WECHAT.value){
loginWechat()
}else if(providerType==providerTypeEnum.GOOGLE.value){
......@@ -294,10 +293,8 @@ const useWechatBind = async(code:string) => {
Message.success(t('personal.bindWechatSuccess'))
getPersonalInfor()
}
router.push('/accountCenter')
}catch (error: any) {
// Message.error(error.message)
router.push('/accountCenter')
Message.error(error.message)
} finally {
loading.value = false
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment