#include "Session.h" #include "BoostLog.h" #include #include #include #include #include #include #include #include #include Wt::Auth::AuthService myAuthService; Wt::Auth::PasswordService myPasswordService(myAuthService); std::vector> myOAuthServices; Session::Session(const std::string &sqliteDb) { auto connection = std::make_unique(sqliteDb); connection->setProperty("show-queries", "true"); setConnection(std::move(connection)); mapClass("user"); mapClass("auth_info"); mapClass("auth_identity"); mapClass("auth_token"); try { createTables(); LOG(info) << "Created database."; } catch (Wt::Dbo::Exception &e) { LOG(error) << e.what() << ", using existing database"; } m_users = std::make_unique(*this); } Session::~Session() { } Wt::Auth::AbstractUserDatabase &Session::users() { return *m_users; } Wt::Auth::Login &Session::login() { return m_login; } void Session::configureAuth() { myAuthService.setAuthTokensEnabled(true, "logincookie"); // myAuthService.setEmailVerificationEnabled(true); // myAuthService.setEmailVerificationRequired(true); auto verifier = std::make_unique(); verifier->addHashFunction(std::make_unique(7)); myPasswordService.setVerifier(std::move(verifier)); myPasswordService.setPasswordThrottle(std::make_unique()); myPasswordService.setStrengthValidator(std::make_unique()); if (Wt::Auth::GoogleService::configured()) { myOAuthServices.push_back(std::make_unique(myAuthService)); } if (Wt::Auth::FacebookService::configured()) { myOAuthServices.push_back(std::make_unique(myAuthService)); } for (const auto &oAuthService : myOAuthServices) { oAuthService->generateRedirectEndpoint(); } } const Wt::Auth::AuthService &Session::auth() { return myAuthService; } const Wt::Auth::PasswordService &Session::passwordAuth() { return myPasswordService; }