Browse Source

add:完善第三方登录

master
秋田弘 7 months ago
parent
commit
3308931168
  1. 60
      frontend/src/components/desktop/LockDesktop.vue

60
frontend/src/components/desktop/LockDesktop.vue

@ -156,7 +156,9 @@
import router from "@/system/router";
import { RestartApp } from "@/util/goutil";
import { notifyError } from "@/util/msg";
import { onMounted, ref } from "vue";
import { onMounted, ref, watchEffect } from "vue";
import { useRoute } from "vue-router";
const route = useRoute();
const store = useLoginStore();
const sys = useSystem();
const loginCallback = sys._options.loginCallback;
@ -207,13 +209,14 @@
}
});
// code
watch(
() => router.currentRoute.value.query.code,
() => {
// 使 watchEffect code
watchEffect(() => {
const code = route.query.code;
if (code) {
console.log(code, "---");
onLogin();
}
);
});
const onLogin = async () => {
localStorage.removeItem("godoosClientId");
@ -238,8 +241,6 @@
const returnedState = router.currentRoute.value.query
.state as string;
console.log(returnedState, "---", store.State);
if (returnedState !== store.State) {
notifyError("登录失败,请重试");
return;
@ -405,8 +406,6 @@
const success = await loginFunction();
if (success) {
loginSuccess();
} else {
notifyError("登录失败");
}
}
};
@ -415,20 +414,35 @@
// stateCSRF,使
const state = Date.now() + Math.random().toString(36).substring(2, 15);
store.State = state;
// url
const currentUrl = window.location.href;
const url = config.userInfo.url + "/github/authorize?state=" + state;
const res: any = await fetch(url, {
method: "POST",
body: JSON.stringify({
state: state,
redirect_url: currentUrl,
}),
});
if (!res.ok) {
return false;
}
const data = await res.json();
console.log(data.data.url);
window.location.href = data.data.url;
return true;
if (data && data.data && data.data.url) {
console.log(data.data.url, "---");
// 使URL
const urlPattern = /client_id=[^&]+/;
if (urlPattern.test(data.data.url)) {
window.location.href = data.data.url;
return true;
} else {
notifyError("请先在系统配置中设置github登陆配置");
return false;
}
} else {
notifyError("获取授权URL失败");
return false;
}
};
const authWithWechat = (): boolean | PromiseLike<boolean> => {
@ -447,20 +461,34 @@
// stateCSRF,使
const state = Date.now() + Math.random().toString(36).substring(2, 15);
store.State = state;
// url
const currentUrl = window.location.href;
const url = config.userInfo.url + "/gitee/authorize?state=" + state;
const res: any = await fetch(url, {
method: "POST",
body: JSON.stringify({
state: state,
redirect_url: currentUrl,
}),
});
if (!res.ok) {
return false;
}
const data = await res.json();
// Gitee
window.location.href = data.data.url;
return true;
if (data && data.data && data.data.url) {
// 使URL
const urlPattern = /client_id=[^&]+/;
if (urlPattern.test(data.data.url)) {
window.location.href = data.data.url;
return true;
} else {
notifyError("请先在系统配置中设置gitee登陆配置");
return false;
}
} else {
notifyError("获取授权URL失败");
return false;
}
};
</script>

Loading…
Cancel
Save