This commit is contained in:
parent
6f7238ea47
commit
1301e4bbc5
@ -5,6 +5,7 @@
|
||||
#include "HomePage.h"
|
||||
#include "LoginPage.h"
|
||||
#include "NavigationBar.h"
|
||||
#include "RedirectPage.h"
|
||||
#include "Restful.h"
|
||||
#include "VisitorRecordsPage.h"
|
||||
#include "model/AuthModel.h"
|
||||
@ -154,6 +155,9 @@ void Application::handlePathChange(const std::string &path) {
|
||||
if (path.starts_with("/wt/login")) {
|
||||
if (m_session->login().loggedIn()) {
|
||||
LOG(info) << "already logged in.";
|
||||
m_root->clear();
|
||||
auto p = m_root->addNew<RedirectPage>();
|
||||
p->setRedirect("/", "您已经登录...");
|
||||
} else {
|
||||
if (m_loginPage) {
|
||||
m_root->clear();
|
||||
@ -170,6 +174,10 @@ void Application::handlePathChange(const std::string &path) {
|
||||
} else if (path.starts_with("/wt/visitor/analysis")) {
|
||||
m_root->clear();
|
||||
m_root->addNew<VisitorRecordsPage>(*m_session);
|
||||
} else if (path.starts_with("/wt/redirect")) {
|
||||
m_root->clear();
|
||||
auto p = m_root->addNew<RedirectPage>();
|
||||
p->setRedirect("/", "您已经登录...");
|
||||
} else {
|
||||
m_root->clear();
|
||||
m_root->addNew<HomePage>();
|
||||
|
@ -6,6 +6,7 @@ add_library(WebApplication
|
||||
HomePage.h HomePage.cpp
|
||||
LoginPage.h LoginPage.cpp
|
||||
NavigationBar.h NavigationBar.cpp
|
||||
RedirectPage.h RedirectPage.cpp
|
||||
VisitorRecordsPage.h VisitorRecordsPage.cpp
|
||||
Restful.h Restful.cpp
|
||||
Dialog.h Dialog.cpp
|
||||
|
37
WebApplication/RedirectPage.cpp
Normal file
37
WebApplication/RedirectPage.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
#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);
|
||||
}
|
||||
}
|
||||
}
|
20
WebApplication/RedirectPage.h
Normal file
20
WebApplication/RedirectPage.h
Normal file
@ -0,0 +1,20 @@
|
||||
#ifndef __REDIRECTPAGE_H__
|
||||
#define __REDIRECTPAGE_H__
|
||||
|
||||
#include <Wt/WTemplate.h>
|
||||
|
||||
class RedirectPage : public Wt::WTemplate {
|
||||
public:
|
||||
RedirectPage();
|
||||
void setRedirect(const std::string &path, const std::string &message);
|
||||
|
||||
protected:
|
||||
void onTimeout();
|
||||
|
||||
private:
|
||||
Wt::WTimer *m_timer = nullptr;
|
||||
int m_time = 5000;
|
||||
std::string m_redirect;
|
||||
};
|
||||
|
||||
#endif // __REDIRECTPAGE_H__
|
Loading…
Reference in New Issue
Block a user