This commit is contained in:
parent
bce19e3dc1
commit
80e52feee6
@ -14,8 +14,7 @@
|
|||||||
#include <Wt/WPushButton.h>
|
#include <Wt/WPushButton.h>
|
||||||
#include <Wt/WText.h>
|
#include <Wt/WText.h>
|
||||||
|
|
||||||
Hello::Hello(const Wt::WEnvironment &env, Wt::Dbo::SqlConnectionPool &connectionPool, bool embedded)
|
Hello::Hello(const Wt::WEnvironment &env, Wt::Dbo::SqlConnectionPool &connectionPool, bool embedded) : Wt::WApplication(env) {
|
||||||
: Wt::WApplication(env) {
|
|
||||||
LOG(info) << "app root: " << appRoot();
|
LOG(info) << "app root: " << appRoot();
|
||||||
m_session = std::make_unique<Session>(connectionPool);
|
m_session = std::make_unique<Session>(connectionPool);
|
||||||
m_session->login().changed().connect(this, &Hello::authEvent);
|
m_session->login().changed().connect(this, &Hello::authEvent);
|
||||||
@ -34,10 +33,20 @@ Hello::Hello(const Wt::WEnvironment &env, Wt::Dbo::SqlConnectionPool &connection
|
|||||||
} else {
|
} else {
|
||||||
LOG(error) << "Missing: parameter: 'div'";
|
LOG(error) << "Missing: parameter: 'div'";
|
||||||
}
|
}
|
||||||
|
internalPathChanged().connect(this, &Hello::handlePathChange);
|
||||||
|
auto externalPath = env.getParameter("path");
|
||||||
|
if (externalPath != nullptr) {
|
||||||
|
m_externalPath = *externalPath;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
auto parameters = env.getParameterMap();
|
||||||
|
for (auto &p : parameters) {
|
||||||
|
LOG(info) << p.first;
|
||||||
|
}
|
||||||
|
}
|
||||||
LOG(info) << "url: " << url();
|
LOG(info) << "url: " << url();
|
||||||
LOG(info) << "relative resources url: " << relativeResourcesUrl();
|
LOG(info) << "relative resources url: " << relativeResourcesUrl();
|
||||||
LOG(info) << "resources url: " << resourcesUrl();
|
LOG(info) << "resources url: " << resourcesUrl();
|
||||||
url();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!embedded) {
|
if (!embedded) {
|
||||||
@ -60,8 +69,7 @@ Hello::Hello(const Wt::WEnvironment &env, Wt::Dbo::SqlConnectionPool &connection
|
|||||||
m_nameEdit->enterPressed().connect(this, &Hello::greet);
|
m_nameEdit->enterPressed().connect(this, &Hello::greet);
|
||||||
|
|
||||||
auto app = Amass::Singleton<WebApplication>::instance();
|
auto app = Amass::Singleton<WebApplication>::instance();
|
||||||
auto authWidget =
|
auto authWidget = std::make_unique<Wt::Auth::AuthWidget>(app->authService(), m_session->users(), m_session->login());
|
||||||
std::make_unique<Wt::Auth::AuthWidget>(app->authService(), m_session->users(), m_session->login());
|
|
||||||
authWidget->setInternalBasePath("/");
|
authWidget->setInternalBasePath("/");
|
||||||
authWidget->model()->addPasswordAuth(&app->passwordService());
|
authWidget->model()->addPasswordAuth(&app->passwordService());
|
||||||
authWidget->setRegistrationEnabled(true);
|
authWidget->setRegistrationEnabled(true);
|
||||||
@ -76,6 +84,7 @@ Hello::~Hello() {
|
|||||||
|
|
||||||
void Hello::greet() {
|
void Hello::greet() {
|
||||||
m_greeting->setText("Hello there, " + m_nameEdit->text());
|
m_greeting->setText("Hello there, " + m_nameEdit->text());
|
||||||
|
setInternalPath(m_externalPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hello::authEvent() {
|
void Hello::authEvent() {
|
||||||
@ -87,3 +96,7 @@ void Hello::authEvent() {
|
|||||||
LOG(info) << "User logged out.";
|
LOG(info) << "User logged out.";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Hello::handlePathChange(const std::string &path) {
|
||||||
|
LOG(info) << "handlePathChange: " << path;
|
||||||
|
}
|
||||||
|
@ -13,11 +13,13 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
void greet();
|
void greet();
|
||||||
void authEvent();
|
void authEvent();
|
||||||
|
void handlePathChange(const std::string &path);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Wt::WLineEdit *m_nameEdit = nullptr;
|
Wt::WLineEdit *m_nameEdit = nullptr;
|
||||||
Wt::WText *m_greeting = nullptr;
|
Wt::WText *m_greeting = nullptr;
|
||||||
std::unique_ptr<Session> m_session;
|
std::unique_ptr<Session> m_session;
|
||||||
|
std::string m_externalPath;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // __HELLO_H__
|
#endif // __HELLO_H__
|
@ -30,7 +30,7 @@ WebApplication::WebApplication() {
|
|||||||
"/hello");
|
"/hello");
|
||||||
m_server->addEntryPoint(Wt::EntryPointType::WidgetSet,
|
m_server->addEntryPoint(Wt::EntryPointType::WidgetSet,
|
||||||
std::bind(&WebApplication::createApplication, this, std::placeholders::_1, true),
|
std::bind(&WebApplication::createApplication, this, std::placeholders::_1, true),
|
||||||
"/gui/hello.js");
|
"/wt.js");
|
||||||
m_server->addResource(std::make_shared<AuthenticationResource>(*m_sqlConnectionPool), "/auth");
|
m_server->addResource(std::make_shared<AuthenticationResource>(*m_sqlConnectionPool), "/auth");
|
||||||
m_server->addResource(std::make_shared<PlaintextResource>(), "/plaintext");
|
m_server->addResource(std::make_shared<PlaintextResource>(), "/plaintext");
|
||||||
m_server->addResource(std::make_shared<DbResource>("database.sqlite"), "/db");
|
m_server->addResource(std::make_shared<DbResource>("database.sqlite"), "/db");
|
||||||
|
Loading…
Reference in New Issue
Block a user