Older/WebApplication/RedirectPage.cpp
amass 1301e4bbc5
All checks were successful
Deploy / Build (push) Successful in 6m48s
add redirect page.
2025-01-05 00:33:19 +08:00

38 lines
1.0 KiB
C++

#include "RedirectPage.h"
#include "BoostLog.h"
#include <Wt/WTimer.h>
constexpr auto Template = R"(
<p>${message}</p>
<div>${seconds}</div>
)";
RedirectPage::RedirectPage() : Wt::WTemplate(Template) {
m_timer = addChild(std::make_unique<Wt::WTimer>());
m_timer->setInterval(std::chrono::milliseconds(1000));
m_timer->timeout().connect(this, &RedirectPage::onTimeout);
m_timer->start();
bindInt("seconds", m_time / 1000);
}
void RedirectPage::setRedirect(const std::string &path, const std::string &message) {
bindString("message", message);
if (m_redirect != path) {
m_redirect = path;
}
}
void RedirectPage::onTimeout() {
m_time -= 1000;
bindInt("seconds", m_time / 1000);
if (m_time <= 0) {
m_timer->stop();
auto app = Wt::WApplication::instance();
if (m_redirect.starts_with("/wt")) {
app->setInternalPath(m_redirect, true);
} else {
app->redirect(m_redirect);
}
}
}