#include "WebApplication.h" #include "BoostLog.h" #include "Database/Session.h" #include "Hello.h" #include "Restful.h" #include #include #include #include #include #include #include #include #include #include WebApplication::WebApplication(uint16_t port, const std::string &documentRoot) { try { std::vector args; args.push_back(std::format("--docroot={};/resources", documentRoot)); args.push_back(std::format("--approot={}/resources", documentRoot)); args.push_back(std::format("--http-listen=127.0.0.1:{}", port)); initializeAuthenticationService(); m_server = std::make_unique(std::format("{}/resources", documentRoot), args); m_server->addEntryPoint(Wt::EntryPointType::Application, std::bind(&WebApplication::createApplication, this, std::placeholders::_1, false)); m_server->addEntryPoint(Wt::EntryPointType::WidgetSet, std::bind(&WebApplication::createApplication, this, std::placeholders::_1, true), "/wt/app.js"); m_server->addResource(std::make_shared(), "/auth"); m_server->addResource(std::make_shared(), "/plaintext"); m_server->addResource(std::make_shared(std::format("{}/database.sqlite", documentRoot)), "/db"); m_server->start(); } catch (const std::exception &e) { LOG(error) << e.what(); } } std::unique_ptr WebApplication::createApplication(const Wt::WEnvironment &env, bool embedded) { return std::make_unique(env, embedded); } WebApplication::~WebApplication() { } void WebApplication::initializeAuthenticationService() { m_authService = std::make_unique(); m_authService->setAuthTokensEnabled(true, "logincookie"); m_passwordService = std::make_unique(*m_authService); auto verifier = std::make_unique(); verifier->addHashFunction(std::make_unique(7)); m_passwordService->setVerifier(std::move(verifier)); m_passwordService->setPasswordThrottle(std::make_unique()); m_passwordService->setStrengthValidator(std::make_unique()); } const Wt::Auth::AuthService &WebApplication::authService() { return *m_authService; } const Wt::Auth::PasswordService &WebApplication::passwordService() { return *m_passwordService; }