Village management skeleton classes.

This commit is contained in:
Relintai 2021-11-14 11:45:34 +01:00
parent aa2664c200
commit 731f45f63d
7 changed files with 178 additions and 0 deletions

View File

@ -33,6 +33,7 @@ import traceback
folders = [
'app',
'app/village',
]
module_folders = [

9
app/village/village.cpp Normal file
View File

@ -0,0 +1,9 @@
#include "village.h"
Village::Village() :
Resource() {
}
Village::~Village() {
}

16
app/village/village.h Normal file
View File

@ -0,0 +1,16 @@
#ifndef VILLAGE_H
#define VILLAGE_H
#include "core/string.h"
#include "core/resource.h"
class Village : public Resource {
RCPP_OBJECT(Village, Resource);
public:
Village();
~Village();
};
#endif

View File

@ -0,0 +1,34 @@
#include "village_controller.h"
#include "core/html/form_validator.h"
#include "core/html/html_builder.h"
#include "core/http/cookie.h"
#include "core/http/http_session.h"
#include "core/http/request.h"
#include "core/http/session_manager.h"
void VillageController::handle_request_default(Request *request) {
}
VillageController *VillageController::get_singleton() {
return _self;
}
VillageController::VillageController() :
Object() {
if (_self) {
printf("VillageController::VillageController(): Error! self is not null!/n");
}
_self = this;
}
VillageController::~VillageController() {
if (_self == this) {
_self = nullptr;
}
}
VillageController *VillageController::_self = nullptr;

View File

@ -0,0 +1,29 @@
#ifndef VILLAGE_CONTROLLER_H
#define VILLAGE_CONTROLLER_H
#include "core/string.h"
#include "core/containers/vector.h"
#include "core/object.h"
#include "village.h"
class Request;
class FormValidator;
class VillageController : public Object {
RCPP_OBJECT(VillageController, Object);
public:
virtual void handle_request_default(Request *request);
static VillageController *get_singleton();
VillageController();
~VillageController();
protected:
static VillageController *_self;
};
#endif

View File

@ -0,0 +1,63 @@
#include "village_model.h"
#include "core/database/database.h"
#include "core/database/database_manager.h"
#include "core/database/query_builder.h"
#include "core/database/query_result.h"
#include "core/database/table_builder.h"
#include "core/hash/sha256.h"
#define VILLAGE_TABLE_NAME "village"
void VillageModel::create_table() {
Ref<TableBuilder> tb = DatabaseManager::get_singleton()->ddb->get_table_builder();
tb->create_table(VILLAGE_TABLE_NAME);
tb->integer("id")->auto_increment()->next_row();
tb->varchar("username", 60)->not_null()->next_row();
tb->varchar("email", 100)->not_null()->next_row();
tb->integer("rank")->not_null()->next_row();
tb->varchar("pre_salt", 100)->next_row();
tb->varchar("post_salt", 100)->next_row();
tb->varchar("password_hash", 100)->next_row();
tb->integer("banned")->next_row();
tb->varchar("password_reset_token", 100)->next_row();
tb->integer("locked")->next_row();
tb->primary_key("id");
tb->ccreate_table();
tb->run_query();
//tb->print();
}
void VillageModel::drop_table() {
Ref<TableBuilder> tb = DatabaseManager::get_singleton()->ddb->get_table_builder();
tb->drop_table_if_exists(VILLAGE_TABLE_NAME)->run_query();
}
void VillageModel::migrate() {
drop_table();
create_table();
}
VillageModel *VillageModel::get_singleton() {
return _self;
}
VillageModel::VillageModel() :
Object() {
if (_self) {
printf("VillageModel::VillageModel(): Error! self is not null!/n");
}
_self = this;
}
VillageModel::~VillageModel() {
if (_self == this) {
_self = nullptr;
}
}
VillageModel *VillageModel::_self = nullptr;

View File

@ -0,0 +1,26 @@
#ifndef VILLAGE_MODEL_H
#define VILLAGE_MODEL_H
#include "core/string.h"
#include "core/containers/vector.h"
#include "core/object.h"
class VillageModel : public Object {
RCPP_OBJECT(VillageModel, Object);
public:
virtual void create_table();
virtual void drop_table();
virtual void migrate();
static VillageModel *get_singleton();
VillageModel();
~VillageModel();
protected:
static VillageModel *_self;
};
#endif