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/domain/account.hpp"
28#include "ores.iam/domain/login_info.hpp"
29#include "ores.iam/repository/account_repository.hpp"
30#include "ores.iam/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& recorded_by,
85 const std::string& change_commentary =
"Account created");
93 std::optional<domain::account>
get_account(
const boost::uuids::uuid& account_id);
109 std::vector<domain::account>
list_accounts(std::uint32_t offset,
110 std::uint32_t limit);
150 const std::string& password,
const boost::asio::ip::address& ip_address);
161 bool lock_account(
const boost::uuids::uuid& account_id);
183 void logout(
const boost::uuids::uuid& account_id);
203 const std::string& email,
const std::string& recorded_by,
204 const std::string& change_reason_code,
205 const std::string& change_commentary);
240 const std::string& new_password);
261 const std::string& new_email);
Service layer for the IAM module.
Definition account_service.hpp:34
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Context for the operations on a postgres database.
Definition context.hpp:30
Represents an account for an entity in the system.
Definition account.hpp:32
Represents login tracking and security information for an account.
Definition login_info.hpp:32
Reads and writes accounts off of data storage.
Definition account_repository.hpp:36
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
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:153
domain::account create_account(const std::string &username, const std::string &email, const std::string &password, const std::string &recorded_by, const std::string &change_commentary="Account created")
Creates a new account with the provided details.
Definition account_service.cpp:56
void logout(const boost::uuids::uuid &account_id)
Logs out a user by setting their online status to false.
Definition account_service.cpp:292
domain::login_info get_login_info(const boost::uuids::uuid &account_id)
Retrieves the login_info for a specific account.
Definition account_service.cpp:465
bool lock_account(const boost::uuids::uuid &account_id)
Locks an account, preventing login.
Definition account_service.cpp:223
std::optional< domain::account > get_account(const boost::uuids::uuid &account_id)
Gets a single account by its ID.
Definition account_service.cpp:109
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:408
std::uint32_t get_total_account_count()
Gets the total count of active accounts.
Definition account_service.cpp:126
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:257
void delete_account(const boost::uuids::uuid &account_id)
Deletes an account by its ID.
Definition account_service.cpp:134
std::vector< domain::account > list_accounts()
Lists all accounts in the system.
Definition account_service.cpp:117
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:480
bool update_account(const boost::uuids::uuid &account_id, const std::string &email, const std::string &recorded_by, const std::string &change_reason_code, const std::string &change_commentary)
Updates an existing account's email address.
Definition account_service.cpp:319
std::vector< domain::login_info > list_login_info()
Lists all login info records in the system.
Definition account_service.cpp:130
std::vector< domain::account > get_account_history(const std::string &username)
Retrieves all historical versions of an account by username.
Definition account_service.cpp:354
bool set_password_reset_required(const boost::uuids::uuid &account_id)
Sets the password_reset_required flag on an account.
Definition account_service.cpp:378
A generator for UUID version 7 (v7) based on RFC 9562.
Definition uuid_v7_generator.hpp:50