refactor
This commit is contained in:
parent
1b82853e5c
commit
625bbfc5ea
@ -4,7 +4,7 @@ project(eedb)
|
||||
add_definitions( -std=c++17 )
|
||||
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "/usr/share/cmake/Modules/")
|
||||
find_package(Wt REQUIRED)
|
||||
find_package(Wt 4.0.0 REQUIRED)
|
||||
find_package(Sqlpp11 REQUIRED)
|
||||
find_package(PostgreSQL REQUIRED)
|
||||
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
project( eedb_app )
|
||||
INCLUDE_DIRECTORIES(.)
|
||||
|
||||
|
||||
|
||||
add_subdirectory(utils)
|
||||
add_subdirectory(eedb)
|
||||
add_subdirectory(app)
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
set(SOURCES
|
||||
Application.cpp
|
||||
DatabaseConnection.cpp
|
||||
Session.cpp
|
||||
main.cpp)
|
||||
|
||||
find_package( Boost 1.54.0 REQUIRED system )
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#include "Application.hpp"
|
||||
#include "DatabaseConnection.hpp"
|
||||
|
||||
#include <eedb/EEDB.hpp>
|
||||
#include <eedb/auth/Services.hpp>
|
||||
#include <eedb/db/connection.hpp>
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
|
||||
Wt::WApplication * createApplication(const Wt::WEnvironment & env) {
|
||||
auto dbConnection = eedb::DbConnection{}.create(env);
|
||||
return eedb::Application{}.create(env, std::move(dbConnection));
|
||||
return new eedb::EEDB{env, std::move(dbConnection)};
|
||||
}
|
||||
|
||||
int main(int argc, char ** argv) {
|
||||
|
||||
@ -1,71 +0,0 @@
|
||||
#include "Application.hpp"
|
||||
|
||||
#include <Wt/WApplication>
|
||||
#include <Wt/WEnvironment>
|
||||
|
||||
#include <eedb/auth/PgUserAuth.hpp>
|
||||
#include <eedb/auth/Services.hpp>
|
||||
#include <eedb/db/connection.hpp>
|
||||
#include <eedb/widgets/AuthWidget.hpp>
|
||||
#include <eedb/widgets/MainWindow.hpp>
|
||||
#include <eedb/widgets/Theme.hpp>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <Wt/WApplication>
|
||||
#include <Wt/WBorderLayout>
|
||||
#include <Wt/WContainerWidget>
|
||||
#include <Wt/WEnvironment>
|
||||
#include <Wt/WLineEdit>
|
||||
#include <Wt/WMessageBox>
|
||||
#include <Wt/WNavigationBar>
|
||||
#include <Wt/WPopupMenu>
|
||||
#include <Wt/WServer>
|
||||
#include <Wt/WStackedWidget>
|
||||
#include <Wt/WText>
|
||||
#include <Wt/WTextArea>
|
||||
|
||||
class AuthApplication : public Wt::WApplication {
|
||||
public:
|
||||
AuthApplication(const Wt::WEnvironment & env, std::unique_ptr< eedb::db::PgConnection > _database)
|
||||
: Wt::WApplication(env), _dbConnection(std::move(_database)) {
|
||||
_login.changed().connect(this, &AuthApplication::authEvent);
|
||||
_userDatabase = std::make_unique< eedb::auth::PgUserAuth >(*_dbConnection, env);
|
||||
|
||||
root()->addStyleClass("container");
|
||||
useStyleSheet("/resources/style.css");
|
||||
|
||||
setTheme(eedb::BootstrapTheme(this).create());
|
||||
|
||||
_authWidget = new eedb::AuthWidget(eedb::auth::Services{}, *_userDatabase, _login);
|
||||
root()->addWidget(_authWidget);
|
||||
}
|
||||
|
||||
void authEvent() {
|
||||
using namespace Wt;
|
||||
|
||||
if(_login.loggedIn()) {
|
||||
Wt::WContainerWidget * container = root();
|
||||
setInternalPath("/app");
|
||||
root()->removeStyleClass("container");
|
||||
new eedb::Home(container);
|
||||
|
||||
} else {
|
||||
root()->addWidget(_authWidget);
|
||||
Wt::log("notice") << "User logged out.";
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr< eedb::db::PgConnection > _dbConnection;
|
||||
std::unique_ptr< eedb::auth::PgUserAuth > _userDatabase;
|
||||
Wt::Auth::Login _login;
|
||||
eedb::AuthWidget * _authWidget;
|
||||
};
|
||||
|
||||
namespace eedb {
|
||||
|
||||
Wt::WApplication * Application::create(const Wt::WEnvironment & env, std::unique_ptr< eedb::db::PgConnection > connection) const {
|
||||
return new AuthApplication(env, std::move(connection));
|
||||
}
|
||||
}
|
||||
@ -1,17 +0,0 @@
|
||||
#include <memory>
|
||||
|
||||
namespace Wt {
|
||||
class WApplication;
|
||||
class WEnvironment;
|
||||
}
|
||||
|
||||
namespace eedb::db {
|
||||
class PgConnection;
|
||||
}
|
||||
|
||||
namespace eedb {
|
||||
class Application {
|
||||
public:
|
||||
Wt::WApplication * create(const Wt::WEnvironment & env, std::unique_ptr< eedb::db::PgConnection > connection) const;
|
||||
};
|
||||
}
|
||||
@ -1,4 +1,5 @@
|
||||
file(GLOB SOURCE
|
||||
EEDB.cpp
|
||||
auth/PgUserAuth.cpp
|
||||
auth/Services.cpp
|
||||
data/*
|
||||
|
||||
60
src/eedb/EEDB.cpp
Normal file
60
src/eedb/EEDB.cpp
Normal file
@ -0,0 +1,60 @@
|
||||
#include "EEDB.hpp"
|
||||
|
||||
#include <Wt/WApplication>
|
||||
#include <Wt/WEnvironment>
|
||||
|
||||
#include <eedb/auth/PgUserAuth.hpp>
|
||||
#include <eedb/auth/Services.hpp>
|
||||
#include <eedb/db/connection.hpp>
|
||||
#include <eedb/widgets/AuthWidget.hpp>
|
||||
#include <eedb/widgets/MainWindow.hpp>
|
||||
#include <eedb/widgets/Theme.hpp>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <Wt/WApplication>
|
||||
#include <Wt/WBorderLayout>
|
||||
#include <Wt/WContainerWidget>
|
||||
#include <Wt/WEnvironment>
|
||||
#include <Wt/WLineEdit>
|
||||
#include <Wt/WMessageBox>
|
||||
#include <Wt/WNavigationBar>
|
||||
#include <Wt/WPopupMenu>
|
||||
#include <Wt/WServer>
|
||||
#include <Wt/WStackedWidget>
|
||||
#include <Wt/WText>
|
||||
#include <Wt/WTextArea>
|
||||
|
||||
namespace eedb {
|
||||
|
||||
EEDB::EEDB(const Wt::WEnvironment & env, std::unique_ptr< eedb::db::PgConnection > _database)
|
||||
: Wt::WApplication(env), _dbConnection(std::move(_database)) {
|
||||
_login.changed().connect(this, &EEDB::authEvent);
|
||||
_userDatabase = std::make_unique< eedb::auth::PgUserAuth >(*_dbConnection, env);
|
||||
|
||||
root()->addStyleClass("container");
|
||||
useStyleSheet("/resources/style.css");
|
||||
|
||||
setTheme(eedb::BootstrapTheme(this).create());
|
||||
|
||||
_authWidget = new eedb::AuthWidget(eedb::auth::Services{}, *_userDatabase, _login);
|
||||
root()->addWidget(_authWidget);
|
||||
}
|
||||
|
||||
void EEDB::authEvent() {
|
||||
using namespace Wt;
|
||||
|
||||
if(_login.loggedIn()) {
|
||||
Wt::WContainerWidget * container = root();
|
||||
setInternalPath("/app");
|
||||
root()->removeStyleClass("container");
|
||||
Wt::log("notice") << "Clearing root and creating widgets";
|
||||
new eedb::Home(container, &_authWidget->login());
|
||||
|
||||
} else {
|
||||
Wt::log("notice") << "User logged out.";
|
||||
redirect(url());
|
||||
quit();
|
||||
}
|
||||
}
|
||||
}
|
||||
32
src/eedb/EEDB.hpp
Normal file
32
src/eedb/EEDB.hpp
Normal file
@ -0,0 +1,32 @@
|
||||
#include <memory>
|
||||
|
||||
#include <Wt/WApplication>
|
||||
|
||||
#include <eedb/auth/PgUserAuth.hpp>
|
||||
#include <eedb/widgets/AuthWidget.hpp>
|
||||
|
||||
// remove later
|
||||
#include <Wt/Auth/Login>
|
||||
|
||||
namespace Wt {
|
||||
class WEnvironment;
|
||||
}
|
||||
|
||||
namespace eedb::db {
|
||||
class PgConnection;
|
||||
}
|
||||
|
||||
namespace eedb {
|
||||
class EEDB : public Wt::WApplication {
|
||||
public:
|
||||
EEDB(const Wt::WEnvironment & env, std::unique_ptr< eedb::db::PgConnection > _database);
|
||||
|
||||
void authEvent();
|
||||
|
||||
private:
|
||||
std::unique_ptr< eedb::db::PgConnection > _dbConnection;
|
||||
std::unique_ptr< eedb::auth::PgUserAuth > _userDatabase;
|
||||
Wt::Auth::Login _login;
|
||||
eedb::AuthWidget * _authWidget;
|
||||
};
|
||||
}
|
||||
@ -1,3 +1,4 @@
|
||||
#pragma once
|
||||
#include <Wt/Auth/AuthWidget>
|
||||
|
||||
namespace eedb::auth {
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
#include <eedb/widgets/MainWindow.hpp>
|
||||
|
||||
#include <Wt/Auth/Login>
|
||||
#include <Wt/WBorderLayout>
|
||||
#include <Wt/WContainerWidget>
|
||||
#include <Wt/WContainerWidget>
|
||||
@ -15,7 +16,7 @@
|
||||
|
||||
namespace eedb {
|
||||
|
||||
eedb::Home::Home(Wt::WContainerWidget * container) {
|
||||
eedb::Home::Home(Wt::WContainerWidget * container, Wt::Auth::Login * login) : _login(login) {
|
||||
// Create a navigation bar with a link to a web page.
|
||||
auto navigation = new Wt::WNavigationBar(container);
|
||||
navigation->setTitle("eedb", "http://eedb.pl");
|
||||
@ -45,7 +46,9 @@ eedb::Home::Home(Wt::WContainerWidget * container) {
|
||||
// Create a popup submenu for the Help menu.
|
||||
auto sessionMenuPopup = new Wt::WPopupMenu();
|
||||
sessionMenuPopup->addItem("Logout");
|
||||
// sessionMenuPopup->itemSelected().connect([=](auto...) { _authWidget->login().logout(); });
|
||||
sessionMenuPopup->setId("session.menu");
|
||||
|
||||
sessionMenuPopup->itemSelected().connect([=](auto...) { const_cast< Wt::Auth::Login * >(_login)->logout(); });
|
||||
|
||||
auto sessionItem = new Wt::WMenuItem("Session");
|
||||
sessionItem->setMenu(sessionMenuPopup);
|
||||
|
||||
@ -1,10 +1,16 @@
|
||||
namespace Wt {
|
||||
class WContainerWidget;
|
||||
}
|
||||
namespace Wt::Auth {
|
||||
class Login;
|
||||
}
|
||||
|
||||
namespace eedb {
|
||||
class Home {
|
||||
public:
|
||||
Home(Wt::WContainerWidget * container);
|
||||
Home(Wt::WContainerWidget * container, Wt::Auth::Login * login);
|
||||
|
||||
private:
|
||||
const Wt::Auth::Login * _login;
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user