Split auth service in two services
This commit is contained in:
+11
-10
@@ -27,7 +27,8 @@
|
||||
#include <Wt/WPushButton.h>
|
||||
#include <Wt/WRandom.h>
|
||||
|
||||
#include "auth/AuthService.hpp"
|
||||
#include "auth/AuthTokenService.hpp"
|
||||
#include "auth/PasswordService.hpp"
|
||||
#include "main/Service.hpp"
|
||||
#include "utils/Logger.hpp"
|
||||
|
||||
@@ -42,7 +43,7 @@ static
|
||||
void
|
||||
createAuthToken(Database::IdType userId, const Wt::WDateTime& expiry)
|
||||
{
|
||||
const std::string secret {getService<::Auth::AuthService>()->createAuthToken(LmsApp->getDbSession(), userId, expiry)};
|
||||
const std::string secret {getService<::Auth::AuthTokenService>()->createAuthToken(LmsApp->getDbSession(), userId, expiry)};
|
||||
|
||||
LmsApp->setCookie(authCookieName,
|
||||
secret,
|
||||
@@ -60,15 +61,15 @@ processAuthToken(const Wt::WEnvironment& env)
|
||||
if (!authCookie)
|
||||
return boost::none;
|
||||
|
||||
const auto res {getService<::Auth::AuthService>()->processAuthToken(LmsApp->getDbSession(), boost::asio::ip::address::from_string(env.clientAddress()), *authCookie)};
|
||||
const auto res {getService<::Auth::AuthTokenService>()->processAuthToken(LmsApp->getDbSession(), boost::asio::ip::address::from_string(env.clientAddress()), *authCookie)};
|
||||
switch (res.state)
|
||||
{
|
||||
case ::Auth::AuthService::AuthTokenProcessResult::State::NotFound:
|
||||
case ::Auth::AuthService::AuthTokenProcessResult::State::Throttled:
|
||||
case ::Auth::AuthTokenService::AuthTokenProcessResult::State::NotFound:
|
||||
case ::Auth::AuthTokenService::AuthTokenProcessResult::State::Throttled:
|
||||
LmsApp->setCookie(authCookieName, std::string {}, 0, "", "", env.urlScheme() == "https");
|
||||
return boost::none;
|
||||
|
||||
case ::Auth::AuthService::AuthTokenProcessResult::State::Found:
|
||||
case ::Auth::AuthTokenService::AuthTokenProcessResult::State::Found:
|
||||
createAuthToken(res.authTokenInfo->userId, res.authTokenInfo->expiry);
|
||||
break;
|
||||
}
|
||||
@@ -124,18 +125,18 @@ class AuthModel : public Wt::WFormModel
|
||||
|
||||
if (field == PasswordField)
|
||||
{
|
||||
switch (getService<::Auth::AuthService>()->checkUserPassword(
|
||||
switch (getService<::Auth::PasswordService>()->checkUserPassword(
|
||||
LmsApp->getDbSession(),
|
||||
boost::asio::ip::address::from_string(LmsApp->environment().clientAddress()),
|
||||
valueText(LoginNameField).toUTF8(),
|
||||
valueText(PasswordField).toUTF8()))
|
||||
{
|
||||
case ::Auth::AuthService::PasswordCheckResult::Match:
|
||||
case ::Auth::PasswordService::PasswordCheckResult::Match:
|
||||
break;
|
||||
case ::Auth::AuthService::PasswordCheckResult::Mismatch:
|
||||
case ::Auth::PasswordService::PasswordCheckResult::Mismatch:
|
||||
error = Wt::WString::tr("Lms.password-bad-login-combination");
|
||||
break;
|
||||
case ::Auth::AuthService::PasswordCheckResult::Throttled:
|
||||
case ::Auth::PasswordService::PasswordCheckResult::Throttled:
|
||||
error = Wt::WString::tr("Lms.password-client-throttled");
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
#include "common/Validators.hpp"
|
||||
#include "common/ValueStringModel.hpp"
|
||||
|
||||
#include "auth/AuthService.hpp"
|
||||
#include "auth/PasswordService.hpp"
|
||||
#include "main/Service.hpp"
|
||||
#include "utils/Logger.hpp"
|
||||
#include "LmsApplication.hpp"
|
||||
@@ -75,7 +75,7 @@ class SettingsModel : public Wt::WFormModel
|
||||
Database::User::PasswordHash passwordHash;
|
||||
|
||||
if (!valueText(PasswordField).empty())
|
||||
passwordHash = getService<::Auth::AuthService>()->hashPassword(valueText(PasswordField).toUTF8());
|
||||
passwordHash = getService<::Auth::PasswordService>()->hashPassword(valueText(PasswordField).toUTF8());
|
||||
|
||||
auto transaction {LmsApp->getDbSession().createUniqueTransaction()};
|
||||
|
||||
@@ -125,7 +125,7 @@ class SettingsModel : public Wt::WFormModel
|
||||
{
|
||||
if (!valueText(PasswordField).empty())
|
||||
{
|
||||
if (!getService<::Auth::AuthService>()->evaluatePasswordStrength(LmsApp->getUserLoginName(), valueText(PasswordField).toUTF8()))
|
||||
if (!getService<::Auth::PasswordService>()->evaluatePasswordStrength(LmsApp->getUserLoginName(), valueText(PasswordField).toUTF8()))
|
||||
error = Wt::WString::tr("Lms.password-too-weak");
|
||||
}
|
||||
else
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
#include <Wt/WLineEdit.h>
|
||||
#include <Wt/WPushButton.h>
|
||||
|
||||
#include "auth/AuthService.hpp"
|
||||
#include "auth/PasswordService.hpp"
|
||||
#include "main/Service.hpp"
|
||||
#include "utils/Exception.hpp"
|
||||
#include "utils/Logger.hpp"
|
||||
@@ -55,7 +55,7 @@ class InitWizardModel : public Wt::WFormModel
|
||||
|
||||
void saveData()
|
||||
{
|
||||
const Database::User::PasswordHash passwordHash {getService<::Auth::AuthService>()->hashPassword(valueText(PasswordField).toUTF8())};
|
||||
const Database::User::PasswordHash passwordHash {getService<::Auth::PasswordService>()->hashPassword(valueText(PasswordField).toUTF8())};
|
||||
|
||||
auto transaction(LmsApp->getDbSession().createUniqueTransaction());
|
||||
|
||||
@@ -77,7 +77,7 @@ class InitWizardModel : public Wt::WFormModel
|
||||
if (!valueText(PasswordField).empty())
|
||||
{
|
||||
// Evaluate the strength of the password
|
||||
if (!getService<::Auth::AuthService>()->evaluatePasswordStrength(valueText(AdminLoginField).toUTF8(), valueText(PasswordField).toUTF8()))
|
||||
if (!getService<::Auth::PasswordService>()->evaluatePasswordStrength(valueText(AdminLoginField).toUTF8(), valueText(PasswordField).toUTF8()))
|
||||
error = Wt::WString::tr("Lms.password-too-weak");
|
||||
}
|
||||
else
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
#include <Wt/WFormModel.h>
|
||||
|
||||
#include "auth/AuthService.hpp"
|
||||
#include "auth/PasswordService.hpp"
|
||||
#include "database/User.hpp"
|
||||
#include "main/Service.hpp"
|
||||
#include "utils/Config.hpp"
|
||||
@@ -82,7 +82,7 @@ class UserModel : public Wt::WFormModel
|
||||
{
|
||||
boost::optional<Database::User::PasswordHash> passwordHash;
|
||||
if (!valueText(PasswordField).empty())
|
||||
passwordHash = getService<::Auth::AuthService>()->hashPassword(valueText(PasswordField).toUTF8());
|
||||
passwordHash = getService<::Auth::PasswordService>()->hashPassword(valueText(PasswordField).toUTF8());
|
||||
|
||||
auto transaction {LmsApp->getDbSession().createUniqueTransaction()};
|
||||
|
||||
@@ -172,7 +172,7 @@ class UserModel : public Wt::WFormModel
|
||||
else
|
||||
{
|
||||
// Evaluate the strength of the password for non demo accounts
|
||||
if (!getService<::Auth::AuthService>()->evaluatePasswordStrength(getLoginName(), valueText(PasswordField).toUTF8()))
|
||||
if (!getService<::Auth::PasswordService>()->evaluatePasswordStrength(getLoginName(), valueText(PasswordField).toUTF8()))
|
||||
error = Wt::WString::tr("Lms.password-too-weak");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user