WIP. User authentication on user interface
This commit is contained in:
@@ -1,14 +1,55 @@
|
||||
#include "DatabaseHandler.hpp"
|
||||
#include <Wt/Auth/Dbo/AuthInfo>
|
||||
#include <Wt/Auth/Dbo/UserDatabase>
|
||||
#include <Wt/Auth/AuthService>
|
||||
#include <Wt/Auth/HashFunction>
|
||||
#include <Wt/Auth/PasswordService>
|
||||
#include <Wt/Auth/PasswordStrengthValidator>
|
||||
#include <Wt/Auth/PasswordVerifier>
|
||||
|
||||
// Db types
|
||||
#include "AudioTypes.hpp"
|
||||
#include "FileTypes.hpp"
|
||||
#include "MediaDirectory.hpp"
|
||||
#include "User.hpp"
|
||||
|
||||
#include "DatabaseHandler.hpp"
|
||||
|
||||
namespace Database {
|
||||
|
||||
|
||||
namespace {
|
||||
Wt::Auth::AuthService authService;
|
||||
Wt::Auth::PasswordService passwordService(authService);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Handler::configureAuth(void)
|
||||
{
|
||||
authService.setEmailVerificationEnabled(true);
|
||||
|
||||
Wt::Auth::PasswordVerifier *verifier = new Wt::Auth::PasswordVerifier();
|
||||
verifier->addHashFunction(new Wt::Auth::BCryptHashFunction(8));
|
||||
passwordService.setVerifier(verifier);
|
||||
passwordService.setAttemptThrottlingEnabled(true);
|
||||
passwordService.setStrengthValidator(new Wt::Auth::PasswordStrengthValidator());
|
||||
}
|
||||
|
||||
const Wt::Auth::AuthService&
|
||||
Handler::getAuthService()
|
||||
{
|
||||
return authService;
|
||||
}
|
||||
|
||||
const Wt::Auth::PasswordService&
|
||||
Handler::getPasswordService()
|
||||
{
|
||||
return passwordService;
|
||||
}
|
||||
|
||||
|
||||
Handler::Handler(boost::filesystem::path db)
|
||||
:
|
||||
_path(db),
|
||||
_dbBackend( db.string() )
|
||||
{
|
||||
_session.setConnection(_dbBackend);
|
||||
@@ -22,6 +63,11 @@ _dbBackend( db.string() )
|
||||
_session.mapClass<Database::MediaDirectory>("media_directory");
|
||||
_session.mapClass<Database::MediaDirectorySettings>("media_directory_settings");
|
||||
|
||||
_session.mapClass<Database::User>("user");
|
||||
_session.mapClass<Database::AuthInfo>("auth_info");
|
||||
_session.mapClass<Database::AuthInfo::AuthIdentityType>("auth_identity");
|
||||
_session.mapClass<Database::AuthInfo::AuthTokenType>("auth_token");
|
||||
|
||||
try {
|
||||
_session.createTables();
|
||||
}
|
||||
@@ -30,6 +76,19 @@ _dbBackend( db.string() )
|
||||
}
|
||||
|
||||
_dbBackend.executeSql("pragma journal_mode=WAL");
|
||||
|
||||
_users = new UserDatabase(_session);
|
||||
}
|
||||
|
||||
Handler::~Handler()
|
||||
{
|
||||
delete _users;
|
||||
}
|
||||
|
||||
Wt::Auth::AbstractUserDatabase&
|
||||
Handler::getUserDatabase()
|
||||
{
|
||||
return *_users;
|
||||
}
|
||||
|
||||
} // namespace Database
|
||||
|
||||
Reference in New Issue
Block a user