From 00fd3f6e36ff534f968cfaf31ff3e27bbc0f4b8b Mon Sep 17 00:00:00 2001 From: qicosmos Date: Sat, 10 Feb 2024 15:51:12 +0800 Subject: [PATCH] do some fix --- "docs/featehr \344\275\277\347\224\250.md" | 25 +++++++++++++++++++++- main.cpp | 2 +- purecpp_controller.hpp | 1 + validate.hpp | 20 +++++++++++++---- 4 files changed, 42 insertions(+), 6 deletions(-) diff --git "a/docs/featehr \344\275\277\347\224\250.md" "b/docs/featehr \344\275\277\347\224\250.md" index f9786e4..f17f5d1 100644 --- "a/docs/featehr \344\275\277\347\224\250.md" +++ "b/docs/featehr \344\275\277\347\224\250.md" @@ -18,6 +18,29 @@ 3. 运行 +建立数据库feather + +导入数据库表 source feather.sql + +成功导入后,应该可以看到如下的表结构: + ++-----------------------+ +| Tables_in_feather | ++-----------------------+ +| article | +| article_detail | +| cncppcon2018_user | +| pp_comment | +| pp_post_views | +| pp_posts | +| pp_sign_out_answer | +| pp_terms | +| pp_user | +| user | +| visit_counter | +| wp_term_relationships | ++-----------------------+ + * 创建运行时需要的目录结构 在`feather`目录下执行(此处假设构建目录为`feather/build`): @@ -48,4 +71,4 @@ * 访问 - **注意**:在数据库无数据的时候无法看到页面,可以通过访问:`http://localhost:8080/sign_out_page`注册用户并发表一篇文章。这时其他页面就可以访问了。 \ No newline at end of file + **注意**:在数据库无数据的时候无法看到页面,可以通过访问:`http://localhost:8080/sign_up_page`注册用户并发表一篇文章。这时其他页面就可以访问了。 \ No newline at end of file diff --git a/main.cpp b/main.cpp index 132abc1..b30b0b7 100644 --- a/main.cpp +++ b/main.cpp @@ -69,7 +69,7 @@ int main() { init(cfg); cinatra::http_server server(cfg.thread_num, atoi(cfg.port.data())); - server.set_static_res_dir("", "static"); + server.set_static_res_dir("", ""); server.set_max_size_of_cache_files(1024 * 1024); purecpp_controller purecpp_ctl; diff --git a/purecpp_controller.hpp b/purecpp_controller.hpp index 01516d8..1db7b8d 100644 --- a/purecpp_controller.hpp +++ b/purecpp_controller.hpp @@ -69,6 +69,7 @@ class purecpp_controller { if (!session || !session->get_data("user_name").has_value()) { auto new_session = req.get_session(); new_session->set_session_timeout(); + session = new_session; } size_t cur_page = atoi(s.data()) / 10 + 1; diff --git a/validate.hpp b/validate.hpp index 83ce21e..1659549 100644 --- a/validate.hpp +++ b/validate.hpp @@ -8,15 +8,27 @@ namespace feather { inline std::vector get_user_info(request& req) { auto session = req.get_session(); - return {session->get_data("user_name").value(), - session->get_data("userid").value(), - session->get_data("user_role").value()}; + std::vector v; + if (auto opt = session->get_data("user_name"); opt) { + v.push_back(opt.value()); + } + if (auto opt = session->get_data("userid"); opt) { + v.push_back(opt.value()); + } + if (auto opt = session->get_data("user_role"); opt) { + v.push_back(opt.value()); + } + return v; } inline std::string get_value_from_session(request& req, const std::string& key) { auto session = req.get_session(); - return session->get_data(key).value(); + auto result = session->get_data(key); + if (result) { + return result.value(); + } + return ""; } inline std::string get_user_name_from_session(request& req) {