refactor(linuxdo): 重构 Linuxdo 账号绑定页面
- 移除了多余的 HTML 结构,将页面内容嵌入到 PHP 逻辑中 - 优化了 JavaScript 函数定义,提高了代码的可读性和可维护性 - 调整了页面样式,简化了 CSS 样式规则 - 重构了 PHP 代码,提高了代码的逻辑清晰度
This commit is contained in:
98
linuxdo.php
98
linuxdo.php
@@ -137,62 +137,46 @@ function get_curl($url, $post = 0, $referer = 0, $cookie = 0, $header = 0, $ua =
|
||||
curl_close($ch);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
?>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<style>
|
||||
html,
|
||||
body {
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<?php if (empty($row)) { ?>
|
||||
当前尚未有你的游戏账号,请选择<br>
|
||||
<a onclick="registerDirect">Linuxdo账号绑定</a></br>
|
||||
<input type="hidden" id="linuxdo" value="<?= $userInfo['user_username'] ?>">
|
||||
<script>
|
||||
function handleBind(account, linuxdo_account) {
|
||||
return fetch("/linuxdo?act=bind&account=" + account + "&connect_id=" + linuxdo_account).then(res => {
|
||||
const { password } = res.data
|
||||
location.href = "/play?account=" + document.getElementById("linuxdo").value + "&token=" + password;
|
||||
})
|
||||
}
|
||||
function processLogin(params = {}, connect_id) {
|
||||
const formData = new FormData();
|
||||
formData.append("serverId", "1");
|
||||
Object.entries(params).forEach(([key, value]) => formData.append(key, value));
|
||||
fetch("/api?act=reg", { method: "POST", body: formData }).then(res => {
|
||||
if (res.code == '0') {
|
||||
handleBind(res.data.account, connect_id)
|
||||
} else {
|
||||
showTips(res.msg, 6, 'error');
|
||||
return
|
||||
})
|
||||
if (empty($row)) {
|
||||
?>
|
||||
当前尚未有你的游戏账号,请选择<br>
|
||||
<a onclick="registerDirect">Linuxdo账号绑定</a></br>
|
||||
<input type="hidden" id="linuxdo" value="<?= $userInfo['user_username'] ?>">
|
||||
<script>
|
||||
function handleBind(account, linuxdo_account) {
|
||||
return fetch("/linuxdo?act=bind&account=" + account + "&connect_id=" + linuxdo_account).then(res => {
|
||||
const { password } = res.data
|
||||
location.href = "/play?account=" + document.getElementById("linuxdo").value + "&token=" + password;
|
||||
})
|
||||
}
|
||||
function registerDirect() {
|
||||
const linuxdo_account = document.getElementById("linuxdo").value;
|
||||
processLogin({ type: "1", account: linuxdo_account, password: "1", password2: "1" }, linuxdo_account)
|
||||
}
|
||||
function linkAccount() {
|
||||
const account = document.getElementById("account").value;
|
||||
const password = document.getElementById("password").value;
|
||||
const linuxdo_account = document.getElementById("linuxdo").value;
|
||||
processLogin({ type: "0", account, password, }, linuxdo_account)
|
||||
}
|
||||
}
|
||||
function processLogin(params = {}, connect_id) {
|
||||
const formData = new FormData();
|
||||
formData.append("serverId", "1");
|
||||
Object.entries(params).forEach(([key, value]) => formData.append(key, value));
|
||||
fetch("/api?act=reg", { method: "POST", body: formData }).then(res => {
|
||||
if (res.code == '0') {
|
||||
handleBind(res.data.account, connect_id)
|
||||
} else {
|
||||
showTips(res.msg, 6, 'error');
|
||||
return
|
||||
})
|
||||
})
|
||||
}
|
||||
function registerDirect() {
|
||||
const linuxdo_account = document.getElementById("linuxdo").value;
|
||||
processLogin({ type: "1", account: linuxdo_account, password: "1", password2: "1" }, linuxdo_account)
|
||||
}
|
||||
function linkAccount() {
|
||||
const account = document.getElementById("account").value;
|
||||
const password = document.getElementById("password").value;
|
||||
const linuxdo_account = document.getElementById("linuxdo").value;
|
||||
processLogin({ type: "0", account, password, }, linuxdo_account)
|
||||
}
|
||||
|
||||
</script>
|
||||
如果已有账号,请输入账号和密码<br>
|
||||
<input type="text" id="account" placeholder="请输入账号" onKeyUp="value = value.replace(/[\W]/g, '')" autocomplete="off"
|
||||
disableautocomplete>
|
||||
<input type="password" id="password" placeholder="请输入密码">
|
||||
<button type="submit" @click="linkAccount">绑定并登录</button>
|
||||
<?php } ?>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</script>
|
||||
如果已有账号,请输入账号和密码<br>
|
||||
<input type="text" id="account" placeholder="请输入账号" onKeyUp="value = value.replace(/[\W]/g, '')" autocomplete="off"
|
||||
disableautocomplete>
|
||||
<input type="password" id="password" placeholder="请输入密码">
|
||||
<button type="submit" @click="linkAccount">绑定并登录</button>
|
||||
<?php } ?>
|
||||
Reference in New Issue
Block a user