完成登录跳转

This commit is contained in:
cxykevin 2024-09-15 17:24:19 +08:00
parent 06cad663e0
commit 3bd99994db
3 changed files with 49 additions and 21 deletions

View File

@ -117,6 +117,11 @@ async def login(apikey: str, resp: Response):
return {}
@app.get("/api/callback")
async def login_callback():
return templates.TemplateResponse("callback.html", {"request": {}, "ui": cfg.config["ui"]})
@app.get("/manager/init")
async def init(key: str):
if (key != KEY):

42
src/callback.html Normal file
View File

@ -0,0 +1,42 @@
<html lang="zh-CN" class="mdui-theme-auto">
<head>
<link rel="stylesheet" href="https://learn.study-area.org.cn/theme/css/mdui.css">
<script src="https://learn.study-area.org.cn/theme/js/mdui.global.js" type="text/javascript"></script>
<link href="https://learn.study-area.org.cn/theme/css/icons.css" rel="stylesheet">
<title>{{ui.title}}</title>
<meta charset="utf-8">
<meta name="charset" content="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
<mdui-dialog id="dialog" title="提示" open>
正在登录中,请稍后,登录后请手动刷新页面
</mdui-dialog>
<script>
setTimeout(function () {
var hashs = window.location.hash
if (hashs !== "") {
var exp = /(?<=#access_token\=).*(?=&token_type)/g
var res = hashs.match(exp)
if (res != null) {
var key = res[0]
var xhr = new XMLHttpRequest()
xhr.open('post', '/api/login?apikey=' + key);
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
window.opener = null;
window.open('', '_self');
window.close();
}
}
xhr.send()
}
}
}, 1000);
</script>
</body>
</html>

View File

@ -187,30 +187,12 @@
</div>
</div>
<script>
setTimeout(function () {
var hashs = window.location.hash
if (hashs !== "") {
var exp = /(?<=#access_token\=).*(?=&token_type)/g
var res = hashs.match(exp)
if (res != null) {
var key = res[0]
var xhr = new XMLHttpRequest()
xhr.open('post', '/api/login?apikey=' + key);
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
window.location.href = window.location.protocol + "//" + window.location.host + window.location.pathname
}
}
xhr.send()
}
}
}, 200);
var old_href = window.location.href
var old_href = window.location.protocol + "//" + window.location.host + "/api/callback"
var logined = Number("{{islogin}}")
function login() {
setTimeout(function () {
window.location.href = "{{ui.link}}/login?redirect_url=" + old_href
window.open("{{ui.link}}/login?redirect_url=" + old_href)
}, 100);
}
var page = 1
@ -235,7 +217,6 @@
window.parent.postMessage({ sacn_height: document.getElementsByClassName("root")[0].offsetHeight }, '*');
}
}, 0);
}
function show_more(ids) {
if (document.getElementById(ids).getElementsByClassName("comment-text")[0].classList.contains("comment-show-all")) {