Skip to content

Commit

Permalink
do some fix
Browse files Browse the repository at this point in the history
  • Loading branch information
qicosmos committed Feb 10, 2024
1 parent 58be3fa commit 00fd3f6
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 6 deletions.
25 changes: 24 additions & 1 deletion docs/featehr 使用.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`):
Expand Down Expand Up @@ -48,4 +71,4 @@

* 访问

**注意**:在数据库无数据的时候无法看到页面,可以通过访问:`http://localhost:8080/sign_out_page`注册用户并发表一篇文章。这时其他页面就可以访问了。
**注意**:在数据库无数据的时候无法看到页面,可以通过访问:`http://localhost:8080/sign_up_page`注册用户并发表一篇文章。这时其他页面就可以访问了。
2 changes: 1 addition & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions purecpp_controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class purecpp_controller {
if (!session || !session->get_data<std::string>("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;
Expand Down
20 changes: 16 additions & 4 deletions validate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,27 @@ namespace feather {

inline std::vector<std::string> get_user_info(request& req) {
auto session = req.get_session();
return {session->get_data<std::string>("user_name").value(),
session->get_data<std::string>("userid").value(),
session->get_data<std::string>("user_role").value()};
std::vector<std::string> v;
if (auto opt = session->get_data<std::string>("user_name"); opt) {
v.push_back(opt.value());
}
if (auto opt = session->get_data<std::string>("userid"); opt) {
v.push_back(opt.value());
}
if (auto opt = session->get_data<std::string>("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<std::string>(key).value();
auto result = session->get_data<std::string>(key);
if (result) {
return result.value();
}
return "";
}

inline std::string get_user_name_from_session(request& req) {
Expand Down

0 comments on commit 00fd3f6

Please sign in to comment.