chore(env): add bundled test accounts and seed admin
这个提交包含在:
@@ -1,7 +1,9 @@
|
||||
#include <drogon/drogon.h>
|
||||
|
||||
#include "csp/app_state.h"
|
||||
#include "csp/services/auth_service.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <filesystem>
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
@@ -11,6 +13,22 @@ int main(int argc, char** argv) {
|
||||
|
||||
csp::AppState::Instance().Init(db_path);
|
||||
|
||||
// Optional seed admin user for dev/test.
|
||||
{
|
||||
const char* u = std::getenv("CSP_SEED_ADMIN_USERNAME");
|
||||
const char* p = std::getenv("CSP_SEED_ADMIN_PASSWORD");
|
||||
if (u && p && std::string(u).size() > 0 && std::string(p).size() > 0) {
|
||||
try {
|
||||
csp::services::AuthService auth(csp::AppState::Instance().db());
|
||||
auth.Register(u, p);
|
||||
LOG_INFO << "seed admin user created: " << u;
|
||||
} catch (const std::exception& e) {
|
||||
// Most likely UNIQUE constraint (already exists)
|
||||
LOG_INFO << "seed admin user skipped: " << e.what();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// CORS (dev-friendly). In production, prefer reverse proxy same-origin.
|
||||
drogon::app().registerPreRoutingAdvice([](const drogon::HttpRequestPtr& req,
|
||||
drogon::AdviceCallback&& cb,
|
||||
|
||||
在新工单中引用
屏蔽一个用户