优化 Linuxdo 登录绑定流程及界面显示
This commit is contained in:
52
linuxdo.php
52
linuxdo.php
@@ -110,15 +110,16 @@ if (isset($getTokenArr['access_token'])) {
|
|||||||
<meta name="keywords" content="<?= $_CONFIG['game_name'] ?>,<?= $_CONFIG['game_description'] ?>">
|
<meta name="keywords" content="<?= $_CONFIG['game_name'] ?>,<?= $_CONFIG['game_description'] ?>">
|
||||||
|
|
||||||
<link rel="stylesheet" href="static/css/login.css?v=1.1.6" />
|
<link rel="stylesheet" href="static/css/login.css?v=1.1.6" />
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
function request(url, params){
|
function request(url, params) {
|
||||||
return fetch(url, params).then(res => res.json())
|
return fetch(url, params).then(res => res.json())
|
||||||
}
|
}
|
||||||
function handleBind(account, linuxdo_account) {
|
function handleBind(account, linuxdo_account) {
|
||||||
return request("/linuxdo?act=bind&account=" + account + "&connect_id=" + linuxdo_account).then(res => {
|
return request("/api?act=bind&account=" + account + "&connect_id=" + linuxdo_account).then(res => {
|
||||||
const { password } = res.data
|
if (res.password) {
|
||||||
location.href = "/play?account=" + document.getElementById("linuxdo").value + "&token=" + password;
|
alert("绑定成功,请点击确定开始游戏!")
|
||||||
|
location.href = "/play?account=" + account + "&token=" + res.password;
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
function processLogin(params = {}, connect_id) {
|
function processLogin(params = {}, connect_id) {
|
||||||
@@ -127,7 +128,7 @@ if (isset($getTokenArr['access_token'])) {
|
|||||||
Object.entries(params).forEach(([key, value]) => formData.append(key, value));
|
Object.entries(params).forEach(([key, value]) => formData.append(key, value));
|
||||||
request("/api?act=reg", { method: "POST", body: formData }).then(res => {
|
request("/api?act=reg", { method: "POST", body: formData }).then(res => {
|
||||||
if (res.code == '0') {
|
if (res.code == '0') {
|
||||||
handleBind(res.data.account, connect_id)
|
handleBind(params.account, connect_id)
|
||||||
} else {
|
} else {
|
||||||
document.body.innerHTML = "授权失败"
|
document.body.innerHTML = "授权失败"
|
||||||
return
|
return
|
||||||
@@ -137,7 +138,7 @@ if (isset($getTokenArr['access_token'])) {
|
|||||||
|
|
||||||
function registerDirect() {
|
function registerDirect() {
|
||||||
const linuxdo_account = document.getElementById("linuxdo").value;
|
const linuxdo_account = document.getElementById("linuxdo").value;
|
||||||
processLogin({ type: "1", account: linuxdo_account, password: "1", password2: "1" }, linuxdo_account)
|
processLogin({ type: "1", account: linuxdo_account, password: "linuxdo", password2: "linuxdo" }, linuxdo_account)
|
||||||
}
|
}
|
||||||
function linkAccount() {
|
function linkAccount() {
|
||||||
const account = document.getElementById("account").value;
|
const account = document.getElementById("account").value;
|
||||||
@@ -149,37 +150,38 @@ if (isset($getTokenArr['access_token'])) {
|
|||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body oncontextmenu="return false" onselectstart="return false" ondragstart="return false">
|
<body>
|
||||||
<input type="hidden" id="linuxdo" value="<?= $getUserArr['username'] ?>">
|
<input type="hidden" id="linuxdo" value="<?= $getUserArr['username'] ?>">
|
||||||
<?php if (!empty($getUserArr['username'])) { ?>
|
<?php if (!empty($getUserArr['username'])) { ?>
|
||||||
<script>
|
<script>
|
||||||
const connectId = document.getElementById('linuxdo').value
|
const connectId = document.getElementById('linuxdo').value
|
||||||
request("/api?act=link&connect_id=" + connectId,{method:"POST"}).then(res => {
|
request("/api?act=link&connect_id=" + connectId, { method: "POST" }).then(res => {
|
||||||
if (res.code == '0') {
|
if (res.code == '0') {
|
||||||
location.href = "/play?account=" + res.data.username + "&token=" + res.data.password;
|
location.href = "/play?account=" + res.data.username + "&token=" + res.data.password;
|
||||||
} else {
|
} else {
|
||||||
document.body.innerHTML = "授权失败"
|
document.getElementById("bindBox").style.display = "block"
|
||||||
|
const linkAccountBtn = document.getElementById("linkAccount");
|
||||||
|
linkAccountBtn.addEventListener("click", linkAccount)
|
||||||
|
const registerDirectBtn = document.getElementById("registerDirect");
|
||||||
|
registerDirectBtn.addEventListener("click", registerDirect)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
<div id="bindBox"
|
||||||
|
style="width:400px;position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);display:flex;justify-content:center;align-items:center;flex-direction:column;display:none;">
|
||||||
|
<div>当前尚未有你的游戏账号,请选择</div><br>
|
||||||
|
<a id="registerDirect" onclick="registerDirect" style="cursor:pointer;font-weight:bold">Linuxdo账号绑定</a><br>
|
||||||
|
<div>如果已有账号,请输入账号和密码</div><br>
|
||||||
|
<input type="text" id="account" placeholder="请输入账号" onKeyUp="value = value.replace(/[\W]/g, '')"
|
||||||
|
autocomplete="off" disableautocomplete><br>
|
||||||
|
<input type="password" id="password" placeholder="请输入密码"><br>
|
||||||
|
<button id="linkAccount">绑定并登录</button>
|
||||||
|
</div>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
<?php if (!empty($err)) { ?>
|
<?php if (!empty($err)) { ?>
|
||||||
授权发生异常:<?= $err ?>
|
授权发生异常:<?= $err ?>
|
||||||
<?php } elseif ($getCheckLink['code'] == '1') { ?>
|
|
||||||
<div
|
|
||||||
style="width:400px;position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);display:flex;justify-content:center;align-items:center;flex-direction:column;">
|
|
||||||
当前尚未有你的游戏账号,请选择<br>
|
|
||||||
<a onclick="registerDirect" style="cursor:pointer;font-weight:bold">Linuxdo账号绑定</a><br>
|
|
||||||
如果已有账号,请输入账号和密码
|
|
||||||
<br>
|
|
||||||
<input type="text" id="account" placeholder="请输入账号" onKeyUp="value = value.replace(/[\W]/g, '')"
|
|
||||||
autocomplete="off" disableautocomplete>
|
|
||||||
<br>
|
|
||||||
<input type="password" id="password" placeholder="请输入密码">
|
|
||||||
<br>
|
|
||||||
<button type="submit" onclick="linkAccount">绑定并登录</button>
|
|
||||||
</div>
|
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
Reference in New Issue
Block a user