|
/**************************************************************
|
|
* FPMWebGui Main-Application *
|
|
* -------------------------- *
|
|
* Handles the authentication screen and in advance sessions. *
|
|
**************************************************************/
|
|
|
|
|
|
|
|
// +------------+
|
|
// | Inclusions |
|
|
// +------------+
|
|
|
|
// - Wt-Library-Inclusions
|
|
// - - General
|
|
#include <Wt/WString.h> // https://www.webtoolkit.eu/wt/doc/reference/html/classWt_1_1WString.html
|
|
// - - Basic Widgets
|
|
#include <Wt/WApplication.h> // https://www.webtoolkit.eu/wt/doc/reference/html/classWt_1_1WApplication.html
|
|
#include <Wt/WEnvironment.h> // https://www.webtoolkit.eu/wt/doc/reference/html/classWt_1_1WEnvironment.html
|
|
#include <Wt/WBootstrapTheme.h> // https://www.webtoolkit.eu/wt/doc/reference/html/classWt_1_1WBootstrapTheme.html
|
|
#include <Wt/WCssTheme.h> // https://www.webtoolkit.eu/wt/doc/reference/html/classWt_1_1WCssTheme.html
|
|
#include <Wt/WContainerWidget.h> // https://www.webtoolkit.eu/wt/doc/reference/html/classWt_1_1WContainerWidget.html
|
|
#include <Wt/WHBoxLayout.h> // https://www.webtoolkit.eu/wt/doc/reference/html/classWt_1_1WHBoxLayout.html
|
|
#include <Wt/WImage.h> // https://www.webtoolkit.eu/wt/doc/reference/html/classWt_1_1WImage.html
|
|
// - - Web Application Server
|
|
#include <Wt/WServer.h> // https://www.webtoolkit.eu/wt/doc/reference/html/classWt_1_1WServer.html
|
|
// - - Database
|
|
#include <Wt/Dbo/Dbo.h> // https://www.webtoolkit.eu/wt/doc/reference/html/classWt_1_1Dbo_1_1Dbo.html
|
|
// - - Authentication
|
|
#include <Wt/Auth/AuthModel.h> // https://www.webtoolkit.eu/wt/doc/reference/html/classWt_1_1Auth_1_1AuthModel.html
|
|
#include <Wt/Auth/AuthWidget.h> // https://www.webtoolkit.eu/wt/doc/reference/html/classWt_1_1Auth_1_1AuthWidget.html
|
|
#include <Wt/Auth/PasswordService.h> // https://www.webtoolkit.eu/wt/doc/reference/html/classWt_1_1Auth_1_1PasswordService.html
|
|
// - Custom Inclusions
|
|
#include "main.h" // Prototype definition of class "AuthApplication" and its functions.
|
|
#include "model/Session.h" //
|
|
#include "BaseScreen.h" //
|
|
|
|
|
|
|
|
// +--------------------------------+
|
|
// | Class-Function-Implementations |
|
|
// +--------------------------------+
|
|
|
|
AuthApplication::AuthApplication(const Wt::WEnvironment& env) :
|
|
Wt::WApplication(env),
|
|
session_() {
|
|
session_.login().changed().connect(this, &AuthApplication::authEvent);
|
|
createLoginScreen();
|
|
}
|
|
|
|
// Creates the Login-Screen.
|
|
void AuthApplication::createLoginScreen() {
|
|
root()->addStyleClass("container");
|
|
auto theme = std::make_shared<Wt::WBootstrapTheme>();
|
|
theme->setVersion(Wt::BootstrapVersion::v3);
|
|
this->setTheme(theme);
|
|
//this->setTheme(new Wt::WBootstrapTheme());
|
|
//WApplication::requireJQuery(), solves the jQuery version mismatch bug at my personal machine.
|
|
requireJQuery("resources/jquery.min.js");
|
|
//This need not be checked in.
|
|
std::unique_ptr<Wt::WContainerWidget> container_logo = std::make_unique<Wt::WContainerWidget>();
|
|
//Wt::WContainerWidget *container_logo = new Wt::WContainerWidget();
|
|
Wt::WImage *image = container_logo->addWidget(std::make_unique<Wt::WImage>(Wt::WLink("icons/wt_powered.jpg")));
|
|
image->setAlternateText("Fraunhofer ITWM");
|
|
std::unique_ptr<Wt::Auth::AuthWidget> authWidget = std::make_unique<Wt::Auth::AuthWidget>(Session::auth(), session_.users(), session_.login());
|
|
|
|
authWidget->model()->addPasswordAuth(&Session::passwordAuth());
|
|
authWidget->setRegistrationEnabled(true);
|
|
|
|
authWidget->processEnvironment();
|
|
root()->addWidget(std::move(container_logo));
|
|
//Wt::WContainerWidget *container_logo = root()->addWidget(std::make_unique<Wt::WContainerWidget>()); //works fine but meh tomorrow
|
|
|
|
root()->addWidget(std::move(authWidget));
|
|
}
|
|
|
|
// Handles user-logins and user-logouts.
|
|
void AuthApplication::authEvent() {
|
|
|
|
//std::cout<<"---------INSIDE the authEvent() function block------------\n"; // -> von Rajveer; auskommentiert von Stefan
|
|
if (session_.login().loggedIn()) {
|
|
const Wt::Auth::User& u = session_.login().user();
|
|
Wt::log("notice")
|
|
<< "User " << u.id()
|
|
<< " (" << u.identity(Wt::Auth::Identity::LoginName) << ")"
|
|
<< " logged in.";
|
|
//populating the User table with details of the newly created user // "newly created"?
|
|
session_.addNames();
|
|
createApplicationTree();
|
|
} else {
|
|
Wt::log("notice") << "User logged out.";
|
|
//createApplicationTree();
|
|
root()->clear();
|
|
createLoginScreen();
|
|
}
|
|
}
|
|
|
|
void AuthApplication::createApplicationTree() {
|
|
|
|
if (appRoot().empty()) {
|
|
std::cerr << "!!!!!!!!!!" << std::endl
|
|
<< "!! Warning: read the README.md file for hints on deployment,"
|
|
<< " the approot looks suspect!" << std::endl
|
|
<< "!!!!!!!!!!" << std::endl;
|
|
}
|
|
root()->removeStyleClass("container");
|
|
// root()->setTheme(new Wt::WBootstrapTheme(app));
|
|
|
|
// load text bundles (for the tr() function)
|
|
messageResourceBundle().use(appRoot() + "text");
|
|
// app->messageResourceBundle().use(app->appRoot() + "src");
|
|
|
|
//wt 3: Wt::WHBoxLayout *layout = new Wt::WHBoxLayout(root());
|
|
auto layout = root()->setLayout(std::make_unique<Wt::WHBoxLayout>());
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
|
std::unique_ptr<BaseScreen> baseScreen = std::make_unique<BaseScreen>(session_); //error on creating base screen.
|
|
layout->addWidget(std::move(baseScreen));
|
|
//wt3 : layout->addWidget(new BaseScreen(session_));
|
|
setTitle("FPMWeb");
|
|
|
|
useStyleSheet("style/everywidget.css");
|
|
useStyleSheet("style/dragdrop.css");
|
|
}
|
|
|
|
|
|
|
|
// +----------------------+
|
|
// | Actual Main-Function |
|
|
// +----------------------+
|
|
|
|
std::unique_ptr<Wt::WApplication> createApplication(const Wt::WEnvironment& env) {
|
|
return std::make_unique<AuthApplication>(env);
|
|
}
|
|
|
|
int main(int argc, char **argv) {
|
|
try {
|
|
Wt::WServer server(argc, argv, WTHTTP_CONFIGURATION);
|
|
server.addEntryPoint(Wt::EntryPointType::Application, createApplication);
|
|
Session::configureAuth();
|
|
server.run();
|
|
Wt::WApplication *app = Wt::WApplication::instance();
|
|
app->internalPathChanged().connect(std::bind([=] () {
|
|
createApplication(app->environment());
|
|
}));
|
|
} catch (Wt::WServer::Exception& e) {
|
|
std::cerr << "main.C::main::WServer-Exception: " << e.what() << std::endl;
|
|
} catch (std::exception &e) {
|
|
std::cerr << "main.C::main::Exception: " << e.what() << std::endl;
|
|
}
|
|
}
|