From 530a9c16a227578c425982e33bc20915263247cc Mon Sep 17 00:00:00 2001 From: Wieczorek Bartosz Date: Fri, 3 Feb 2017 09:39:53 +0100 Subject: [PATCH] add working login widget --- .gitignore | 2 +- CMakeLists.txt | 3 +- CMakeLists.txt.user | 7 +- sql/schema.sql | 9 +- src/app/CMakeLists.txt | 13 +- src/{eedb/db/session.cpp => app/Session.cpp} | 0 src/{eedb/db/session.hpp => app/Session.hpp} | 0 src/app/main.cpp | 110 ++++- src/eedb/CMakeLists.txt | 1 + src/eedb/auth/PgUserAuth.cpp | 405 +++++++++++++++--- src/eedb/auth/PgUserAuth.hpp | 46 +- src/eedb/auth/Services.cpp | 63 +++ src/eedb/auth/Services.hpp | 22 + src/eedb/db/CMakeLists.txt | 9 +- src/eedb/db/connection.cpp | 8 + src/eedb/db/connection.hpp | 26 ++ src/eedb/db/dbo_object.cpp | 4 - src/eedb/db/dbo_object.hpp | 43 -- src/eedb/model/action.h | 60 +++ src/eedb/model/auth_identity.h | 92 ++++ src/eedb/model/auth_info.h | 204 +++++++++ src/eedb/model/auth_token.h | 108 +++++ src/eedb/model/category.h | 204 +++++++++ src/eedb/model/implemented_action.h | 76 ++++ src/eedb/model/inventory.h | 172 ++++++++ src/eedb/model/item.h | 236 ++++++++++ src/eedb/model/privilege.h | 124 ++++++ src/eedb/model/stat.h | 156 +++++++ src/eedb/model/system_info.h | 92 ++++ src/eedb/model/user.h | 220 ++++++++++ src/eedb/model/user_history.h | 92 ++++ src/eedb/model/user_inventory.h | 60 +++ src/eedb/model/users.hpp | 7 - .../users.cpp => widgets/MainWindow.cpp} | 0 src/eedb/widgets/MainWindow.hpp | 0 35 files changed, 2526 insertions(+), 148 deletions(-) rename src/{eedb/db/session.cpp => app/Session.cpp} (100%) rename src/{eedb/db/session.hpp => app/Session.hpp} (100%) create mode 100644 src/eedb/auth/Services.cpp create mode 100644 src/eedb/auth/Services.hpp create mode 100644 src/eedb/db/connection.cpp create mode 100644 src/eedb/db/connection.hpp delete mode 100644 src/eedb/db/dbo_object.cpp delete mode 100644 src/eedb/db/dbo_object.hpp create mode 100644 src/eedb/model/action.h create mode 100644 src/eedb/model/auth_identity.h create mode 100644 src/eedb/model/auth_info.h create mode 100644 src/eedb/model/auth_token.h create mode 100644 src/eedb/model/category.h create mode 100644 src/eedb/model/implemented_action.h create mode 100644 src/eedb/model/inventory.h create mode 100644 src/eedb/model/item.h create mode 100644 src/eedb/model/privilege.h create mode 100644 src/eedb/model/stat.h create mode 100644 src/eedb/model/system_info.h create mode 100644 src/eedb/model/user.h create mode 100644 src/eedb/model/user_history.h create mode 100644 src/eedb/model/user_inventory.h delete mode 100644 src/eedb/model/users.hpp rename src/eedb/{model/users.cpp => widgets/MainWindow.cpp} (100%) create mode 100644 src/eedb/widgets/MainWindow.hpp diff --git a/.gitignore b/.gitignore index fab7372..ebe56af 100644 --- a/.gitignore +++ b/.gitignore @@ -37,7 +37,7 @@ Thumbs.db # qtcreator generated files *.pro.user* - +*.user # xemacs temporary files *.flc diff --git a/CMakeLists.txt b/CMakeLists.txt index e25efb0..5ee8da1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,10 @@ cmake_minimum_required(VERSION 3.2) project(eedb) -add_definitions( -std=c++17 -fconcepts ) +add_definitions( -std=c++17 ) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "/usr/share/cmake/Modules/") - #set(EEDB_WT_INSTALL_PATH /usr/local/wt_gcc6/) find_package(Wt REQUIRED) diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user index 6fd83cd..a446b5e 100644 --- a/CMakeLists.txt.user +++ b/CMakeLists.txt.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -248,7 +248,7 @@ - + all true Make @@ -334,7 +334,8 @@ 14 eedb - + --docroot=/home/bwieczor/src/wt/ --http-port 8080 --http-addr 0.0.0.0 + false /home/bwieczor/src/__BUILDS__/eedb-GCC6-Debug/src/app 2 diff --git a/sql/schema.sql b/sql/schema.sql index c830d2a..20a52ee 100644 --- a/sql/schema.sql +++ b/sql/schema.sql @@ -141,23 +141,23 @@ create table "user" ( "address" text check( length(address) <= 1000 ), "config" json DEFAULT ('{}'), "avatar" text, + "email" varchar(256) not null, + "status" integer not null, constraint "pk_user_uid" primary key ("uid"), - constraint "ux_user_name" unique ("name") + constraint "ux_user_name" unique ("name"), + constraint "ux_user_email" unique ("email") ) INHERITS (stat); create trigger update_user_last_update before update on "user" FOR EACH ROW EXECUTE PROCEDURE last_update_column(); create table "auth_info" ( "id" serial not null, - "version" integer not null, "user_uid" bigint, "password_hash" varchar(100) not null, "password_method" varchar(20) not null, "password_salt" varchar(20) not null, - "status" integer not null, "failed_login_attempts" integer not null, "last_login_attempt" timestamp, - "email" varchar(256) not null, "unverified_email" varchar(256) not null, "email_token" varchar(64) not null, "email_token_expires" timestamp, @@ -168,7 +168,6 @@ create table "auth_info" ( create table "auth_identity" ( "id" serial not null, - "version" integer not null, "auth_info_id" bigint, "provider" varchar(64) not null, "identity" varchar(512) not null, diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index fe5be41..bdcbbb0 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -1,4 +1,15 @@ -set(SOURCES main.cpp) +set(SOURCES + Session.cpp + main.cpp) +find_package( Boost 1.54.0 REQUIRED system ) + +INCLUDE_DIRECTORIES(${PostgreSQL_INCLUDE_DIRS}) add_executable(eedb ${SOURCES} ) +target_link_libraries(eedb + ${Wt_LIBRARY} # or {Wt_DEBUG_LIBRARY} + ${Wt_HTTP_LIBRARY} # or {Wt_HTTP_DEBUG_LIBRARY} + ${Boost_LIBRARIES} + eedb_db auth + ) diff --git a/src/eedb/db/session.cpp b/src/app/Session.cpp similarity index 100% rename from src/eedb/db/session.cpp rename to src/app/Session.cpp diff --git a/src/eedb/db/session.hpp b/src/app/Session.hpp similarity index 100% rename from src/eedb/db/session.hpp rename to src/app/Session.hpp diff --git a/src/app/main.cpp b/src/app/main.cpp index 9c94784..3114707 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -1,9 +1,107 @@ -#include -#include -#include +#include +#include +#include -using namespace std::literals; +#include -int main() -{ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +class AuthApplication : public Wt::WApplication { + public: + Wt::WLineEdit * nameEdit_; + Wt::WText * greeting_; + + AuthApplication(const Wt::WEnvironment & env) : Wt::WApplication(env) { + login_.changed().connect(this, &AuthApplication::authEvent); + + auto config = std::make_shared< sqlpp::postgresql::connection_config >(); + config->host = "10.154.34.245"; + config->port = 5432; + config->user = "postgres"; + config->password = "postgres"; + config->dbname = "eedb"; + config->debug = true; + + conn_ = std::make_unique< eedb::db::PgConnection >(config); + userDatabase_ = std::make_unique< eedb::auth::PgUserAuth >(*conn_); + userDatabase_->setAuthService(eedb::auth::Services::authService()); + + root()->addStyleClass("container"); + setTheme(new Wt::WBootstrapTheme(this)); + + useStyleSheet("css/style.css"); + + Wt::Auth::AuthWidget * authWidget = new Wt::Auth::AuthWidget( + *eedb::auth::Services::authService(), *userDatabase_, login_); + + authWidget->model()->addPasswordAuth(eedb::auth::Services::passwordService()); + authWidget->model()->addOAuth(eedb::auth::Services::oAuthServices()); + authWidget->setRegistrationEnabled(true); + + authWidget->processEnvironment(); + + root()->addWidget(authWidget); + } + + void authEvent() { + if(login_.loggedIn()) { + const Wt::Auth::User & u = login_.user(); + Wt::log("notice") << "User " << u.id() << " (" << u.identity(Wt::Auth::Identity::LoginName) << ")" + << " logged in."; + + root()->addWidget(new Wt::WText("A first widget")); + for(unsigned int i = 0; i < 3; ++i) { + // A widget can be added to a container by passing the container as + // the last constructor argument. + new Wt::WText(Wt::WString::fromUTF8("

Text {1}

").arg(i), root()); + } + + } else + Wt::log("notice") << "User logged out."; + } + + private: + std::unique_ptr< eedb::db::PgConnection > conn_; + std::unique_ptr< eedb::auth::PgUserAuth > userDatabase_; + Wt::Auth::Login login_; +}; + +Wt::WApplication * createApplication(const Wt::WEnvironment & env) { + return new AuthApplication(env); +} + +int main(int argc, char ** argv) { + try { + Wt::WServer server(argc, argv, WTHTTP_CONFIGURATION); + + server.addEntryPoint(Wt::Application, createApplication); + + eedb::auth::Services::configureAuth(); + + server.run(); + } catch(Wt::WServer::Exception & e) { + std::cerr << e.what() << std::endl; + } catch(std::exception & e) { + std::cerr << "exception: " << e.what() << std::endl; + } } diff --git a/src/eedb/CMakeLists.txt b/src/eedb/CMakeLists.txt index bef3276..7ba4b99 100644 --- a/src/eedb/CMakeLists.txt +++ b/src/eedb/CMakeLists.txt @@ -1,5 +1,6 @@ file(GLOB SOURCE auth/PgUserAuth.cpp + auth/Services.cpp model/*) add_subdirectory(db) diff --git a/src/eedb/auth/PgUserAuth.cpp b/src/eedb/auth/PgUserAuth.cpp index e91211e..0c9a3b1 100644 --- a/src/eedb/auth/PgUserAuth.cpp +++ b/src/eedb/auth/PgUserAuth.cpp @@ -1,72 +1,361 @@ #include "PgUserAuth.hpp" +#include + #include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +using namespace sqlpp; +using namespace Wt::Auth; + namespace eedb::auth { -PgUserAuth::PgUserAuth(sqlpp::postgresql::connection & _db): db(_db) -{ +namespace { + SQLPP_ALIAS_PROVIDER(fk_auth_info_id); + SQLPP_ALIAS_PROVIDER(user_status); + + constexpr eedb::user t_user; + constexpr eedb::auth_identity auth_identity; + constexpr eedb::auth_info auth_info; + + auto auth = + t_user.join(auth_info).on(t_user.uid == auth_info.user_uid).join(auth_identity).on(auth_info.id == auth_identity.auth_info_id); + + auto auth_info_identity = auth_info.join(auth_identity).on(auth_info.id == auth_identity.auth_info_id); + auto user_auth_info = t_user.join(auth_info).on(auth_info.user_uid == t_user.uid); } -Wt::Auth::AbstractUserDatabase::Transaction * PgUserAuth::startTransaction() { - return nullptr; +PgUserAuth::PgUserAuth(eedb::db::PgConnection & _db) : db(_db) {} + +User PgUserAuth::findWithId(const std::string & id) const { + const auto uid_eq = t_user.uid == std::atoi(id.c_str()); + + if(db(select(exists(select(t_user.uid) // + .from(t_user) // + .where(uid_eq)))) + .front() + .exists) { + return User(id, *this); + } + return User(); } -Wt::Auth::User PgUserAuth::findWithId( const std::string & id ) const {} +User PgUserAuth::findWithIdentity(const std::string & provider, const Wt::WString & identity) const { +// if(_userProvider != provider || _userIdentity != identity) { + auto _identity = identity.toUTF8(); + if(_authService && _authService->identityPolicy() == EmailAddressIdentity) { + std::transform(_identity.begin(), _identity.end(), _identity.begin(), ::tolower); + } -Wt::Auth::User PgUserAuth::findWithIdentity( const std::string & provider, const Wt::WString & identity ) const {} + auto identity_eq = auth_identity.identity == _identity; + auto provider_eq = auth_identity.provider == provider; -void PgUserAuth::addIdentity( const Wt::Auth::User & user, const std::string & provider, const Wt::WString & id ) {} + auto result = db(select(auth_info.user_uid) // + .from(auth_info_identity) // + .where(provider_eq and identity_eq)); -void PgUserAuth::setIdentity( const Wt::Auth::User & user, const std::string & provider, const Wt::WString & id ) {} - -Wt::WString PgUserAuth::identity( const Wt::Auth::User & user, const std::string & provider ) const {} - -void PgUserAuth::removeIdentity( const Wt::Auth::User & user, const std::string & provider ) {} - -Wt::Auth::User PgUserAuth::registerNew() {} - -void PgUserAuth::deleteUser( const Wt::Auth::User & user ) {} - -Wt::Auth::User::Status PgUserAuth::status( const Wt::Auth::User & user ) const {} - -void PgUserAuth::setStatus( const Wt::Auth::User & user, Wt::Auth::User::Status status ) {} - -void PgUserAuth::setPassword( const Wt::Auth::User & user, const Wt::Auth::PasswordHash & password ) {} - -Wt::Auth::PasswordHash PgUserAuth::password( const Wt::Auth::User & user ) const {} - -bool PgUserAuth::setEmail( const Wt::Auth::User & user, const std::string & address ) {} - -std::string PgUserAuth::email( const Wt::Auth::User & user ) const {} - -void PgUserAuth::setUnverifiedEmail( const Wt::Auth::User & user, const std::string & address ) {} - -std::string PgUserAuth::unverifiedEmail( const Wt::Auth::User & user ) const {} - -Wt::Auth::User PgUserAuth::findWithEmail( const std::string & address ) const {} - -void PgUserAuth::setEmailToken( const Wt::Auth::User & user, const Wt::Auth::Token & token, Wt::Auth::User::EmailTokenRole role ) {} - -Wt::Auth::Token PgUserAuth::emailToken( const Wt::Auth::User & user ) const {} - -Wt::Auth::User::EmailTokenRole PgUserAuth::emailTokenRole( const Wt::Auth::User & user ) const {} - -Wt::Auth::User PgUserAuth::findWithEmailToken( const std::string & hash ) const {} - -void PgUserAuth::addAuthToken( const Wt::Auth::User & user, const Wt::Auth::Token & token ) {} - -void PgUserAuth::removeAuthToken( const Wt::Auth::User & user, const std::string & hash ) {} - -Wt::Auth::User PgUserAuth::findWithAuthToken( const std::string & hash ) const {} - -int PgUserAuth::updateAuthToken( const Wt::Auth::User & user, const std::string & oldhash, const std::string & newhash ) {} - -void PgUserAuth::setFailedLoginAttempts( const Wt::Auth::User & user, int count ) {} - -int PgUserAuth::failedLoginAttempts( const Wt::Auth::User & user ) const {} - -void PgUserAuth::setLastLoginAttempt( const Wt::Auth::User & user, const Wt::WDateTime & t ) {} - -Wt::WDateTime PgUserAuth::lastLoginAttempt( const Wt::Auth::User & user ) const {} + if(!result.empty()) { + _userProvider = provider; + _userIdentity = identity.toUTF8(); + return User(std::to_string(result.front().user_uid), *this); + } +// } + return User(); +} + +void PgUserAuth::addIdentity(const User & user, const std::string & provider, const Wt::WString & identity) { + const auto uid_eq = auth_info.user_uid == std::atoi(user.id().c_str()); + const auto identity_eq = auth_identity.identity == identity.toUTF8(); + const auto provider_eq = auth_identity.provider == provider; + + auto res = db(select(auth_info.user_uid, auth_info.id) // + .from(auth_info_identity) + .where(identity_eq and provider_eq and uid_eq)); + + if(!res.empty()) { + Wt::log("error") << "cannot add identity " << provider << ":'" << identity << "': already exists"; + return; + } + + auto auth_info_id = db(select(auth_info.id) + .from(auth_info) // + .where(uid_eq)); + + if(auth_info_id.empty()) { + throw std::exception(); + } + + db(insert_into(auth_identity) + .set(auth_identity.identity = identity.toUTF8(), // + auth_identity.provider = provider, // + auth_identity.auth_info_id = auth_info_id.front().id)); + + Wt::log("info") << "created new identity for user"; +} + +void PgUserAuth::setIdentity(const User & user, const std::string & provider, const Wt::WString & identity) { + const auto uid = std::atoi(user.id().c_str()); + const auto provider_eq = auth_identity.provider == provider; + + db.native()->start_transaction(); + auto ret = db(select(auth_info.id) // + .from(auth_info) // + .where(auth_info.user_uid == uid)); + + if(ret.empty()) { + throw std::exception(); + } + + auto auth_info_id = ret.front().id; + + db(update(auth_identity) // + .set(auth_identity.identity = identity.toUTF8()) // + .where(auth_identity.auth_info_id == auth_info_id and provider_eq)); + + db.native()->commit_transaction(); +} + +Wt::WString PgUserAuth::identity(const User & user, const std::string & provider) const { + const auto uid = std::atoi(user.id().c_str()); + const auto id_eq = auth_info.user_uid == uid; + const auto provider_eq = auth_identity.provider == provider; + + auto res = db(select(auth_identity.identity) // + .from(auth_info_identity) // + .where(id_eq and provider_eq)); + + if(res.empty()) + return Wt::WString::Empty; + return {res.front().identity}; +} + +void PgUserAuth::removeIdentity(const User & user, const std::string & provider) { + const auto id_eq = auth_identity.id == std::atoi(user.id().c_str()); + const auto provider_eq = auth_identity.provider == provider; + + db(remove_from(auth_identity) // + .where(id_eq and provider_eq)); +} + +User PgUserAuth::registerNew() { + db.native()->start_transaction(); + + auto user_id = db(sqlpp::postgresql::insert_into(t_user) // + .set(t_user.email = "", // + t_user.name = "", // + t_user.status = -1) + .returning(t_user.uid)) + .front() + .uid; + + auto info_id = db(sqlpp::postgresql::insert_into(auth_info) + .set(auth_info.password_hash = "", // + auth_info.password_method = "", // + auth_info.password_salt = "", // + auth_info.failed_login_attempts = 0, // + auth_info.user_uid = user_id, // + auth_info.unverified_email = "", // + auth_info.email_token = "", // + auth_info.email_token_role = 0) // + .returning(auth_info.id)) + .front() + .id; + + db(insert_into(auth_identity) // + .set(auth_identity.identity = "", // + auth_identity.provider = "", // + auth_identity.auth_info_id = info_id)); + + db.native()->commit_transaction(); + return User{std::to_string(user_id), *this}; +} + +void PgUserAuth::deleteUser(const User & user) { + db(remove_from(auth_info) // + .where(auth_info.id == std::atoi(user.id().c_str()))); +} + +// User::Status PgUserAuth::status(const User & user) const { +// const auto id_eq = auth_identity.id == std::atoi(user.id().c_str()); + +// auto status = db(select(auth_info.status.as(user_status)) // +// .from(join) // +// .where(id_eq)) +// .front() +// .user_status; +// return status.value() == User::Status::Normal ? User::Status::Normal : User::Status::Disabled; +//} + +// void PgUserAuth::setStatus(const User & user, User::Status status) { +// db(update(auth_info) // +// .set(auth_info.status = static_cast< int >(status)) // +// .where(auth_info.id == std::atoi(user.id().c_str()))); +//} + +void PgUserAuth::setPassword(const User & user, const PasswordHash & password) { + db(update(auth_info) + .set(auth_info.password_hash = password.value(), // + auth_info.password_method = password.function(), // + auth_info.password_salt = password.salt()) + .where(auth_info.user_uid == std::atoi(user.id().c_str()))); +} + +PasswordHash PgUserAuth::password(const User & user) const { + const auto id_eq = auth_info.user_uid == std::atoi(user.id().c_str()); + + auto row = db(select(auth_info.password_hash, auth_info.password_method, auth_info.password_salt) + .from(auth_info) // + .where(id_eq)); + if(row.empty()) + return PasswordHash(); + auto & front = row.front(); + return {std::move(front.password_method), std::move(front.password_salt), std::move(front.password_hash)}; +} + +bool PgUserAuth::setEmail(const User & user, const std::string & address) { + const auto uid_eq = t_user.uid == std::atoi(user.id().c_str()); + + db(update(t_user) // + .set(t_user.email = address) // + .where(uid_eq)); + return true; +} + +std::string PgUserAuth::email(const User & user) const { + auto ret = db(select(t_user.email) // + .from(t_user) // + .where(t_user.uid == std::atoi(user.id().c_str()))); + if(ret.empty()) + return {}; + return std::move(ret.front().email); +} + +void PgUserAuth::setUnverifiedEmail(const User & user, const std::string & address) { + db(update(auth_info) // + .set(auth_info.unverified_email = address) // + .where(auth_info.user_uid == std::atoi(user.id().c_str()))); +} + +std::string PgUserAuth::unverifiedEmail(const User & user) const { + auto ret = db(select(auth_info.unverified_email) // + .from(auth_info) // + .where(auth_info.user_uid == std::atoi(user.id().c_str()))); + if(ret.empty()) + return {}; + return std::move(ret.front().unverified_email); +} + +User PgUserAuth::findWithEmail(const std::string & address) const { + auto ret = db(select(t_user.uid) // + .from(t_user) // + .where(t_user.email == address)); + + if(ret.empty()) + return {}; + return {std::to_string(ret.front().uid), *this}; +} + +void PgUserAuth::setEmailToken(const User & user, const Token & token, User::EmailTokenRole role) { + auto exp = ::date::floor<::std::chrono::milliseconds >(std::chrono::system_clock::from_time_t(token.expirationTime().toTime_t())); + db(update(auth_info) // + .set(auth_info.email_token = token.hash(), // + auth_info.email_token_expires = exp, + auth_info.email_token_role = static_cast< int >(role)) // + .where(auth_info.user_uid == std::atoi(user.id().c_str()))); +} + +Token PgUserAuth::emailToken(const User & user) const { + auto ret = db(select(auth_info.email_token, auth_info.email_token_expires) // + .from(auth_info) // + .where(auth_info.user_uid == std::atoi(user.id().c_str()))); + if(ret.empty()) + return {}; + auto exp = Wt::WDateTime(); + auto time = ret.front().email_token_expires.value(); + auto systime = std::chrono::system_clock::to_time_t(time); + exp.setTime_t(systime); + return {ret.front().email_token, exp}; +} + +User::EmailTokenRole PgUserAuth::emailTokenRole(const User & user) const { + auto ret = db(select(auth_info.email_token_role) // + .from(auth_info) // + .where(auth_info.user_uid == std::atoi(user.id().c_str()))); + if(ret.empty()) + throw std::exception(); + auto val = ret.front().email_token_role; + return static_cast< User::EmailTokenRole >(val.value()); +} + +User PgUserAuth::findWithEmailToken(const std::string & hash) const { + auto ret = db(select(t_user.uid) // + .from(user_auth_info) // + .where(auth_info.email_token == hash)); + + if(ret.empty()) + return {}; + return {std::to_string(ret.front().uid), *this}; +} + +// void PgUserAuth::addAuthToken(const User & user, const Token & token) {} + +// void PgUserAuth::removeAuthToken(const User & user, const std::string & hash) {} + +// User PgUserAuth::findWithAuthToken(const std::string & hash) const { +// auto ret = db(select(auth_info.id).from(auth_info).where(auth_info == hash)); + +// if(ret.empty()) +// return {}; +// return {std::to_string(ret.front().id), *this}; +//} + +// int PgUserAuth::updateAuthToken(const User & user, const std::string & oldhash, const std::string & newhash) {} + +void PgUserAuth::setFailedLoginAttempts(const User & user, int count) { + db(update(auth_info) // + .set(auth_info.failed_login_attempts = count) // + .where(auth_info.user_uid == std::atoi(user.id().c_str()))); +} + +int PgUserAuth::failedLoginAttempts(const User & user) const { + auto res = db(select(auth_info.failed_login_attempts) // + .from(auth_info) // + .where(auth_info.user_uid == std::atoi(user.id().c_str()))); + if(res.empty()) + return 0; + return static_cast< int >(res.front().failed_login_attempts); +} + +void PgUserAuth::setLastLoginAttempt(const User & user, const Wt::WDateTime & t) { + auto exp = ::date::floor<::std::chrono::milliseconds >(std::chrono::system_clock::from_time_t(t.toTime_t())); + db(update(auth_info) // + .set(auth_info.last_login_attempt = exp) // + .where(auth_info.user_uid == std::atoi(user.id().c_str()))); +} + +Wt::WDateTime PgUserAuth::lastLoginAttempt(const User & user) const { + auto res = db(select(auth_info.last_login_attempt) // + .from(auth_info) // + .where(auth_info.user_uid == std::atoi(user.id().c_str()))); + if(res.empty()) + return {}; + + auto lastLogin = Wt::WDateTime(); + auto time = res.front().last_login_attempt.value(); + auto systime = std::chrono::system_clock::to_time_t(time); + lastLogin.setTime_t(systime); + + return lastLogin; +} } diff --git a/src/eedb/auth/PgUserAuth.hpp b/src/eedb/auth/PgUserAuth.hpp index 19727c5..717cdf4 100644 --- a/src/eedb/auth/PgUserAuth.hpp +++ b/src/eedb/auth/PgUserAuth.hpp @@ -2,30 +2,38 @@ #include -#include +namespace eedb::db { +class PgConnection; +} + +namespace Wt { +class Wt::Auth::AuthService; +} namespace eedb::auth { class PgUserAuth : public Wt::Auth::AbstractUserDatabase { public: - PgUserAuth(sqlpp::postgresql::connection & db); - - Transaction * startTransaction() override; - - Wt::Auth::User registerNew() override; - void deleteUser(const Wt::Auth::User & user) override; + void setAuthService(Wt::Auth::AuthService * s) { + _authService = s; + } + + PgUserAuth(eedb::db::PgConnection & db); Wt::Auth::User findWithId(const std::string & id) const override; Wt::Auth::User findWithIdentity(const std::string & provider, const Wt::WString & identity) const override; - Wt::Auth::User::Status status(const Wt::Auth::User & user) const override; - void setStatus(const Wt::Auth::User & user, Wt::Auth::User::Status status) override; - void addIdentity(const Wt::Auth::User & user, const std::string & provider, const Wt::WString & id) override; void setIdentity(const Wt::Auth::User & user, const std::string & provider, const Wt::WString & id) override; Wt::WString identity(const Wt::Auth::User & user, const std::string & provider) const override; void removeIdentity(const Wt::Auth::User & user, const std::string & provider) override; + Wt::Auth::User registerNew() override; + void deleteUser(const Wt::Auth::User & user) override; + + // Wt::Auth::User::Status status(const Wt::Auth::User & user) const override; + // void setStatus(const Wt::Auth::User & user, Wt::Auth::User::Status status) override; + void setPassword(const Wt::Auth::User & user, const Wt::Auth::PasswordHash & password) override; Wt::Auth::PasswordHash password(const Wt::Auth::User & user) const override; @@ -39,18 +47,24 @@ class PgUserAuth : public Wt::Auth::AbstractUserDatabase { Wt::Auth::User::EmailTokenRole emailTokenRole(const Wt::Auth::User & user) const override; Wt::Auth::User findWithEmailToken(const std::string & hash) const override; - void addAuthToken(const Wt::Auth::User & user, const Wt::Auth::Token & token) override; - void removeAuthToken(const Wt::Auth::User & user, const std::string & hash) override; - Wt::Auth::User findWithAuthToken(const std::string & hash) const override; - int updateAuthToken(const Wt::Auth::User & user, const std::string & oldhash, const std::string & newhash) override; + // void addAuthToken(const Wt::Auth::User & user, const Wt::Auth::Token & token) override; + // void removeAuthToken(const Wt::Auth::User & user, const std::string & hash) override; + // Wt::Auth::User findWithAuthToken(const std::string & hash) const override; + // int updateAuthToken(const Wt::Auth::User & user, const std::string & oldhash, const std::string & newhash) override; void setFailedLoginAttempts(const Wt::Auth::User & user, int count) override; int failedLoginAttempts(const Wt::Auth::User & user) const override; - void setLastLoginAttempt(const Wt::Auth::User & user, const Wt::WDateTime & t) override; Wt::WDateTime lastLoginAttempt(const Wt::Auth::User & user) const override; private: - sqlpp::postgresql::connection & db; + eedb::db::PgConnection & db; + const Wt::Auth::AuthService * _authService; + + mutable std::string _userProvider; + mutable std::string _userIdentity; + + // AbstractUserDatabase interface + public: }; } diff --git a/src/eedb/auth/Services.cpp b/src/eedb/auth/Services.cpp new file mode 100644 index 0000000..dfdc3cc --- /dev/null +++ b/src/eedb/auth/Services.cpp @@ -0,0 +1,63 @@ +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace { + +class MyOAuth : public std::vector< const Wt::Auth::OAuthService * > { + public: + ~MyOAuth() { + for(unsigned i = 0; i < size(); ++i) + delete(*this)[i]; + } +}; + +Wt::Auth::AuthService myAuthService; +Wt::Auth::PasswordService myPasswordService(myAuthService); +MyOAuth myOAuthServices; +} +namespace eedb::auth { +Wt::Auth::AuthService * Services::authService() { + return &myAuthService; +} + +Wt::Auth::AbstractPasswordService * Services::passwordService() { + return &myPasswordService; +} + +std::vector< const Wt::Auth::OAuthService * > Services::oAuthServices() { + return myOAuthServices; +} + +void Services::configureAuth() { + myAuthService.setAuthTokensEnabled(true, "logincookie"); + myAuthService.setEmailVerificationEnabled(true); + myAuthService.setEmailVerificationRequired(true); + + Wt::Auth::PasswordVerifier * verifier = new Wt::Auth::PasswordVerifier(); + verifier->addHashFunction(new Wt::Auth::BCryptHashFunction(7)); + myPasswordService.setVerifier(verifier); + myPasswordService.setAttemptThrottlingEnabled(true); + myPasswordService.setStrengthValidator(new Wt::Auth::PasswordStrengthValidator()); + + if(Wt::Auth::GoogleService::configured()) + myOAuthServices.push_back(new Wt::Auth::GoogleService(myAuthService)); + + if(Wt::Auth::FacebookService::configured()) + myOAuthServices.push_back(new Wt::Auth::FacebookService(myAuthService)); + + for(unsigned i = 0; i < myOAuthServices.size(); ++i) + myOAuthServices[i]->generateRedirectEndpoint(); +} +}; diff --git a/src/eedb/auth/Services.hpp b/src/eedb/auth/Services.hpp new file mode 100644 index 0000000..6efd62f --- /dev/null +++ b/src/eedb/auth/Services.hpp @@ -0,0 +1,22 @@ +#pragma once +#include + +namespace Wt::Auth { +class AuthService; +class AbstractPasswordService; +class OAuthService; +} + +namespace eedb::auth { + +class Services { + public: + static void configureAuth(); + + static Wt::Auth::AuthService * authService(); + + static Wt::Auth::AbstractPasswordService * passwordService(); + + static std::vector< const Wt::Auth::OAuthService * > oAuthServices(); +}; +} diff --git a/src/eedb/db/CMakeLists.txt b/src/eedb/db/CMakeLists.txt index de22d67..e7f865f 100644 --- a/src/eedb/db/CMakeLists.txt +++ b/src/eedb/db/CMakeLists.txt @@ -1,6 +1,11 @@ set(SOURCE - session.cpp - dbo_object.cpp ) + connection.cpp + ) + +find_package(Sqlpp11 REQUIRED) +find_package(PostgreSQL REQUIRED) + +INCLUDE_DIRECTORIES( ${PostgreSQL_INCLUDE_DIRS} ) add_library(eedb_db ${SOURCE}) target_link_libraries( eedb_db sqlpp-postgresql ) diff --git a/src/eedb/db/connection.cpp b/src/eedb/db/connection.cpp new file mode 100644 index 0000000..8282b23 --- /dev/null +++ b/src/eedb/db/connection.cpp @@ -0,0 +1,8 @@ +#include + + +namespace eedb::db { + + + +} diff --git a/src/eedb/db/connection.hpp b/src/eedb/db/connection.hpp new file mode 100644 index 0000000..1ec9a02 --- /dev/null +++ b/src/eedb/db/connection.hpp @@ -0,0 +1,26 @@ +#pragma once + +#include + +#include + +namespace eedb::db { + +class PgConnection { + public: + PgConnection(std::shared_ptr< sqlpp::postgresql::connection_config > config) + : _conn(std::make_unique< sqlpp::postgresql::connection >(config)) {} + + sqlpp::postgresql::connection * native() { + return _conn.get(); + } + + template < typename T > + auto operator()(T && t) { + return _conn->operator()(std::forward< T >(t)); + } + + private: + std::unique_ptr< sqlpp::postgresql::connection > _conn; +}; +} diff --git a/src/eedb/db/dbo_object.cpp b/src/eedb/db/dbo_object.cpp deleted file mode 100644 index ea79f5c..0000000 --- a/src/eedb/db/dbo_object.cpp +++ /dev/null @@ -1,4 +0,0 @@ -#include "dbo_object.hpp" -namespace eedb::db -{ -} diff --git a/src/eedb/db/dbo_object.hpp b/src/eedb/db/dbo_object.hpp deleted file mode 100644 index b97abb5..0000000 --- a/src/eedb/db/dbo_object.hpp +++ /dev/null @@ -1,43 +0,0 @@ -#pragma once - -#include - -namespace eedb::db -{ - template < typename T > - class DatabaseObject - { - }; - - template < typename T > - class DatabaseCacheObject - { - public: - DatabaseObject< T > & operator->() - { - if( isDirty() ) - reload(); - } - - virtual bool isDirty() - { - return true; - } - - virtual void reload() = 0; - - protected: - void markDirty() - { - is_dirty = true; - } - - private: - bool is_dirty; - }; - - template < typename T > - class DatabaseCacheContainer - { - }; -} diff --git a/src/eedb/model/action.h b/src/eedb/model/action.h new file mode 100644 index 0000000..8ae27d0 --- /dev/null +++ b/src/eedb/model/action.h @@ -0,0 +1,60 @@ +#ifndef EEDB_ACTION_H +#define EEDB_ACTION_H + +#include +#include +#include + +namespace eedb { + + namespace action_ { + + struct Title { + struct _alias_t { + static constexpr const char _literal[] ="title"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T title; + T &operator()() { return title; } + const T &operator()() const { return title; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::text, sqlpp::tag::require_insert>; + }; + + struct Apply_object { + struct _alias_t { + static constexpr const char _literal[] ="apply_object"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T apply_object; + T &operator()() { return apply_object; } + const T &operator()() const { return apply_object; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::boolean, sqlpp::tag::require_insert>; + }; + } + + struct action : sqlpp::table_t { + using _value_type = sqlpp::no_value_t; + struct _alias_t { + static constexpr const char _literal[] = "action"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T action; + T &operator()() { return action; } + const T &operator()() const { return action; } + }; + }; + }; +} + +#endif diff --git a/src/eedb/model/auth_identity.h b/src/eedb/model/auth_identity.h new file mode 100644 index 0000000..12d57d8 --- /dev/null +++ b/src/eedb/model/auth_identity.h @@ -0,0 +1,92 @@ +#ifndef EEDB_AUTH_IDENTITY_H +#define EEDB_AUTH_IDENTITY_H + +#include +#include +#include + +namespace eedb { + + namespace auth_identity_ { + + struct Id { + struct _alias_t { + static constexpr const char _literal[] ="id"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T id; + T &operator()() { return id; } + const T &operator()() const { return id; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::integer, sqlpp::tag::must_not_insert, sqlpp::tag::must_not_update>; + }; + + struct Auth_info_id { + struct _alias_t { + static constexpr const char _literal[] ="auth_info_id"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T auth_info_id; + T &operator()() { return auth_info_id; } + const T &operator()() const { return auth_info_id; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::bigint, sqlpp::tag::can_be_null>; + }; + + struct Provider { + struct _alias_t { + static constexpr const char _literal[] ="provider"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T provider; + T &operator()() { return provider; } + const T &operator()() const { return provider; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::varchar, sqlpp::tag::require_insert>; + }; + + struct Identity { + struct _alias_t { + static constexpr const char _literal[] ="identity"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T identity; + T &operator()() { return identity; } + const T &operator()() const { return identity; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::varchar, sqlpp::tag::require_insert>; + }; + } + + struct auth_identity : sqlpp::table_t { + using _value_type = sqlpp::no_value_t; + struct _alias_t { + static constexpr const char _literal[] = "auth_identity"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T auth_identity; + T &operator()() { return auth_identity; } + const T &operator()() const { return auth_identity; } + }; + }; + }; +} + +#endif diff --git a/src/eedb/model/auth_info.h b/src/eedb/model/auth_info.h new file mode 100644 index 0000000..df11a22 --- /dev/null +++ b/src/eedb/model/auth_info.h @@ -0,0 +1,204 @@ +#ifndef EEDB_AUTH_INFO_H +#define EEDB_AUTH_INFO_H + +#include +#include +#include + +namespace eedb { + + namespace auth_info_ { + + struct Id { + struct _alias_t { + static constexpr const char _literal[] ="id"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T id; + T &operator()() { return id; } + const T &operator()() const { return id; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::integer, sqlpp::tag::must_not_insert, sqlpp::tag::must_not_update>; + }; + + struct User_uid { + struct _alias_t { + static constexpr const char _literal[] ="user_uid"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T user_uid; + T &operator()() { return user_uid; } + const T &operator()() const { return user_uid; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::bigint, sqlpp::tag::can_be_null>; + }; + + struct Password_hash { + struct _alias_t { + static constexpr const char _literal[] ="password_hash"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T password_hash; + T &operator()() { return password_hash; } + const T &operator()() const { return password_hash; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::varchar, sqlpp::tag::require_insert>; + }; + + struct Password_method { + struct _alias_t { + static constexpr const char _literal[] ="password_method"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T password_method; + T &operator()() { return password_method; } + const T &operator()() const { return password_method; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::varchar, sqlpp::tag::require_insert>; + }; + + struct Password_salt { + struct _alias_t { + static constexpr const char _literal[] ="password_salt"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T password_salt; + T &operator()() { return password_salt; } + const T &operator()() const { return password_salt; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::varchar, sqlpp::tag::require_insert>; + }; + + struct Failed_login_attempts { + struct _alias_t { + static constexpr const char _literal[] ="failed_login_attempts"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T failed_login_attempts; + T &operator()() { return failed_login_attempts; } + const T &operator()() const { return failed_login_attempts; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::integer, sqlpp::tag::require_insert>; + }; + + struct Last_login_attempt { + struct _alias_t { + static constexpr const char _literal[] ="last_login_attempt"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T last_login_attempt; + T &operator()() { return last_login_attempt; } + const T &operator()() const { return last_login_attempt; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::time_point, sqlpp::tag::can_be_null>; + }; + + struct Unverified_email { + struct _alias_t { + static constexpr const char _literal[] ="unverified_email"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T unverified_email; + T &operator()() { return unverified_email; } + const T &operator()() const { return unverified_email; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::varchar, sqlpp::tag::require_insert>; + }; + + struct Email_token { + struct _alias_t { + static constexpr const char _literal[] ="email_token"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T email_token; + T &operator()() { return email_token; } + const T &operator()() const { return email_token; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::varchar, sqlpp::tag::require_insert>; + }; + + struct Email_token_expires { + struct _alias_t { + static constexpr const char _literal[] ="email_token_expires"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T email_token_expires; + T &operator()() { return email_token_expires; } + const T &operator()() const { return email_token_expires; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::time_point, sqlpp::tag::can_be_null>; + }; + + struct Email_token_role { + struct _alias_t { + static constexpr const char _literal[] ="email_token_role"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T email_token_role; + T &operator()() { return email_token_role; } + const T &operator()() const { return email_token_role; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::integer, sqlpp::tag::require_insert>; + }; + } + + struct auth_info : sqlpp::table_t { + using _value_type = sqlpp::no_value_t; + struct _alias_t { + static constexpr const char _literal[] = "auth_info"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T auth_info; + T &operator()() { return auth_info; } + const T &operator()() const { return auth_info; } + }; + }; + }; +} + +#endif diff --git a/src/eedb/model/auth_token.h b/src/eedb/model/auth_token.h new file mode 100644 index 0000000..a85a1ce --- /dev/null +++ b/src/eedb/model/auth_token.h @@ -0,0 +1,108 @@ +#ifndef EEDB_AUTH_TOKEN_H +#define EEDB_AUTH_TOKEN_H + +#include +#include +#include + +namespace eedb { + + namespace auth_token_ { + + struct Id { + struct _alias_t { + static constexpr const char _literal[] ="id"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T id; + T &operator()() { return id; } + const T &operator()() const { return id; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::integer, sqlpp::tag::must_not_insert, sqlpp::tag::must_not_update>; + }; + + struct Version { + struct _alias_t { + static constexpr const char _literal[] ="version"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T version; + T &operator()() { return version; } + const T &operator()() const { return version; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::integer, sqlpp::tag::require_insert>; + }; + + struct Auth_info_id { + struct _alias_t { + static constexpr const char _literal[] ="auth_info_id"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T auth_info_id; + T &operator()() { return auth_info_id; } + const T &operator()() const { return auth_info_id; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::bigint, sqlpp::tag::can_be_null>; + }; + + struct Value { + struct _alias_t { + static constexpr const char _literal[] ="value"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T value; + T &operator()() { return value; } + const T &operator()() const { return value; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::varchar, sqlpp::tag::require_insert>; + }; + + struct Expires { + struct _alias_t { + static constexpr const char _literal[] ="expires"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T expires; + T &operator()() { return expires; } + const T &operator()() const { return expires; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::time_point, sqlpp::tag::can_be_null>; + }; + } + + struct auth_token : sqlpp::table_t { + using _value_type = sqlpp::no_value_t; + struct _alias_t { + static constexpr const char _literal[] = "auth_token"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T auth_token; + T &operator()() { return auth_token; } + const T &operator()() const { return auth_token; } + }; + }; + }; +} + +#endif diff --git a/src/eedb/model/category.h b/src/eedb/model/category.h new file mode 100644 index 0000000..93c85b9 --- /dev/null +++ b/src/eedb/model/category.h @@ -0,0 +1,204 @@ +#ifndef EEDB_CATEGORY_H +#define EEDB_CATEGORY_H + +#include +#include +#include + +namespace eedb { + + namespace category_ { + + struct Uid { + struct _alias_t { + static constexpr const char _literal[] ="uid"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T uid; + T &operator()() { return uid; } + const T &operator()() const { return uid; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::integer>; + }; + + struct Owner { + struct _alias_t { + static constexpr const char _literal[] ="owner"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T owner; + T &operator()() { return owner; } + const T &operator()() const { return owner; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::integer>; + }; + + struct Stat_group { + struct _alias_t { + static constexpr const char _literal[] ="stat_group"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T stat_group; + T &operator()() { return stat_group; } + const T &operator()() const { return stat_group; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::integer>; + }; + + struct Unixperms { + struct _alias_t { + static constexpr const char _literal[] ="unixperms"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T unixperms; + T &operator()() { return unixperms; } + const T &operator()() const { return unixperms; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::integer>; + }; + + struct Status { + struct _alias_t { + static constexpr const char _literal[] ="status"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T status; + T &operator()() { return status; } + const T &operator()() const { return status; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::integer>; + }; + + struct Name { + struct _alias_t { + static constexpr const char _literal[] ="name"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T name; + T &operator()() { return name; } + const T &operator()() const { return name; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::text, sqlpp::tag::require_insert>; + }; + + struct Creation_date { + struct _alias_t { + static constexpr const char _literal[] ="creation_date"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T creation_date; + T &operator()() { return creation_date; } + const T &operator()() const { return creation_date; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::time_point>; + }; + + struct Last_update { + struct _alias_t { + static constexpr const char _literal[] ="last_update"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T last_update; + T &operator()() { return last_update; } + const T &operator()() const { return last_update; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::time_point, sqlpp::tag::can_be_null>; + }; + + struct Parent_id { + struct _alias_t { + static constexpr const char _literal[] ="parent_id"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T parent_id; + T &operator()() { return parent_id; } + const T &operator()() const { return parent_id; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::integer, sqlpp::tag::can_be_null>; + }; + + struct Description { + struct _alias_t { + static constexpr const char _literal[] ="description"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T description; + T &operator()() { return description; } + const T &operator()() const { return description; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::text, sqlpp::tag::can_be_null>; + }; + + struct Parent_path { + struct _alias_t { + static constexpr const char _literal[] ="parent_path"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T parent_path; + T &operator()() { return parent_path; } + const T &operator()() const { return parent_path; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::varchar, sqlpp::tag::can_be_null>; + }; + } + + struct category : sqlpp::table_t { + using _value_type = sqlpp::no_value_t; + struct _alias_t { + static constexpr const char _literal[] = "category"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T category; + T &operator()() { return category; } + const T &operator()() const { return category; } + }; + }; + }; +} + +#endif diff --git a/src/eedb/model/implemented_action.h b/src/eedb/model/implemented_action.h new file mode 100644 index 0000000..507b89f --- /dev/null +++ b/src/eedb/model/implemented_action.h @@ -0,0 +1,76 @@ +#ifndef EEDB_IMPLEMENTED_ACTION_H +#define EEDB_IMPLEMENTED_ACTION_H + +#include +#include +#include + +namespace eedb { + + namespace implemented_action_ { + + struct Table_name { + struct _alias_t { + static constexpr const char _literal[] ="table_name"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T table_name; + T &operator()() { return table_name; } + const T &operator()() const { return table_name; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::text, sqlpp::tag::require_insert>; + }; + + struct Action { + struct _alias_t { + static constexpr const char _literal[] ="action"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T action; + T &operator()() { return action; } + const T &operator()() const { return action; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::text, sqlpp::tag::require_insert>; + }; + + struct Status { + struct _alias_t { + static constexpr const char _literal[] ="status"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T status; + T &operator()() { return status; } + const T &operator()() const { return status; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::integer, sqlpp::tag::require_insert>; + }; + } + + struct implemented_action : sqlpp::table_t { + using _value_type = sqlpp::no_value_t; + struct _alias_t { + static constexpr const char _literal[] = "implemented_action"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T implemented_action; + T &operator()() { return implemented_action; } + const T &operator()() const { return implemented_action; } + }; + }; + }; +} + +#endif diff --git a/src/eedb/model/inventory.h b/src/eedb/model/inventory.h new file mode 100644 index 0000000..eef49df --- /dev/null +++ b/src/eedb/model/inventory.h @@ -0,0 +1,172 @@ +#ifndef EEDB_INVENTORY_H +#define EEDB_INVENTORY_H + +#include +#include +#include + +namespace eedb { + + namespace inventory_ { + + struct Uid { + struct _alias_t { + static constexpr const char _literal[] ="uid"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T uid; + T &operator()() { return uid; } + const T &operator()() const { return uid; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::integer>; + }; + + struct Owner { + struct _alias_t { + static constexpr const char _literal[] ="owner"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T owner; + T &operator()() { return owner; } + const T &operator()() const { return owner; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::integer>; + }; + + struct Stat_group { + struct _alias_t { + static constexpr const char _literal[] ="stat_group"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T stat_group; + T &operator()() { return stat_group; } + const T &operator()() const { return stat_group; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::integer>; + }; + + struct Unixperms { + struct _alias_t { + static constexpr const char _literal[] ="unixperms"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T unixperms; + T &operator()() { return unixperms; } + const T &operator()() const { return unixperms; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::integer>; + }; + + struct Status { + struct _alias_t { + static constexpr const char _literal[] ="status"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T status; + T &operator()() { return status; } + const T &operator()() const { return status; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::integer>; + }; + + struct Name { + struct _alias_t { + static constexpr const char _literal[] ="name"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T name; + T &operator()() { return name; } + const T &operator()() const { return name; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::text, sqlpp::tag::require_insert>; + }; + + struct Creation_date { + struct _alias_t { + static constexpr const char _literal[] ="creation_date"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T creation_date; + T &operator()() { return creation_date; } + const T &operator()() const { return creation_date; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::time_point>; + }; + + struct Last_update { + struct _alias_t { + static constexpr const char _literal[] ="last_update"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T last_update; + T &operator()() { return last_update; } + const T &operator()() const { return last_update; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::time_point, sqlpp::tag::can_be_null>; + }; + + struct Description { + struct _alias_t { + static constexpr const char _literal[] ="description"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T description; + T &operator()() { return description; } + const T &operator()() const { return description; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::text, sqlpp::tag::can_be_null>; + }; + } + + struct inventory : sqlpp::table_t { + using _value_type = sqlpp::no_value_t; + struct _alias_t { + static constexpr const char _literal[] = "inventory"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T inventory; + T &operator()() { return inventory; } + const T &operator()() const { return inventory; } + }; + }; + }; +} + +#endif diff --git a/src/eedb/model/item.h b/src/eedb/model/item.h new file mode 100644 index 0000000..984ee5a --- /dev/null +++ b/src/eedb/model/item.h @@ -0,0 +1,236 @@ +#ifndef EEDB_ITEM_H +#define EEDB_ITEM_H + +#include +#include +#include + +namespace eedb { + + namespace item_ { + + struct Uid { + struct _alias_t { + static constexpr const char _literal[] ="uid"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T uid; + T &operator()() { return uid; } + const T &operator()() const { return uid; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::integer>; + }; + + struct Owner { + struct _alias_t { + static constexpr const char _literal[] ="owner"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T owner; + T &operator()() { return owner; } + const T &operator()() const { return owner; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::integer>; + }; + + struct Stat_group { + struct _alias_t { + static constexpr const char _literal[] ="stat_group"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T stat_group; + T &operator()() { return stat_group; } + const T &operator()() const { return stat_group; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::integer>; + }; + + struct Unixperms { + struct _alias_t { + static constexpr const char _literal[] ="unixperms"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T unixperms; + T &operator()() { return unixperms; } + const T &operator()() const { return unixperms; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::integer>; + }; + + struct Status { + struct _alias_t { + static constexpr const char _literal[] ="status"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T status; + T &operator()() { return status; } + const T &operator()() const { return status; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::integer>; + }; + + struct Name { + struct _alias_t { + static constexpr const char _literal[] ="name"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T name; + T &operator()() { return name; } + const T &operator()() const { return name; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::text, sqlpp::tag::require_insert>; + }; + + struct Creation_date { + struct _alias_t { + static constexpr const char _literal[] ="creation_date"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T creation_date; + T &operator()() { return creation_date; } + const T &operator()() const { return creation_date; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::time_point>; + }; + + struct Last_update { + struct _alias_t { + static constexpr const char _literal[] ="last_update"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T last_update; + T &operator()() { return last_update; } + const T &operator()() const { return last_update; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::time_point, sqlpp::tag::can_be_null>; + }; + + struct Category_id { + struct _alias_t { + static constexpr const char _literal[] ="category_id"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T category_id; + T &operator()() { return category_id; } + const T &operator()() const { return category_id; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::integer, sqlpp::tag::require_insert>; + }; + + struct Symbol { + struct _alias_t { + static constexpr const char _literal[] ="symbol"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T symbol; + T &operator()() { return symbol; } + const T &operator()() const { return symbol; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::text, sqlpp::tag::require_insert>; + }; + + struct Producer { + struct _alias_t { + static constexpr const char _literal[] ="producer"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T producer; + T &operator()() { return producer; } + const T &operator()() const { return producer; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::text, sqlpp::tag::can_be_null>; + }; + + struct Attributes { + struct _alias_t { + static constexpr const char _literal[] ="attributes"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T attributes; + T &operator()() { return attributes; } + const T &operator()() const { return attributes; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::text>; + }; + + struct Description { + struct _alias_t { + static constexpr const char _literal[] ="description"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T description; + T &operator()() { return description; } + const T &operator()() const { return description; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::text, sqlpp::tag::can_be_null>; + }; + } + + struct item : sqlpp::table_t { + using _value_type = sqlpp::no_value_t; + struct _alias_t { + static constexpr const char _literal[] = "item"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T item; + T &operator()() { return item; } + const T &operator()() const { return item; } + }; + }; + }; +} + +#endif diff --git a/src/eedb/model/privilege.h b/src/eedb/model/privilege.h new file mode 100644 index 0000000..01174a7 --- /dev/null +++ b/src/eedb/model/privilege.h @@ -0,0 +1,124 @@ +#ifndef EEDB_PRIVILEGE_H +#define EEDB_PRIVILEGE_H + +#include +#include +#include + +namespace eedb { + + namespace privilege_ { + + struct Role { + struct _alias_t { + static constexpr const char _literal[] ="role"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T role; + T &operator()() { return role; } + const T &operator()() const { return role; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::varchar, sqlpp::tag::require_insert>; + }; + + struct Who { + struct _alias_t { + static constexpr const char _literal[] ="who"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T who; + T &operator()() { return who; } + const T &operator()() const { return who; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::integer>; + }; + + struct Action { + struct _alias_t { + static constexpr const char _literal[] ="action"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T action; + T &operator()() { return action; } + const T &operator()() const { return action; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::text, sqlpp::tag::require_insert>; + }; + + struct Type { + struct _alias_t { + static constexpr const char _literal[] ="type"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T type; + T &operator()() { return type; } + const T &operator()() const { return type; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::varchar, sqlpp::tag::require_insert>; + }; + + struct Related_table_name { + struct _alias_t { + static constexpr const char _literal[] ="related_table_name"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T related_table_name; + T &operator()() { return related_table_name; } + const T &operator()() const { return related_table_name; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::varchar, sqlpp::tag::require_insert>; + }; + + struct Related_object_uid { + struct _alias_t { + static constexpr const char _literal[] ="related_object_uid"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T related_object_uid; + T &operator()() { return related_object_uid; } + const T &operator()() const { return related_object_uid; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::integer>; + }; + } + + struct privilege : sqlpp::table_t { + using _value_type = sqlpp::no_value_t; + struct _alias_t { + static constexpr const char _literal[] = "privilege"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T privilege; + T &operator()() { return privilege; } + const T &operator()() const { return privilege; } + }; + }; + }; +} + +#endif diff --git a/src/eedb/model/stat.h b/src/eedb/model/stat.h new file mode 100644 index 0000000..6edd05c --- /dev/null +++ b/src/eedb/model/stat.h @@ -0,0 +1,156 @@ +#ifndef EEDB_STAT_H +#define EEDB_STAT_H + +#include +#include +#include + +namespace eedb { + + namespace stat_ { + + struct Uid { + struct _alias_t { + static constexpr const char _literal[] ="uid"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T uid; + T &operator()() { return uid; } + const T &operator()() const { return uid; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::integer, sqlpp::tag::must_not_insert, sqlpp::tag::must_not_update>; + }; + + struct Owner { + struct _alias_t { + static constexpr const char _literal[] ="owner"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T owner; + T &operator()() { return owner; } + const T &operator()() const { return owner; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::integer>; + }; + + struct Stat_group { + struct _alias_t { + static constexpr const char _literal[] ="stat_group"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T stat_group; + T &operator()() { return stat_group; } + const T &operator()() const { return stat_group; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::integer>; + }; + + struct Unixperms { + struct _alias_t { + static constexpr const char _literal[] ="unixperms"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T unixperms; + T &operator()() { return unixperms; } + const T &operator()() const { return unixperms; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::integer>; + }; + + struct Status { + struct _alias_t { + static constexpr const char _literal[] ="status"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T status; + T &operator()() { return status; } + const T &operator()() const { return status; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::integer>; + }; + + struct Name { + struct _alias_t { + static constexpr const char _literal[] ="name"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T name; + T &operator()() { return name; } + const T &operator()() const { return name; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::text, sqlpp::tag::require_insert>; + }; + + struct Creation_date { + struct _alias_t { + static constexpr const char _literal[] ="creation_date"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T creation_date; + T &operator()() { return creation_date; } + const T &operator()() const { return creation_date; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::time_point>; + }; + + struct Last_update { + struct _alias_t { + static constexpr const char _literal[] ="last_update"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T last_update; + T &operator()() { return last_update; } + const T &operator()() const { return last_update; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::time_point, sqlpp::tag::can_be_null>; + }; + } + + struct stat : sqlpp::table_t { + using _value_type = sqlpp::no_value_t; + struct _alias_t { + static constexpr const char _literal[] = "stat"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T stat; + T &operator()() { return stat; } + const T &operator()() const { return stat; } + }; + }; + }; +} + +#endif diff --git a/src/eedb/model/system_info.h b/src/eedb/model/system_info.h new file mode 100644 index 0000000..8429e29 --- /dev/null +++ b/src/eedb/model/system_info.h @@ -0,0 +1,92 @@ +#ifndef EEDB_SYSTEM_INFO_H +#define EEDB_SYSTEM_INFO_H + +#include +#include +#include + +namespace eedb { + + namespace system_info_ { + + struct Id { + struct _alias_t { + static constexpr const char _literal[] ="id"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T id; + T &operator()() { return id; } + const T &operator()() const { return id; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::integer, sqlpp::tag::must_not_insert, sqlpp::tag::must_not_update>; + }; + + struct Name { + struct _alias_t { + static constexpr const char _literal[] ="name"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T name; + T &operator()() { return name; } + const T &operator()() const { return name; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::text, sqlpp::tag::can_be_null>; + }; + + struct Value { + struct _alias_t { + static constexpr const char _literal[] ="value"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T value; + T &operator()() { return value; } + const T &operator()() const { return value; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::text, sqlpp::tag::can_be_null>; + }; + + struct Creation_time { + struct _alias_t { + static constexpr const char _literal[] ="creation_time"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T creation_time; + T &operator()() { return creation_time; } + const T &operator()() const { return creation_time; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::time_point, sqlpp::tag::can_be_null>; + }; + } + + struct system_info : sqlpp::table_t { + using _value_type = sqlpp::no_value_t; + struct _alias_t { + static constexpr const char _literal[] = "system_info"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T system_info; + T &operator()() { return system_info; } + const T &operator()() const { return system_info; } + }; + }; + }; +} + +#endif diff --git a/src/eedb/model/user.h b/src/eedb/model/user.h new file mode 100644 index 0000000..1a2031b --- /dev/null +++ b/src/eedb/model/user.h @@ -0,0 +1,220 @@ +#ifndef EEDB_USER_H +#define EEDB_USER_H + +#include +#include +#include + +namespace eedb { + + namespace user_ { + + struct Uid { + struct _alias_t { + static constexpr const char _literal[] ="uid"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T uid; + T &operator()() { return uid; } + const T &operator()() const { return uid; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::integer>; + }; + + struct Owner { + struct _alias_t { + static constexpr const char _literal[] ="owner"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T owner; + T &operator()() { return owner; } + const T &operator()() const { return owner; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::integer>; + }; + + struct Stat_group { + struct _alias_t { + static constexpr const char _literal[] ="stat_group"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T stat_group; + T &operator()() { return stat_group; } + const T &operator()() const { return stat_group; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::integer>; + }; + + struct Unixperms { + struct _alias_t { + static constexpr const char _literal[] ="unixperms"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T unixperms; + T &operator()() { return unixperms; } + const T &operator()() const { return unixperms; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::integer>; + }; + + struct Status { + struct _alias_t { + static constexpr const char _literal[] ="status"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T status; + T &operator()() { return status; } + const T &operator()() const { return status; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::integer>; + }; + + struct Name { + struct _alias_t { + static constexpr const char _literal[] ="name"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T name; + T &operator()() { return name; } + const T &operator()() const { return name; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::text, sqlpp::tag::require_insert>; + }; + + struct Creation_date { + struct _alias_t { + static constexpr const char _literal[] ="creation_date"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T creation_date; + T &operator()() { return creation_date; } + const T &operator()() const { return creation_date; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::time_point>; + }; + + struct Last_update { + struct _alias_t { + static constexpr const char _literal[] ="last_update"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T last_update; + T &operator()() { return last_update; } + const T &operator()() const { return last_update; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::time_point, sqlpp::tag::can_be_null>; + }; + + struct Address { + struct _alias_t { + static constexpr const char _literal[] ="address"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T address; + T &operator()() { return address; } + const T &operator()() const { return address; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::text, sqlpp::tag::can_be_null>; + }; + + struct Config { + struct _alias_t { + static constexpr const char _literal[] ="config"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T config; + T &operator()() { return config; } + const T &operator()() const { return config; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::text, sqlpp::tag::can_be_null>; + }; + + struct Avatar { + struct _alias_t { + static constexpr const char _literal[] ="avatar"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T avatar; + T &operator()() { return avatar; } + const T &operator()() const { return avatar; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::text, sqlpp::tag::can_be_null>; + }; + + struct Email { + struct _alias_t { + static constexpr const char _literal[] ="email"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T email; + T &operator()() { return email; } + const T &operator()() const { return email; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::varchar, sqlpp::tag::require_insert>; + }; + } + + struct user : sqlpp::table_t { + using _value_type = sqlpp::no_value_t; + struct _alias_t { + static constexpr const char _literal[] = "\"user\""; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T user; + T &operator()() { return user; } + const T &operator()() const { return user; } + }; + }; + }; +} + +#endif diff --git a/src/eedb/model/user_history.h b/src/eedb/model/user_history.h new file mode 100644 index 0000000..1925595 --- /dev/null +++ b/src/eedb/model/user_history.h @@ -0,0 +1,92 @@ +#ifndef EEDB_USER_HISTORY_H +#define EEDB_USER_HISTORY_H + +#include +#include +#include + +namespace eedb { + + namespace user_history_ { + + struct Id { + struct _alias_t { + static constexpr const char _literal[] ="id"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T id; + T &operator()() { return id; } + const T &operator()() const { return id; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::integer, sqlpp::tag::must_not_insert, sqlpp::tag::must_not_update>; + }; + + struct Uid { + struct _alias_t { + static constexpr const char _literal[] ="uid"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T uid; + T &operator()() { return uid; } + const T &operator()() const { return uid; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::integer, sqlpp::tag::require_insert>; + }; + + struct Action { + struct _alias_t { + static constexpr const char _literal[] ="action"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T action; + T &operator()() { return action; } + const T &operator()() const { return action; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::text, sqlpp::tag::require_insert>; + }; + + struct When { + struct _alias_t { + static constexpr const char _literal[] ="when"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T when; + T &operator()() { return when; } + const T &operator()() const { return when; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::time_point, sqlpp::tag::can_be_null>; + }; + } + + struct user_history : sqlpp::table_t { + using _value_type = sqlpp::no_value_t; + struct _alias_t { + static constexpr const char _literal[] = "user_history"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T user_history; + T &operator()() { return user_history; } + const T &operator()() const { return user_history; } + }; + }; + }; +} + +#endif diff --git a/src/eedb/model/user_inventory.h b/src/eedb/model/user_inventory.h new file mode 100644 index 0000000..ec2eb6e --- /dev/null +++ b/src/eedb/model/user_inventory.h @@ -0,0 +1,60 @@ +#ifndef EEDB_USER_INVENTORY_H +#define EEDB_USER_INVENTORY_H + +#include +#include +#include + +namespace eedb { + + namespace user_inventory_ { + + struct User_id { + struct _alias_t { + static constexpr const char _literal[] ="user_id"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T user_id; + T &operator()() { return user_id; } + const T &operator()() const { return user_id; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::integer, sqlpp::tag::require_insert>; + }; + + struct Inventory_id { + struct _alias_t { + static constexpr const char _literal[] ="inventory_id"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T inventory_id; + T &operator()() { return inventory_id; } + const T &operator()() const { return inventory_id; } + }; + }; + + using _traits = ::sqlpp::make_traits<::sqlpp::integer, sqlpp::tag::require_insert>; + }; + } + + struct user_inventory : sqlpp::table_t { + using _value_type = sqlpp::no_value_t; + struct _alias_t { + static constexpr const char _literal[] = "user_inventory"; + using _name_t = sqlpp::make_char_sequence; + template + struct _member_t { + T user_inventory; + T &operator()() { return user_inventory; } + const T &operator()() const { return user_inventory; } + }; + }; + }; +} + +#endif diff --git a/src/eedb/model/users.hpp b/src/eedb/model/users.hpp deleted file mode 100644 index 5bb7c07..0000000 --- a/src/eedb/model/users.hpp +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -namespace eedb::model{ - - - -} diff --git a/src/eedb/model/users.cpp b/src/eedb/widgets/MainWindow.cpp similarity index 100% rename from src/eedb/model/users.cpp rename to src/eedb/widgets/MainWindow.cpp diff --git a/src/eedb/widgets/MainWindow.hpp b/src/eedb/widgets/MainWindow.hpp new file mode 100644 index 0000000..e69de29