77 lines
2.0 KiB
C++
77 lines
2.0 KiB
C++
#ifndef __WEBAPPLICATION_H__
|
|
#define __WEBAPPLICATION_H__
|
|
|
|
#include "Singleton.h"
|
|
#include <Wt/WApplication.h>
|
|
#include <memory>
|
|
#include <unordered_map>
|
|
#include "Database/User.h"
|
|
|
|
namespace Wt {
|
|
class WServer;
|
|
class WApplication;
|
|
class WEnvironment;
|
|
|
|
namespace Auth {
|
|
class AuthService;
|
|
class PasswordService;
|
|
class AuthTokenResult;
|
|
} // namespace Auth
|
|
|
|
}; // namespace Wt
|
|
|
|
class Session;
|
|
class LoginPage;
|
|
class NavigationBar;
|
|
|
|
namespace WebToolkit {
|
|
|
|
class Application : public Wt::WApplication {
|
|
public:
|
|
Application(const Wt::WEnvironment &env, bool embedded);
|
|
~Application();
|
|
|
|
protected:
|
|
void authEvent();
|
|
void handlePathChange(const std::string &path);
|
|
|
|
private:
|
|
std::unique_ptr<Session> m_session;
|
|
Wt::JSignal<> m_startup;
|
|
|
|
Wt::WContainerWidget *m_root = nullptr;
|
|
NavigationBar *m_navigationBar = nullptr;
|
|
std::unique_ptr<LoginPage> m_loginPage;
|
|
LoginPage *m_loginPageRef = nullptr;
|
|
Wt::JSignal<> m_logout;
|
|
std::string m_loginedRedirectUrl;
|
|
};
|
|
|
|
class Server {
|
|
friend class Amass::Singleton<Server>;
|
|
|
|
public:
|
|
~Server();
|
|
|
|
void initializeAuthenticationService();
|
|
Wt::Auth::AuthService &authService();
|
|
const Wt::Auth::PasswordService &passwordService();
|
|
void insertCookie(const std::string &cookie, const Wt::Auth::User &user);
|
|
Wt::Http::Cookie updateCookie(const std::string &oldCookie, const Wt::Auth::AuthTokenResult &result, bool secure);
|
|
std::optional<User> user(const std::string &cookie);
|
|
void removeCookie(const std::string &cookie);
|
|
|
|
protected:
|
|
Server(uint16_t port, const std::string &applicationRoot, const std::string &documentRoot);
|
|
std::unique_ptr<Wt::WApplication> createApplication(const Wt::WEnvironment &env, bool embedded);
|
|
|
|
private:
|
|
std::unique_ptr<Wt::WServer> m_server;
|
|
|
|
std::unique_ptr<Wt::Auth::AuthService> m_authService;
|
|
std::unique_ptr<Wt::Auth::PasswordService> m_passwordService;
|
|
|
|
std::unordered_map<std::string, User> m_cookies;
|
|
};
|
|
} // namespace WebToolkit
|
|
#endif // __WEBAPPLICATION_H__
|