修改wt url.
All checks were successful
Deploy / Build (push) Successful in 4m31s

This commit is contained in:
luocai 2024-11-19 19:23:08 +08:00
parent bce19e3dc1
commit 80e52feee6
3 changed files with 22 additions and 7 deletions

View File

@ -14,8 +14,7 @@
#include <Wt/WPushButton.h>
#include <Wt/WText.h>
Hello::Hello(const Wt::WEnvironment &env, Wt::Dbo::SqlConnectionPool &connectionPool, bool embedded)
: Wt::WApplication(env) {
Hello::Hello(const Wt::WEnvironment &env, Wt::Dbo::SqlConnectionPool &connectionPool, bool embedded) : Wt::WApplication(env) {
LOG(info) << "app root: " << appRoot();
m_session = std::make_unique<Session>(connectionPool);
m_session->login().changed().connect(this, &Hello::authEvent);
@ -34,10 +33,20 @@ Hello::Hello(const Wt::WEnvironment &env, Wt::Dbo::SqlConnectionPool &connection
} else {
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) << "relative resources url: " << relativeResourcesUrl();
LOG(info) << "resources url: " << resourcesUrl();
url();
}
if (!embedded) {
@ -60,8 +69,7 @@ Hello::Hello(const Wt::WEnvironment &env, Wt::Dbo::SqlConnectionPool &connection
m_nameEdit->enterPressed().connect(this, &Hello::greet);
auto app = Amass::Singleton<WebApplication>::instance();
auto authWidget =
std::make_unique<Wt::Auth::AuthWidget>(app->authService(), m_session->users(), m_session->login());
auto authWidget = std::make_unique<Wt::Auth::AuthWidget>(app->authService(), m_session->users(), m_session->login());
authWidget->setInternalBasePath("/");
authWidget->model()->addPasswordAuth(&app->passwordService());
authWidget->setRegistrationEnabled(true);
@ -76,6 +84,7 @@ Hello::~Hello() {
void Hello::greet() {
m_greeting->setText("Hello there, " + m_nameEdit->text());
setInternalPath(m_externalPath);
}
void Hello::authEvent() {
@ -87,3 +96,7 @@ void Hello::authEvent() {
LOG(info) << "User logged out.";
}
}
void Hello::handlePathChange(const std::string &path) {
LOG(info) << "handlePathChange: " << path;
}

View File

@ -7,17 +7,19 @@ class Session;
class Hello : public Wt::WApplication {
public:
Hello(const Wt::WEnvironment &env,Wt::Dbo::SqlConnectionPool &connectionPool, bool embedded);
Hello(const Wt::WEnvironment &env, Wt::Dbo::SqlConnectionPool &connectionPool, bool embedded);
~Hello();
protected:
void greet();
void authEvent();
void handlePathChange(const std::string &path);
private:
Wt::WLineEdit *m_nameEdit = nullptr;
Wt::WText *m_greeting = nullptr;
std::unique_ptr<Session> m_session;
std::string m_externalPath;
};
#endif // __HELLO_H__

View File

@ -30,7 +30,7 @@ WebApplication::WebApplication() {
"/hello");
m_server->addEntryPoint(Wt::EntryPointType::WidgetSet,
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<PlaintextResource>(), "/plaintext");
m_server->addResource(std::make_shared<DbResource>("database.sqlite"), "/db");