Older/WebApplication/Session.cpp
amass d37cf655dc
Some checks failed
Deploy / Build (push) Failing after 6m49s
Deploy Docker Images / Build dockerfile and Server deploy (push) Successful in 1h12m51s
clean code.
2024-11-14 23:06:22 +08:00

48 lines
1.3 KiB
C++

#include "Session.h"
#include "BoostLog.h"
#include <Wt/Auth/Dbo/AuthInfo.h>
#include <Wt/Auth/Dbo/UserDatabase.h>
#include <Wt/Auth/FacebookService.h>
#include <Wt/Auth/GoogleService.h>
#include <Wt/Auth/HashFunction.h>
#include <Wt/Auth/PasswordService.h>
#include <Wt/Auth/PasswordStrengthValidator.h>
#include <Wt/Auth/PasswordVerifier.h>
#include <Wt/Dbo/backend/Sqlite3.h>
Session::Session(Wt::Dbo::SqlConnectionPool &connectionPool) : m_connectionPool(connectionPool) {
setConnectionPool(m_connectionPool);
mapClass<User>("user");
mapClass<AuthInfo>("auth_info");
mapClass<AuthInfo::AuthIdentityType>("auth_identity");
mapClass<AuthInfo::AuthTokenType>("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<UserDatabase>(*this);
}
Session::~Session() {
}
Wt::Dbo::ptr<User> Session::user() const {
if (m_login.loggedIn()) {
Wt::Dbo::ptr<AuthInfo> authInfo = m_users->find(m_login.user());
return authInfo->user();
} else
return Wt::Dbo::ptr<User>();
}
Wt::Auth::AbstractUserDatabase &Session::users() {
return *m_users;
}
Wt::Auth::Login &Session::login() {
return m_login;
}