21#ifndef ORES_IAM_SERVICE_ACCOUNT_SERVICE_HPP
22#define ORES_IAM_SERVICE_ACCOUNT_SERVICE_HPP
25#include <boost/uuid/uuid.hpp>
26#include <boost/asio/ip/address.hpp>
27#include "ores.iam.api/domain/account.hpp"
28#include "ores.iam.api/domain/login_info.hpp"
29#include "ores.iam.core/repository/account_repository.hpp"
30#include "ores.iam.core/repository/login_info_repository.hpp"
31#include "ores.utility/uuid/uuid_v7_generator.hpp"
32#include "ores.logging/make_logger.hpp"
41 inline static std::string_view logger_name =
42 "ores.iam.service.account_service";
44 [[nodiscard]]
static auto& lg() {
46 static auto instance = make_logger(logger_name);
50 static void throw_if_empty(
const std::string& name,
const std::string& value);
83 const std::string& email,
const std::string& password,
84 const std::string& modified_by,
85 const std::string& change_commentary =
"Account created");
102 const std::string& email,
const std::string& account_type,
103 const std::string& modified_by,
104 const std::string& change_commentary =
"Service account created");
112 std::optional<domain::account>
get_account(
const boost::uuids::uuid& account_id);
128 std::vector<domain::account>
list_accounts(std::uint32_t offset,
129 std::uint32_t limit);
169 const std::string& password,
const boost::asio::ip::address& ip_address);
180 bool lock_account(
const boost::uuids::uuid& account_id);
202 void logout(
const boost::uuids::uuid& account_id);
222 const std::string& email,
const std::string& modified_by,
223 const std::string& change_reason_code,
224 const std::string& change_commentary);
236 const std::string& username);
271 const std::string& new_password);
292 const std::string& new_email);
Service layer for the IAM module.
Definition auth_session_service.hpp:32
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Context for the operations on a postgres database.
Definition context.hpp:47
Represents an account for an entity in the system.
Definition account.hpp:34
Represents login tracking and security information for an account.
Definition login_info.hpp:33
Reads and writes accounts off of data storage.
Definition account_repository.hpp:37
Reads and writes login tracking information off of data storage.
Definition login_info_repository.hpp:36
Service for managing user accounts including creation, listing, and deletion.
Definition account_service.hpp:39
std::optional< domain::account > find_account_by_username(const std::string &username)
Finds an account by username.
Definition account_service.cpp:429
domain::account login(const std::string &username, const std::string &password, const boost::asio::ip::address &ip_address)
Authenticates a user and updates login tracking information.
Definition account_service.cpp:220
void logout(const boost::uuids::uuid &account_id)
Logs out a user by setting their online status to false.
Definition account_service.cpp:367
domain::login_info get_login_info(const boost::uuids::uuid &account_id)
Retrieves the login_info for a specific account.
Definition account_service.cpp:552
bool lock_account(const boost::uuids::uuid &account_id)
Locks an account, preventing login.
Definition account_service.cpp:298
std::optional< domain::account > get_account(const boost::uuids::uuid &account_id)
Gets a single account by its ID.
Definition account_service.cpp:176
std::string change_password(const boost::uuids::uuid &account_id, const std::string &new_password)
Changes the password for an account.
Definition account_service.cpp:495
domain::account create_service_account(const std::string &username, const std::string &email, const std::string &account_type, const std::string &modified_by, const std::string &change_commentary="Service account created")
Creates a new service account for non-human entities.
Definition account_service.cpp:110
std::uint32_t get_total_account_count()
Gets the total count of active accounts.
Definition account_service.cpp:193
domain::account create_account(const std::string &username, const std::string &email, const std::string &password, const std::string &modified_by, const std::string &change_commentary="Account created")
Creates a new account with the provided details.
Definition account_service.cpp:56
bool unlock_account(const boost::uuids::uuid &account_id)
Unlocks an account that has been locked due to failed login attempts or manual locking.
Definition account_service.cpp:332
void delete_account(const boost::uuids::uuid &account_id)
Deletes an account by its ID.
Definition account_service.cpp:201
std::vector< domain::account > list_accounts()
Lists all accounts in the system.
Definition account_service.cpp:184
std::string update_my_email(const boost::uuids::uuid &account_id, const std::string &new_email)
Updates the email address for a user's own account.
Definition account_service.cpp:567
std::vector< domain::login_info > list_login_info()
Lists all login info records in the system.
Definition account_service.cpp:197
bool update_account(const boost::uuids::uuid &account_id, const std::string &email, const std::string &modified_by, const std::string &change_reason_code, const std::string &change_commentary)
Updates an existing account's email address.
Definition account_service.cpp:394
std::vector< domain::account > get_account_history(const std::string &username)
Retrieves all historical versions of an account by username.
Definition account_service.cpp:441
bool set_password_reset_required(const boost::uuids::uuid &account_id)
Sets the password_reset_required flag on an account.
Definition account_service.cpp:465
A generator for UUID version 7 (v7) based on RFC 9562.
Definition uuid_v7_generator.hpp:50