Older/WebApplication/Application.h

72 lines
1.8 KiB
C
Raw Normal View History

2024-10-30 23:59:59 +08:00
#ifndef __WEBAPPLICATION_H__
#define __WEBAPPLICATION_H__
2024-11-11 19:21:48 +08:00
#include "Singleton.h"
2024-12-01 15:10:25 +08:00
#include <Wt/WApplication.h>
2024-11-14 23:06:22 +08:00
#include <memory>
2025-01-03 14:12:02 +08:00
#include <unordered_set>
2024-10-30 23:59:59 +08:00
namespace Wt {
class WServer;
2024-11-14 23:06:22 +08:00
class WApplication;
class WEnvironment;
2024-11-07 18:21:04 +08:00
2024-11-11 19:21:48 +08:00
namespace Auth {
class AuthService;
class PasswordService;
2025-01-03 14:12:02 +08:00
class AuthTokenResult;
2024-11-11 19:21:48 +08:00
} // namespace Auth
2024-11-07 18:21:04 +08:00
}; // namespace Wt
2024-10-30 23:59:59 +08:00
2024-12-01 15:10:25 +08:00
class Session;
2024-12-21 13:35:12 +08:00
class LoginPage;
class NavigationBar;
2024-11-14 23:06:22 +08:00
2024-12-01 15:10:25 +08:00
namespace WebToolkit {
class Application : public Wt::WApplication {
2024-10-30 23:59:59 +08:00
public:
2024-12-01 15:10:25 +08:00
Application(const Wt::WEnvironment &env, bool embedded);
~Application();
protected:
void authEvent();
void handlePathChange(const std::string &path);
private:
std::unique_ptr<Session> m_session;
std::string m_externalPath;
Wt::WContainerWidget *m_root = nullptr;
2024-12-21 13:35:12 +08:00
NavigationBar *m_navigationBar = nullptr;
std::unique_ptr<LoginPage> m_loginPage;
LoginPage *m_loginPageRef = nullptr;
2024-12-01 15:10:25 +08:00
};
class Server {
friend class Amass::Singleton<Server>;
public:
~Server();
2024-10-30 23:59:59 +08:00
2024-11-11 19:21:48 +08:00
void initializeAuthenticationService();
2024-12-26 23:10:41 +08:00
Wt::Auth::AuthService &authService();
2024-11-11 19:21:48 +08:00
const Wt::Auth::PasswordService &passwordService();
2025-01-03 14:12:02 +08:00
void insertCookie(const std::string &cookie);
Wt::Http::Cookie updateCookie(const std::string &oldCookie, const Wt::Auth::AuthTokenResult &result, bool secure);
2024-11-11 19:21:48 +08:00
protected:
2024-12-01 20:01:13 +08:00
Server(uint16_t port, const std::string &applicationRoot, const std::string &documentRoot);
2024-11-14 23:06:22 +08:00
std::unique_ptr<Wt::WApplication> createApplication(const Wt::WEnvironment &env, bool embedded);
2024-11-11 19:21:48 +08:00
2024-10-30 23:59:59 +08:00
private:
std::unique_ptr<Wt::WServer> m_server;
2024-11-11 19:21:48 +08:00
std::unique_ptr<Wt::Auth::AuthService> m_authService;
std::unique_ptr<Wt::Auth::PasswordService> m_passwordService;
2025-01-03 14:12:02 +08:00
std::unordered_set<std::string> m_cookies;
2024-10-30 23:59:59 +08:00
};
2024-12-01 15:10:25 +08:00
} // namespace WebToolkit
2024-10-30 23:59:59 +08:00
#endif // __WEBAPPLICATION_H__