Initial project setup.
17
SConstruct
@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (c) 2019-2021 Péter Magyar
|
||||
# Copyright (c) 2019-2020 Péter Magyar
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
@ -40,6 +40,8 @@ module_folders = [
|
||||
'../custom_modules',
|
||||
]
|
||||
|
||||
databases=True
|
||||
|
||||
main_file = 'main.cpp'
|
||||
|
||||
repository_index = 0
|
||||
@ -58,7 +60,7 @@ exports = {
|
||||
'javascript': [],
|
||||
}
|
||||
|
||||
engine_repository = [ ['https://github.com/Relintai/rcpp_framework.git', 'git@github.com:Relintai/rcpp_framework.git'], 'engine', '' ]
|
||||
engine_repository = [ ['https://github.com/Relintai/rcpp_cms.git', 'git@github.com:Relintai/rcpp_cms.git'], 'engine', '' ]
|
||||
|
||||
module_repositories = [
|
||||
]
|
||||
@ -336,6 +338,9 @@ if len(sys.argv) > 1:
|
||||
if 'v' in arg:
|
||||
build_string += 'vsproj=yes'
|
||||
|
||||
if databases:
|
||||
build_string += " databases=yes "
|
||||
|
||||
build_string += 'folders="'
|
||||
|
||||
for f in folders:
|
||||
@ -344,14 +349,6 @@ if len(sys.argv) > 1:
|
||||
|
||||
build_string += '" '
|
||||
|
||||
build_string += 'module_folders="'
|
||||
|
||||
for f in module_folders:
|
||||
build_string += f
|
||||
build_string += ';'
|
||||
|
||||
build_string += '" '
|
||||
|
||||
build_string += 'main_file="../' + main_file + '" '
|
||||
|
||||
for i in range(2, len(sys.argv)):
|
||||
|
198
app/mourne_application.cpp
Normal file
@ -0,0 +1,198 @@
|
||||
#include "mourne_application.h"
|
||||
|
||||
#include "core/http/request.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "core/file_cache.h"
|
||||
|
||||
#include "core/http/handler_instance.h"
|
||||
|
||||
#include "core/database/database_manager.h"
|
||||
|
||||
#include "core/html/html_builder.h"
|
||||
#include "core/http/http_session.h"
|
||||
#include "core/http/session_manager.h"
|
||||
|
||||
#include "modules/users/user.h"
|
||||
#include "modules/users/user_controller.h"
|
||||
|
||||
void MourneApplication::index(Object *instance, Request *request) {
|
||||
add_menu(request, MENUENTRY_NEWS);
|
||||
|
||||
//dynamic_cast<ListPage *>(instance)->index(request);
|
||||
request->body += "test";
|
||||
request->compile_and_send_body();
|
||||
}
|
||||
|
||||
void MourneApplication::session_middleware_func(Object *instance, Request *request) {
|
||||
std::cout << "test: session_middleware_func called" << std::endl;
|
||||
|
||||
//if fail
|
||||
//request->send(); in middleware
|
||||
|
||||
request->next_stage();
|
||||
}
|
||||
|
||||
void MourneApplication::add_menu(Request *request, const MenuEntries index) {
|
||||
request->head += menu_head;
|
||||
request->body += menu_strings[index];
|
||||
request->footer = footer;
|
||||
}
|
||||
|
||||
void MourneApplication::village_page_func(Object *instance, Request *request) {
|
||||
add_menu(request, MENUENTRY_VILLAGE);
|
||||
|
||||
//dynamic_cast<ListPage *>(instance)->index(request);
|
||||
request->body += "test";
|
||||
request->compile_and_send_body();
|
||||
}
|
||||
|
||||
void MourneApplication::user_page_func(Object *instance, Request *request) {
|
||||
add_menu(request, MENUENTRY_SETTINGS);
|
||||
|
||||
UserController::get_singleton()->handle_request_default(request);
|
||||
}
|
||||
|
||||
void MourneApplication::setup_routes() {
|
||||
DWebApplication::setup_routes();
|
||||
|
||||
index_func = HandlerInstance(index);
|
||||
main_route_map["village"] = HandlerInstance(village_page_func);
|
||||
main_route_map["user"] = HandlerInstance(user_page_func);
|
||||
}
|
||||
|
||||
void MourneApplication::setup_middleware() {
|
||||
middlewares.push_back(HandlerInstance(::SessionManager::session_setup_middleware));
|
||||
middlewares.push_back(HandlerInstance(::UserController::user_session_setup_middleware));
|
||||
|
||||
DWebApplication::setup_middleware();
|
||||
}
|
||||
|
||||
void MourneApplication::migrate() {
|
||||
}
|
||||
|
||||
void MourneApplication::compile_menu() {
|
||||
|
||||
for (int i = 0; i < MENUENTRY_MAX; ++i) {
|
||||
HTMLBuilder b;
|
||||
|
||||
HTMLTag *t;
|
||||
|
||||
b.div()->cls("content");
|
||||
{
|
||||
|
||||
b.ul()->cls("menu");
|
||||
{
|
||||
b.li();
|
||||
t = b.a()->href("/");
|
||||
|
||||
if (i == MENUENTRY_NEWS) {
|
||||
t->cls("menu_active");
|
||||
}
|
||||
|
||||
b.w("TSITE");
|
||||
b.ca();
|
||||
b.cli();
|
||||
|
||||
b.li();
|
||||
t = b.a()->href("/village/selected");
|
||||
|
||||
if (i == MENUENTRY_VILLAGE) {
|
||||
t->cls("menu_active");
|
||||
}
|
||||
|
||||
b.w("Projects");
|
||||
b.ca();
|
||||
b.cli();
|
||||
|
||||
b.li();
|
||||
{
|
||||
t = b.a()->href("/village/select");
|
||||
|
||||
if (i == MENUENTRY_SELECT_VILLAGE) {
|
||||
t->cls("menu_active");
|
||||
}
|
||||
|
||||
b.w("Classes");
|
||||
b.ca();
|
||||
}
|
||||
b.cli();
|
||||
|
||||
b.li();
|
||||
{
|
||||
t = b.a()->href("/user/login");
|
||||
b.w("Login");
|
||||
b.ca();
|
||||
}
|
||||
b.cli();
|
||||
|
||||
b.li();
|
||||
{
|
||||
t = b.a()->href("/user/register");
|
||||
b.w("Register");
|
||||
b.ca();
|
||||
}
|
||||
b.cli();
|
||||
|
||||
b.li();
|
||||
{
|
||||
t = b.a()->href("/user/settings");
|
||||
b.w("Profile");
|
||||
b.ca();
|
||||
}
|
||||
b.cli();
|
||||
|
||||
b.li();
|
||||
{
|
||||
t = b.a()->href("/user/logout");
|
||||
b.w("Logout");
|
||||
b.ca();
|
||||
}
|
||||
b.cli();
|
||||
}
|
||||
b.cul();
|
||||
}
|
||||
b.div()->cls("inner_content");
|
||||
b.write_tag();
|
||||
|
||||
menu_strings.push_back(b.result);
|
||||
}
|
||||
|
||||
HTMLBuilder bh;
|
||||
|
||||
bh.meta()->charset_utf_8();
|
||||
|
||||
bh.link()->rel_stylesheet()->href("/css/main.css");
|
||||
bh.write_tag();
|
||||
|
||||
menu_head = bh.result;
|
||||
|
||||
HTMLBuilder bf;
|
||||
|
||||
bf.cdiv();
|
||||
bf.footer();
|
||||
bf.w("Powered by ");
|
||||
bf.a()->href("https://github.com/Relintai/rcpp_cms");
|
||||
bf.w("rcpp cms");
|
||||
bf.ca();
|
||||
bf.w(".");
|
||||
bf.cfooter();
|
||||
|
||||
bf.cdiv();
|
||||
|
||||
footer = bf.result;
|
||||
}
|
||||
|
||||
MourneApplication::MourneApplication() :
|
||||
DWebApplication() {
|
||||
|
||||
compile_menu();
|
||||
}
|
||||
|
||||
MourneApplication::~MourneApplication() {
|
||||
}
|
||||
|
||||
std::vector<std::string> MourneApplication::menu_strings;
|
||||
std::string MourneApplication::menu_head = "";
|
||||
std::string MourneApplication::footer = "";
|
56
app/mourne_application.h
Normal file
@ -0,0 +1,56 @@
|
||||
#ifndef RDN_APPLICATION_H
|
||||
#define RDN_APPLICATION_H
|
||||
|
||||
//#include "core/http/web_application.h"
|
||||
#include "core/object.h"
|
||||
#include "modules/drogon/web_application.h"
|
||||
|
||||
#include "modules/list_page/list_page.h"
|
||||
#include "modules/message_page/message_page.h"
|
||||
#include "modules/paged_article/paged_article.h"
|
||||
#include "modules/paged_list/paged_list.h"
|
||||
|
||||
class MourneApplication : public DWebApplication {
|
||||
public:
|
||||
enum MenuEntries {
|
||||
MENUENTRY_NEWS = 0,
|
||||
MENUENTRY_MAIL,
|
||||
MENUENTRY_HERO,
|
||||
MENUENTRY_VILLAGE,
|
||||
MENUENTRY_SELECT_VILLAGE,
|
||||
MENUENTRY_ALLIANCE,
|
||||
MENUENTRY_ALLIANCE_MENU,
|
||||
MENUENTRY_FORUM,
|
||||
MENUENTRY_CHANGELOG,
|
||||
MENUENTRY_SETTINGS,
|
||||
MENUENTRY_LOGOUT,
|
||||
|
||||
MENUENTRY_MAX,
|
||||
};
|
||||
|
||||
public:
|
||||
static void index(Object *instance, Request *request);
|
||||
|
||||
static void session_middleware_func(Object *instance, Request *request);
|
||||
|
||||
static void add_menu(Request *request, const MenuEntries index);
|
||||
|
||||
static void village_page_func(Object *instance, Request *request);
|
||||
static void user_page_func(Object *instance, Request *request);
|
||||
|
||||
virtual void setup_routes();
|
||||
virtual void setup_middleware();
|
||||
|
||||
virtual void migrate();
|
||||
|
||||
void compile_menu();
|
||||
|
||||
MourneApplication();
|
||||
~MourneApplication();
|
||||
|
||||
static std::vector<std::string> menu_strings;
|
||||
static std::string menu_head;
|
||||
static std::string footer;
|
||||
};
|
||||
|
||||
#endif
|
81
main.cpp
@ -2,48 +2,47 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "core/http/web_application.h"
|
||||
#include "core/file_cache.h"
|
||||
#include "core/bry_http/http_server.h"
|
||||
#include "core/file_cache.h"
|
||||
#include "core/http/web_application.h"
|
||||
|
||||
#include "core/database/database_manager.h"
|
||||
#include "app/mourne_application.h"
|
||||
|
||||
#include "database/db_init.h"
|
||||
|
||||
#include "core/settings.h"
|
||||
|
||||
#define MAIN_CLASS ICApplication
|
||||
#include "core/http/session_manager.h"
|
||||
|
||||
#define MAIN_CLASS MourneApplication
|
||||
|
||||
#include "modules/drogon/web_application.h"
|
||||
|
||||
//Backends
|
||||
#include "backends/hash_hashlib/setup.h"
|
||||
|
||||
#include "modules/users/user.h"
|
||||
#include "modules/users/user_controller.h"
|
||||
#include "modules/users/user_model.h"
|
||||
|
||||
#include "core/database/database_manager.h"
|
||||
|
||||
void initialize_backends() {
|
||||
initialize_database_backends();
|
||||
backend_hash_hashlib_install_providers();
|
||||
}
|
||||
|
||||
void create_databases() {
|
||||
|
||||
//Settings *settings = Settings::get_singleton();
|
||||
|
||||
//if (!settings) {
|
||||
// printf("create_databases: Settings singleton is null!");
|
||||
// return;
|
||||
//}
|
||||
|
||||
/*
|
||||
rapidjson::Value dbs = settings->settings["databases"];
|
||||
|
||||
if (!dbs.IsArray()) {
|
||||
printf("create_databases: dbs !dbs.IsArray()!");
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
DatabaseManager *dbm = DatabaseManager::get_singleton();
|
||||
|
||||
//uint32_t index = dbm->create_database("mysql");
|
||||
//Database *db = dbm->databases[0];
|
||||
//db->connect("");
|
||||
|
||||
uint32_t index = dbm->create_database("sqlite");
|
||||
Database *db = dbm->databases[index];
|
||||
db->connect("database.sqlite");
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
initialize_backends();
|
||||
|
||||
bool migrate = false;
|
||||
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
@ -54,46 +53,54 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
}
|
||||
|
||||
initialize_database_backends();
|
||||
::SessionManager *session_manager = new ::SessionManager();
|
||||
|
||||
//todo init these in the module automatically
|
||||
UserController *user_controller = new UserController();
|
||||
UserModel *user_model = new UserModel();
|
||||
//user_manager->set_path("./users/");
|
||||
|
||||
Settings *settings = new Settings(true);
|
||||
|
||||
settings->parse_file("settings.json");
|
||||
|
||||
FileCache *file_cache = new FileCache(true);
|
||||
file_cache->wwwroot = "./content/www";
|
||||
file_cache->wwwroot = "./www";
|
||||
file_cache->wwwroot_refresh_cache();
|
||||
|
||||
DatabaseManager *dbm = new DatabaseManager();
|
||||
|
||||
create_databases();
|
||||
|
||||
WebApplication *app = new MAIN_CLASS();
|
||||
DWebApplication *app = new MAIN_CLASS();
|
||||
|
||||
session_manager->load_sessions();
|
||||
|
||||
app->load_settings();
|
||||
app->setup_routes();
|
||||
app->setup_middleware();
|
||||
|
||||
HTTPServer *server = new HTTPServer();
|
||||
server->application = app;
|
||||
|
||||
server->port = 8080;
|
||||
server->initialize();
|
||||
app->add_listener("127.0.0.1", 8080);
|
||||
LOG_INFO << "Server running on 127.0.0.1:8080";
|
||||
|
||||
if (!migrate) {
|
||||
printf("Initialized!\n");
|
||||
|
||||
server->main_loop();
|
||||
app->run();
|
||||
} else {
|
||||
printf("Running migrations.\n");
|
||||
|
||||
session_manager->migrate();
|
||||
user_model->migrate();
|
||||
|
||||
app->migrate();
|
||||
}
|
||||
|
||||
delete server;
|
||||
delete app;
|
||||
delete dbm;
|
||||
delete file_cache;
|
||||
delete settings;
|
||||
delete user_controller;
|
||||
delete user_model;
|
||||
delete session_manager;
|
||||
|
||||
return 0;
|
||||
}
|
Before Width: | Height: | Size: 180 B After Width: | Height: | Size: 180 B |
Before Width: | Height: | Size: 211 B After Width: | Height: | Size: 211 B |
Before Width: | Height: | Size: 115 B After Width: | Height: | Size: 115 B |
Before Width: | Height: | Size: 135 B After Width: | Height: | Size: 135 B |
Before Width: | Height: | Size: 131 B After Width: | Height: | Size: 131 B |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 95 B After Width: | Height: | Size: 95 B |
Before Width: | Height: | Size: 98 B After Width: | Height: | Size: 98 B |
Before Width: | Height: | Size: 117 B After Width: | Height: | Size: 117 B |
Before Width: | Height: | Size: 4.3 KiB After Width: | Height: | Size: 4.3 KiB |
Before Width: | Height: | Size: 4.3 KiB After Width: | Height: | Size: 4.3 KiB |
Before Width: | Height: | Size: 4.3 KiB After Width: | Height: | Size: 4.3 KiB |
Before Width: | Height: | Size: 4.3 KiB After Width: | Height: | Size: 4.3 KiB |
Before Width: | Height: | Size: 4.3 KiB After Width: | Height: | Size: 4.3 KiB |
Before Width: | Height: | Size: 9.3 KiB After Width: | Height: | Size: 9.3 KiB |
Before Width: | Height: | Size: 9.0 KiB After Width: | Height: | Size: 9.0 KiB |
Before Width: | Height: | Size: 8.0 KiB After Width: | Height: | Size: 8.0 KiB |
Before Width: | Height: | Size: 377 B After Width: | Height: | Size: 377 B |
Before Width: | Height: | Size: 5.8 KiB After Width: | Height: | Size: 5.8 KiB |
Before Width: | Height: | Size: 5.8 KiB After Width: | Height: | Size: 5.8 KiB |
Before Width: | Height: | Size: 9.0 KiB After Width: | Height: | Size: 9.0 KiB |
Before Width: | Height: | Size: 320 B After Width: | Height: | Size: 320 B |
Before Width: | Height: | Size: 349 B After Width: | Height: | Size: 349 B |
Before Width: | Height: | Size: 5.0 KiB After Width: | Height: | Size: 5.0 KiB |
Before Width: | Height: | Size: 455 B After Width: | Height: | Size: 455 B |
Before Width: | Height: | Size: 357 B After Width: | Height: | Size: 357 B |
Before Width: | Height: | Size: 444 B After Width: | Height: | Size: 444 B |
Before Width: | Height: | Size: 190 B After Width: | Height: | Size: 190 B |
Before Width: | Height: | Size: 190 B After Width: | Height: | Size: 190 B |
Before Width: | Height: | Size: 167 B After Width: | Height: | Size: 167 B |
Before Width: | Height: | Size: 167 B After Width: | Height: | Size: 167 B |
Before Width: | Height: | Size: 167 B After Width: | Height: | Size: 167 B |
Before Width: | Height: | Size: 167 B After Width: | Height: | Size: 167 B |
Before Width: | Height: | Size: 167 B After Width: | Height: | Size: 167 B |
Before Width: | Height: | Size: 167 B After Width: | Height: | Size: 167 B |
Before Width: | Height: | Size: 167 B After Width: | Height: | Size: 167 B |
Before Width: | Height: | Size: 167 B After Width: | Height: | Size: 167 B |
Before Width: | Height: | Size: 167 B After Width: | Height: | Size: 167 B |
Before Width: | Height: | Size: 167 B After Width: | Height: | Size: 167 B |
Before Width: | Height: | Size: 167 B After Width: | Height: | Size: 167 B |
Before Width: | Height: | Size: 167 B After Width: | Height: | Size: 167 B |
Before Width: | Height: | Size: 167 B After Width: | Height: | Size: 167 B |
Before Width: | Height: | Size: 167 B After Width: | Height: | Size: 167 B |
Before Width: | Height: | Size: 167 B After Width: | Height: | Size: 167 B |
Before Width: | Height: | Size: 167 B After Width: | Height: | Size: 167 B |
Before Width: | Height: | Size: 167 B After Width: | Height: | Size: 167 B |
Before Width: | Height: | Size: 167 B After Width: | Height: | Size: 167 B |
Before Width: | Height: | Size: 167 B After Width: | Height: | Size: 167 B |
Before Width: | Height: | Size: 167 B After Width: | Height: | Size: 167 B |
Before Width: | Height: | Size: 9.3 KiB After Width: | Height: | Size: 9.3 KiB |
Before Width: | Height: | Size: 8.0 KiB After Width: | Height: | Size: 8.0 KiB |
Before Width: | Height: | Size: 8.2 KiB After Width: | Height: | Size: 8.2 KiB |
Before Width: | Height: | Size: 8.2 KiB After Width: | Height: | Size: 8.2 KiB |
Before Width: | Height: | Size: 168 B After Width: | Height: | Size: 168 B |
Before Width: | Height: | Size: 605 B After Width: | Height: | Size: 605 B |
Before Width: | Height: | Size: 568 B After Width: | Height: | Size: 568 B |
Before Width: | Height: | Size: 168 B After Width: | Height: | Size: 168 B |
Before Width: | Height: | Size: 658 B After Width: | Height: | Size: 658 B |
Before Width: | Height: | Size: 684 B After Width: | Height: | Size: 684 B |
Before Width: | Height: | Size: 460 B After Width: | Height: | Size: 460 B |
Before Width: | Height: | Size: 480 B After Width: | Height: | Size: 480 B |
Before Width: | Height: | Size: 543 B After Width: | Height: | Size: 543 B |
Before Width: | Height: | Size: 591 B After Width: | Height: | Size: 591 B |
Before Width: | Height: | Size: 435 B After Width: | Height: | Size: 435 B |