#include "Hello.h" #include "BoostLog.h" #include "Dialog.h" #include "Session.h" #include "WebApplication.h" #include #include #include #include #include #include #include #include #include #include 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(connectionPool); m_session->login().changed().connect(this, &Hello::authEvent); setTitle("Hello world"); Wt::WContainerWidget *top = nullptr; if (!embedded) { setTheme(std::make_shared()); top = root(); } else { std::unique_ptr topPtr = std::make_unique(); top = topPtr.get(); const std::string *div = env.getParameter("div"); if (div) { setJavaScriptClass(*div); bindWidget(std::move(topPtr), *div); } else { LOG(error) << "Missing: parameter: 'div'"; } LOG(info) << "url: " << url(); LOG(info) << "relative resources url: " << relativeResourcesUrl(); LOG(info) << "resources url: " << resourcesUrl(); url(); } if (!embedded) { root()->addWidget(std::make_unique("

Note: you can also run this application " "from within a web page.

")); } top->addWidget(std::make_unique("Your name, please ? ")); m_nameEdit = top->addWidget(std::make_unique()); m_nameEdit->setFocus(); auto b = top->addWidget(std::make_unique("点击我!")); b->setMargin(5, Wt::Side::Left); top->addWidget(std::make_unique()); m_greeting = top->addWidget(std::make_unique()); b->clicked().connect(this, &Hello::greet); m_nameEdit->enterPressed().connect(this, &Hello::greet); auto app = Amass::Singleton::instance(); auto authWidget = std::make_unique(app->authService(), m_session->users(), m_session->login()); authWidget->setInternalBasePath("/"); authWidget->model()->addPasswordAuth(&app->passwordService()); authWidget->setRegistrationEnabled(true); authWidget->processEnvironment(); top->addWidget(std::move(authWidget)); top->addWidget(std::make_unique()); } Hello::~Hello() { } void Hello::greet() { m_greeting->setText("Hello there, " + m_nameEdit->text()); } void Hello::authEvent() { if (m_session->login().loggedIn()) { const Wt::Auth::User &u = m_session->login().user(); LOG(info) << "User " << u.id() << " (" << u.identity(Wt::Auth::Identity::LoginName) << ")" << " logged in."; } else { LOG(info) << "User logged out."; } }