feat(gateway): 登录成功后更新 Users.last_login(v0.5.1)

启用 handleLogin 中被注释的 last_login 更新:经 DbC::call_msg 以
"$now" 哨兵(db 日期适配层转为服务端 UTC 时间)写入,失败按惯例
THROW_EX_CUSTOM 抛 500 由 wrapper 统一处理。README 版本节同步
(原仍停留在 0.3.0-security)。
This commit is contained in:
qing committed 2026-07-28 23:31:20 +08:00
1 parent 19d5b65625
commit b07dbf2da5
3 files changed
+21 -19

No files matched your search

+4 -2
View File
@@ -226,12 +226,14 @@ gateway/
## 版本
`0.3.0-security`(见 [src/main.cpp:27](src/main.cpp#L27))。启动时打印:
`0.5.1`(见 [src/main.cpp:29](src/main.cpp#L29))。启动时打印:
```
Gateway 0.3.0-security started (PBKDF2 + CAPTCHA + RateLimit)
Gateway 0.5.1 started
```
近期变更:登录成功后通过 db 更新 `Users.last_login`(`"$now"` 哨兵,db 日期适配层转为服务端当前 UTC 时间;更新失败经 THROW_EX_CUSTOM 抛 500,与其他步骤一致)。
## 依赖
- C++20(`g++`)
+16 -16
View File
@@ -26,7 +26,7 @@ using namespace qing;
namespace json = boost::json;
namespace po = boost::program_options;
constexpr const char *_VER = "0.5.0";
constexpr const char *_VER = "0.5.1";
//////////////////////////////////
#include <sstream>
@@ -811,21 +811,21 @@ http::response<http::string_body> handleLogin(
//stmt_upd.bind_text(1, username);
//stmt_upd.step();
//
// 新版调用db模块 无法通过DB上传时间戳目前
//json::value jv_upd = {
// {"action", "update"},
// {"table", "Users"},
// {"values", json::object{
// {"last_login", LocalTime::getCurrent()},
// }},
// {"where", json::object{
// {"username", username},
// }}
//};
//auto jv_db_r = DbC::call_http(jv_upd);
//auto obj_r = jv_db_r.as_object();
//auto success = obj_r["success"].as_bool();
//if (!success) THROW_EX_CUSTOM(HttpException, 2102, json::serialize(jv_db_r)+"Login (Update Step) Failed", 500, "/login");
// 新版调用db模块:values 中的 "$now" 哨兵由 db 日期适配层替换为服务端当前 UTC 时间
//(此前因 db 无法处理日期列而注释,dbv2 增加 _coerce_value 后可用)。
json::value jv_upd = {
{"action", "update"},
{"table", "Users"},
{"values", json::object{
{"last_login", "$now"},
}},
{"where", json::object{
{"username", username},
}}
};
auto jv_upd_r = DbC::call_msg(jv_upd);
if (!jv_upd_r.as_object()["success"].as_bool())
THROW_EX_CUSTOM(HttpException, 2102, "Login (Update Step) Failed", 500, "/login");
/* 生成令牌 */