修改后端登陆响应为json,修复登陆页面
This commit is contained in:
1 parent
0811dd7960
commit
0399715008
2 files changed
+8
-6
No files matched your search
@@ -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) {
|
||||
|
||||
@@ -146,16 +146,14 @@ 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}`);
|
||||
if (result.success) {
|
||||
alert(`登陆成功`);
|
||||
sessionStorage.setItem('token', result.data.token);
|
||||
location.href = 'main.html';
|
||||
} else {
|
||||
alert(result.message || '登录失败');
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
alert(err.message || '接口请求失败,请检查后端服务是否启动');
|
||||
console.error('登录请求异常:', err);
|
||||
|
||||
Reference in new issue
Block a user