!1 merge wei into main

对之前页面的修复

Created-by: qingss0
Commit-by: qing
Merged-by: qingss0
Description: 引入validation.js,修改Content-Type
注册修复
dos2unix
修改后端登陆响应为json,修复登陆页面

See merge request: qingss0/micro_servers!1
This commit is contained in:
qingss0 committed 2026-07-21 22:31:56 +08:00
commit 5940759088
6 files changed
+276 -275

No files matched your search

+5 -1
View File
@@ -359,9 +359,13 @@ http::response<http::string_body> handleLogin(
std::string token = Base64::base64_encode(data);
std::string sign = _PRIV.Sign(data);
json::value jv_rr = {
{"success", true},
{"data", json::object{{"token", token + "_" + sign}}} // 双大括号
};
res.set("Connection", "close");
res.result(http::status::ok);
res.body() = token + "_" + sign;
res.body() = json::serialize(jv_rr);
}
catch (const HttpException& e) {
+111 -113
View File
@@ -1,40 +1,40 @@
const msgTip = document.getElementById('msgTip');
const pwdTip = document.getElementById('pwdTip');
const emlTip = document.getElementById('emlTip');
const agreeTip = document.getElementById('agreeTip');
const form = document.getElementById('form');
const usernameInput = document.getElementById('loginUsername');
const passwordInput = document.getElementById('loginPassword');
const emailInput = document.getElementById('loginEmail');
const agreeBox = document.getElementById('agreeBox');
const msgTip = document.getElementById('msgTip');
const pwdTip = document.getElementById('pwdTip');
const emlTip = document.getElementById('emlTip');
const agreeTip = document.getElementById('agreeTip');
const form = document.getElementById('form');
const usernameInput = document.getElementById('loginUsername');
const passwordInput = document.getElementById('loginPassword');
const emailInput = document.getElementById('loginEmail');
const agreeBox = document.getElementById('agreeBox');
const protocol = document.getElementById('agreement');
const resetUser = document.getElementById('resetUser');
const registerBtn = document.getElementById('registerBtn');
const loginButton = document.getElementById('loginBtn');
resetUser.addEventListener('click', function() {
clearTipStyle();
resetUser.addEventListener('click', function() {
clearTipStyle();
});
function clearTipStyle() {
msgTip.innerHTML = '';
pwdTip.innerHTML = '';
agreeTip.innerHTML = '';
emlTip.innerHTML = '';
msgTip.classList.remove('tip-red', 'tip-yellow', 'tip-green');
pwdTip.classList.remove('tip-red', 'tip-yellow', 'tip-green');
agreeTip.classList.remove('tip-red', 'tip-yellow', 'tip-green');
emlTip.classList.remove('tip-red', 'tip-yellow', 'tip-green');
protocol.classList.remove('tip-red');
protocol.classList.remove('tip-green');
}
clearTipStyle();
/**
* @returns {string|false}
*/
function clearTipStyle() {
msgTip.innerHTML = '';
pwdTip.innerHTML = '';
agreeTip.innerHTML = '';
emlTip.innerHTML = '';
msgTip.classList.remove('tip-red', 'tip-yellow', 'tip-green');
pwdTip.classList.remove('tip-red', 'tip-yellow', 'tip-green');
agreeTip.classList.remove('tip-red', 'tip-yellow', 'tip-green');
emlTip.classList.remove('tip-red', 'tip-yellow', 'tip-green');
protocol.classList.remove('tip-red');
protocol.classList.remove('tip-green');
}
clearTipStyle();
/**
* @returns {string|false}
*/
function checkUsername() {
const result = FormValidators.username(usernameInput.value);
msgTip.innerHTML = '';
@@ -42,11 +42,11 @@ function checkUsername() {
msgTip.textContent = result.message;
msgTip.classList.add(result.className);
return result.valid ? result.value : false;
}
/**
* @returns {string|false}
*/
}
/**
* @returns {string|false}
*/
function checkPwd() {
const result = FormValidators.password(passwordInput.value);
pwdTip.innerHTML = '';
@@ -54,11 +54,11 @@ function checkPwd() {
pwdTip.textContent = result.message;
pwdTip.classList.add(result.className);
return result.valid ? result.value : false;
}
/**
* @returns {string|false}
*/
}
/**
* @returns {string|false}
*/
function checkEml() {
const result = FormValidators.email(emailInput.value);
emlTip.innerHTML = '';
@@ -66,71 +66,71 @@ function checkEml() {
emlTip.textContent = result.message;
emlTip.classList.add(result.className);
return result.valid ? result.value : false;
}
/**
* @returns {boolean}
*/
function checkAgree() {
agreeTip.innerHTML = '';
agreeTip.classList.remove('tip-red');
protocol.classList.remove('tip-green', 'tip-red');
if (!agreeBox.checked) {
agreeTip.innerHTML = '请同意用户协议!';
agreeTip.classList.add('tip-red');
protocol.classList.add('tip-red');
return false;
}
protocol.classList.add('tip-green');
return true;
}
usernameInput.addEventListener('focus', checkUsername);
passwordInput.addEventListener('focus', checkPwd);
usernameInput.addEventListener('input', checkUsername);
passwordInput.addEventListener('input', checkPwd);
usernameInput.addEventListener('blur', checkUsername);
passwordInput.addEventListener('blur', checkPwd);
emailInput.addEventListener('focus', checkEml);
emailInput.addEventListener('input', checkEml);
emailInput.addEventListener('blur', checkEml);
agreeBox.addEventListener('change', checkAgree);
registerBtn.addEventListener('click', function() {
location.href = 'register.html';
}
/**
* @returns {boolean}
*/
function checkAgree() {
agreeTip.innerHTML = '';
agreeTip.classList.remove('tip-red');
protocol.classList.remove('tip-green', 'tip-red');
if (!agreeBox.checked) {
agreeTip.innerHTML = '请同意用户协议!';
agreeTip.classList.add('tip-red');
protocol.classList.add('tip-red');
return false;
}
protocol.classList.add('tip-green');
return true;
}
usernameInput.addEventListener('focus', checkUsername);
passwordInput.addEventListener('focus', checkPwd);
usernameInput.addEventListener('input', checkUsername);
passwordInput.addEventListener('input', checkPwd);
usernameInput.addEventListener('blur', checkUsername);
passwordInput.addEventListener('blur', checkPwd);
emailInput.addEventListener('focus', checkEml);
emailInput.addEventListener('input', checkEml);
emailInput.addEventListener('blur', checkEml);
agreeBox.addEventListener('change', checkAgree);
registerBtn.addEventListener('click', function() {
location.href = 'register.html';
});
form.addEventListener('submit', async function(e) {
e.preventDefault();
clearTipStyle();
const userOk = checkUsername();
const pwdOk = checkPwd();
const emlOk = checkEml();
const agreeOk = checkAgree();
if (!(userOk && pwdOk && emlOk && agreeOk)) {
return;
}
const jsonBody = JSON.stringify({
username: userOk,
password: pwdOk
});
form.addEventListener('submit', async function(e) {
e.preventDefault();
clearTipStyle();
const userOk = checkUsername();
const pwdOk = checkPwd();
const emlOk = checkEml();
const agreeOk = checkAgree();
if (!(userOk && pwdOk && emlOk && agreeOk)) {
return;
}
const jsonBody = JSON.stringify({
username: userOk,
password: pwdOk
});
try {
loginButton.disabled = true;
const res = await fetch('/login', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: jsonBody
});
method: 'POST',
headers: {
'Content-Type': 'application/json' // 告诉服务器内容为json
},
body: jsonBody
});
const responseText = await res.text();
let result;
@@ -146,19 +146,17 @@ form.addEventListener('submit', async function(e) {
throw new Error(result.message || `登录失败(HTTP ${res.status})`);
}
if (result.code === 0) {
if (!result.data || !result.data.token || !result.data.username) {
throw new Error('登录成功,但服务器返回的数据不完整');
}
alert(`${result.message},账号:${result.data.username}`);
sessionStorage.setItem('token', result.data.token);
location.href = 'main.html';
} else {
if (result.success) {
alert(`登陆成功`);
sessionStorage.setItem('token', result.data.token);
location.href = 'main.html';
} else {
alert(result.message || '登录失败');
}
} catch (err) {
}
} catch (err) {
alert(err.message || '接口请求失败,请检查后端服务是否启动');
console.error('登录请求异常:', err);
console.error('登录请求异常:', err);
} finally {
loginButton.disabled = false;
}
+3 -5
View File
@@ -183,11 +183,8 @@ form.addEventListener('submit', async function (e) {
throw new Error(result.message || `注册失败(HTTP ${res.status})`);
}
if (result.code === 0) {
if (!result.data || !result.data.username) {
throw new Error('注册成功,但服务器返回的数据不完整');
}
alert(`${result.message},账号:${result.data.username}`);
if (result.success) {
alert('注册成功');
form.reset();
sendCode = '';
codeTarget = '';
@@ -196,6 +193,7 @@ form.addEventListener('submit', async function (e) {
}
alert(result.message || '注册失败');
} catch (err) {
console.error('注册请求异常:', err);
alert(err.message || '接口请求失败,请检查后端服务是否启动');
+40 -39
View File
@@ -1,47 +1,48 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<!-- 移动端适配核心标签 -->
<meta charset="utf-8">
<!-- 移动端适配核心标签 -->
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no">
<title>登录</title>
<style>
.tip-red {color:red;}
.tip-yellow {color: orange;}
.tip-green {color: greenyellow;}
<title>登录</title>
<style>
.tip-red {color:red;}
.tip-yellow {color: orange;}
.tip-green {color: greenyellow;}
</style>
</head>
<body>
<h2>用户登录</h2>
<form action="" id="form" method="post">
<div>
<label>用户名/推荐邮箱:</label>
<input type="text" id="loginUsername" name="username" placeholder="请输入用户名">
<span id="msgTip" ></span>
<br>
<label>密码:</label>
<input type="password" id="loginPassword" name="password" placeholder="请输入密码">
<span id="pwdTip"></span>
</div>
<div>
<label>验证邮箱:</label>
<input type="email" id="loginEmail" name="email" placeholder="请输入验证邮箱">
<span id="emlSub">
<input type="submit" value="发送验证码">
</span>
<span id="emlTip"></span>
</div>
<div>
<button type="button" id="registerBtn">注册</button>
<input type="submit" id="loginBtn" value="登录">
<input type="reset" id="resetUser" value="重置">
</div>
<div>
<input type="checkbox" id="agreeBox" name="agree" value="access">
<label id="agreement">同意该系统相关用户使用条例</label>
<span id="agreeTip"></span>
</div>
</form>
<body>
<h2>用户登录</h2>
<form action="" id="form" method="post">
<div>
<label>用户名/推荐邮箱:</label>
<input type="text" id="loginUsername" name="username" placeholder="请输入用户名">
<span id="msgTip" ></span>
<br>
<label>密码:</label>
<input type="password" id="loginPassword" name="password" placeholder="请输入密码">
<span id="pwdTip"></span>
</div>
<div>
<label>验证邮箱:</label>
<input type="email" id="loginEmail" name="email" placeholder="请输入验证邮箱">
<span id="emlSub">
<input type="submit" value="发送验证码">
</span>
<span id="emlTip"></span>
</div>
<div>
<button type="button" id="registerBtn">注册</button>
<input type="submit" id="loginBtn" value="登录">
<input type="reset" id="resetUser" value="重置">
</div>
<div>
<input type="checkbox" id="agreeBox" name="agree" value="access">
<label id="agreement">同意该系统相关用户使用条例</label>
<span id="agreeTip"></span>
</div>
</form>
<script src="js/validation.js"></script>
<script src="js/login.js"></script>
</body>
</html>
</html>
+101 -101
View File
@@ -1,102 +1,102 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<!-- 移动端适配核心标签 -->
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no">
<title>DNFS · 树状笔记</title>
<style></style>
</head>
<body>
<!-- 文章主标题 -->
<div id="article-title">
<h1>
<p>Python</p>
</h1>
</div>
<!-- 文章详情 -->
<div id="publish-time">
<p>发布时间:2026-07-11</p>
</div>
<div>
<span id="visit-count">浏览:126</span>
<span id="like-count">点赞:28</span>
<span id="share-count">分享:7</span>
</div>
<!-- 文章正文-->
<div id="article-content">
<p>
Python 的 <code>socket</code>
模块是网络编程的核心,其函数可分为<strong>核心套接字操作</strong>、<strong>套接字选项设置</strong>、<strong>辅助工具函数</strong>三大类。本文将逐一拆解所有函数的语法、参数、用法和实战示例,覆盖从基础到高级的所有场景。
</p>
<h2>一、模块初始化与核心对象</h2>
<h3>1. socket.socket():创建套接字对象</h3>
<p><strong>语法</strong>:</p>
<pre><code>socket.socket(family=AF_INET, type=SOCK_STREAM, proto=0, fileno=None)</code></pre>
<p><strong>作用</strong>:创建一个套接字对象,是所有网络操作的基础。</p>
<p><strong>参数说明</strong>:</p>
<table>
<tr>
<th>参数</th>
<th>取值</th>
<th>说明</th>
</tr>
<tr>
<td><code>family</code></td>
<td><code>AF_INET</code>(默认)</td>
<td>IPv4 协议族(最常用)</td>
</tr>
<tr>
<td></td>
<td><code>AF_INET6</code></td>
<td>IPv6 协议族</td>
</tr>
<tr>
<td></td>
<td><code>AF_UNIX</code></td>
<td>Unix 域套接字(本地进程通信)</td>
</tr>
<tr>
<td><code>type</code></td>
<td><code>SOCK_STREAM</code>(默认)</td>
<td>TCP 套接字(面向连接、可靠)</td>
</tr>
<tr>
<td></td>
<td><code>SOCK_DGRAM</code></td>
<td>UDP 套接字(无连接、数据报)</td>
</tr>
<tr>
<td></td>
<td><code>SOCK_RAW</code></td>
<td>原始套接字(可操作 IP 层,用于抓包)</td>
</tr>
<tr>
<td><code>proto</code></td>
<td>0(默认)</td>
<td>协议编号,默认自动匹配 type(TCP=6,UDP=17)</td>
</tr>
<tr>
<td><code>fileno</code></td>
<td>None(默认)</td>
<td>复用已有文件描述符,无需手动指定</td>
</tr>
</table>
</div>
<div class="other-recommend">
<h3>其他推荐</h3>
</div>
<div class="recommend-list" id="recommend-list">
<ul>
<li><a href="https://www.baidu.com">百度推荐</a></li>
<li><a href="https://www.baidu.com">百度推荐</a></li>
<li><a href="https://www.baidu.com">百度推荐</a></li>
<li><a href="https://www.baidu.com">百度推荐</a></li>
<li><a href="https://www.baidu.com">百度推荐</a></li>
</ul>
</div>
</body>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<!-- 移动端适配核心标签 -->
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no">
<title>DNFS · 树状笔记</title>
<style></style>
</head>
<body>
<!-- 文章主标题 -->
<div id="article-title">
<h1>
<p>Python</p>
</h1>
</div>
<!-- 文章详情 -->
<div id="publish-time">
<p>发布时间:2026-07-11</p>
</div>
<div>
<span id="visit-count">浏览:126</span>
<span id="like-count">点赞:28</span>
<span id="share-count">分享:7</span>
</div>
<!-- 文章正文-->
<div id="article-content">
<p>
Python 的 <code>socket</code>
模块是网络编程的核心,其函数可分为<strong>核心套接字操作</strong>、<strong>套接字选项设置</strong>、<strong>辅助工具函数</strong>三大类。本文将逐一拆解所有函数的语法、参数、用法和实战示例,覆盖从基础到高级的所有场景。
</p>
<h2>一、模块初始化与核心对象</h2>
<h3>1. socket.socket():创建套接字对象</h3>
<p><strong>语法</strong>:</p>
<pre><code>socket.socket(family=AF_INET, type=SOCK_STREAM, proto=0, fileno=None)</code></pre>
<p><strong>作用</strong>:创建一个套接字对象,是所有网络操作的基础。</p>
<p><strong>参数说明</strong>:</p>
<table>
<tr>
<th>参数</th>
<th>取值</th>
<th>说明</th>
</tr>
<tr>
<td><code>family</code></td>
<td><code>AF_INET</code>(默认)</td>
<td>IPv4 协议族(最常用)</td>
</tr>
<tr>
<td></td>
<td><code>AF_INET6</code></td>
<td>IPv6 协议族</td>
</tr>
<tr>
<td></td>
<td><code>AF_UNIX</code></td>
<td>Unix 域套接字(本地进程通信)</td>
</tr>
<tr>
<td><code>type</code></td>
<td><code>SOCK_STREAM</code>(默认)</td>
<td>TCP 套接字(面向连接、可靠)</td>
</tr>
<tr>
<td></td>
<td><code>SOCK_DGRAM</code></td>
<td>UDP 套接字(无连接、数据报)</td>
</tr>
<tr>
<td></td>
<td><code>SOCK_RAW</code></td>
<td>原始套接字(可操作 IP 层,用于抓包)</td>
</tr>
<tr>
<td><code>proto</code></td>
<td>0(默认)</td>
<td>协议编号,默认自动匹配 type(TCP=6,UDP=17)</td>
</tr>
<tr>
<td><code>fileno</code></td>
<td>None(默认)</td>
<td>复用已有文件描述符,无需手动指定</td>
</tr>
</table>
</div>
<div class="other-recommend">
<h3>其他推荐</h3>
</div>
<div class="recommend-list" id="recommend-list">
<ul>
<li><a href="https://www.baidu.com">百度推荐</a></li>
<li><a href="https://www.baidu.com">百度推荐</a></li>
<li><a href="https://www.baidu.com">百度推荐</a></li>
<li><a href="https://www.baidu.com">百度推荐</a></li>
<li><a href="https://www.baidu.com">百度推荐</a></li>
</ul>
</div>
</body>
</html>
+16 -16
View File
@@ -1,32 +1,32 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no">
<title>注册页面</title>
<style>
.tip-red {color:red;}
.tip-yellow {color: orange;}
.tip-green {color: greenyellow;}
<title>注册页面</title>
<style>
.tip-red {color:red;}
.tip-yellow {color: orange;}
.tip-green {color: greenyellow;}
</style>
</head>
<body>
<h2>注册页面</h2>
<body>
<h2>注册页面</h2>
<form id="form">
<div>
<label>用户名/推荐邮箱:</label>
<input type="text" id="regusername" placeholder="请输入用户名">
<span id="msgTip" ></span>
<br>
<label>邮箱号:</label>
<div>
<label>用户名/推荐邮箱:</label>
<input type="text" id="regusername" placeholder="请输入用户名">
<span id="msgTip" ></span>
<br>
<label>邮箱号:</label>
<input type="email" id="regemail" placeholder="请输入邮箱号">
<div class="code-box">验证码:
<input type="text" id="code" placeholder="请输入6位验证码" inputmode="numeric" maxlength="6">
<input type="button" id="getCode" value="获取验证码">
<span id="codeTip"></span>
</div>
<span id="emlTip"></span>
<br>
<span id="emlTip"></span>
<br>
<label>密码:</label>
<input type="password" id="regpsw" placeholder="密码至少6位">
<label>验证密码:</label>