eedb/src/libs/app/src/EEDB.cpp
Bartosz Wieczorek e927cd9ba0 fix #11
2018-03-01 09:22:24 +01:00

77 lines
2.1 KiB
C++

#include <eedb/EEDB.hpp>
#include <eedb/WebSession.hpp>
#include <eedb/auth/PgUserAuth.hpp>
#include <widget/AuthPage.hpp>
#include <widget/BootstrapTheme.hpp>
#include <widget/HomePage.hpp>
#include <widget/Theme.hpp>
#include <memory>
#include <Wt/Auth/AuthWidget.h>
#include <Wt/WApplication.h>
#include <Wt/WBorderLayout.h>
#include <Wt/WContainerWidget.h>
#include <Wt/WEnvironment.h>
#include <Wt/WLineEdit.h>
#include <Wt/WMessageBox.h>
#include <Wt/WNavigationBar.h>
#include <Wt/WPopupMenu.h>
#include <Wt/WServer.h>
#include <Wt/WStackedWidget.h>
#include <Wt/WText.h>
#include <Wt/WTextArea.h>
#include <spdlog/spdlog.h>
using std::move;
namespace eedb {
EEDB::EEDB(std::unique_ptr< WebSession > session, AuthPageFactory authPageFactory, HomePageFactory homePageFactory)
: Wt::WApplication(session->enviroment()),
_session(move(session)),
_authPageFactory(move(authPageFactory)),
_homePageFactory(move(homePageFactory)) {
useStyleSheet("/resources/style.css");
setTheme(eedb::BootstrapTheme{}.create());
root()->addStyleClass("container");
_authPage = _authPageFactory();
_authPage->registerOnNeedVerification([] {});
_authPage->registerOnUserWeakLogin([=] { authEventLogin(LoginState::weak); });
_authPage->registerOnUserStrongLogin([=] { authEventLogin(LoginState::strong); });
_authPage->registerOnUserLogout([=] { authEventLogout(); });
auto authWidget = _authPage->detachWidget();
authWidget->processEnvironment();
root()->addWidget(std::move(authWidget));
}
void EEDB::authEventLogin(EEDB::LoginState state) {
{
// auth widget must survive :)
auto authWidgetPtr = root()->findById("eedb.authWidget");
auto authWidget = root()->removeWidget(authWidgetPtr);
root()->clear();
root()->removeStyleClass("container");
if(authWidget)
root()->addWidget(std::move(authWidget));
}
_homePage = _homePageFactory();
_homePage->attachTo(root());
// new eedb::Home(container, &_authWidget->login());
}
void EEDB::authEventLogout() {
redirect(url());
quit();
}
} // namespace eedb