|
ORE Studio 0.0.4
|
Service for managing user accounts including creation, listing, and deletion. More...
#include <account_service.hpp>

Public Types | |
| using | context = ores::database::context |
Public Member Functions | |
| account_service (database::context ctx) | |
| Constructs an account_service with required repositories and security components. | |
| 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. | |
| std::optional< domain::account > | get_account (const boost::uuids::uuid &account_id) |
| Gets a single account by its ID. | |
| std::vector< domain::account > | list_accounts () |
| Lists all accounts in the system. | |
| std::vector< domain::account > | list_accounts (std::uint32_t offset, std::uint32_t limit) |
| Lists accounts with pagination support. | |
| std::uint32_t | get_total_account_count () |
| Gets the total count of active accounts. | |
| std::vector< domain::login_info > | list_login_info () |
| Lists all login info records in the system. | |
| void | delete_account (const boost::uuids::uuid &account_id) |
| Deletes an account by its ID. | |
| 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. | |
| bool | lock_account (const boost::uuids::uuid &account_id) |
| Locks an account, preventing login. | |
| bool | unlock_account (const boost::uuids::uuid &account_id) |
| Unlocks an account that has been locked due to failed login attempts or manual locking. | |
| void | logout (const boost::uuids::uuid &account_id) |
| Logs out a user by setting their online status to false. | |
| 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. | |
| std::vector< domain::account > | get_account_history (const std::string &username) |
| Retrieves all historical versions of an account by username. | |
| bool | set_password_reset_required (const boost::uuids::uuid &account_id) |
| Sets the password_reset_required flag on an account. | |
| std::string | change_password (const boost::uuids::uuid &account_id, const std::string &new_password) |
| Changes the password for an account. | |
| domain::login_info | get_login_info (const boost::uuids::uuid &account_id) |
| Retrieves the login_info for a specific account. | |
| 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. | |
Service for managing user accounts including creation, listing, and deletion.
|
explicit |
Constructs an account_service with required repositories and security components.
| account_repo | The repository for managing account data. |
| login_info_repo | The repository for managing login tracking data. |
| 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.
This method receives non-computed fields of the account entity such as email, password, username, etc. It uses the password manager to compute the salt and hash, uses the account repository to create the account, and adds a new login tracking entry.
Note: Administrative privileges are now managed through RBAC roles. Use authorization_service::assign_role() to grant roles after creation.
| username | The unique username for the account |
| The email address for the account | |
| password | The plaintext password (will be hashed) |
| recorded_by | The username of the person creating the account |
| change_commentary | Optional commentary explaining account creation |

| std::optional< domain::account > get_account | ( | const boost::uuids::uuid & | account_id | ) |
Gets a single account by its ID.
| account_id | The ID of the account to retrieve |
| std::vector< domain::account > list_accounts | ( | ) |
Lists all accounts in the system.
| std::vector< domain::account > list_accounts | ( | std::uint32_t | offset, |
| std::uint32_t | limit | ||
| ) |
Lists accounts with pagination support.
| offset | Number of records to skip |
| limit | Maximum number of records to return |
| std::uint32_t get_total_account_count | ( | ) |
Gets the total count of active accounts.
| std::vector< domain::login_info > list_login_info | ( | ) |
Lists all login info records in the system.
| void delete_account | ( | const boost::uuids::uuid & | account_id | ) |
Deletes an account by its ID.
| account_id | The ID of the account to delete |
| 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.
This method validates the provided credentials against stored account data, and if successful, updates the login_info table with the current login information. It also handles failed login attempts by incrementing the failed_login_info counter and may lock the account after too many consecutive failures.
| username | The username for authentication |
| password | The plaintext password to verify |
| ip_address | The IP address of the login attempt |
| std::invalid_argument | If username or password is empty |
| std::runtime_error | If account is locked or credentials are invalid |
| bool lock_account | ( | const boost::uuids::uuid & | account_id | ) |
Locks an account, preventing login.
This method sets the account's locked status to true, preventing the user from logging in until the account is unlocked.
| account_id | The ID of the account to lock |

| bool unlock_account | ( | const boost::uuids::uuid & | account_id | ) |
Unlocks an account that has been locked due to failed login attempts or manual locking.
This method resets the account's locked status and clears the failed login counter, allowing the user to attempt to login again.
| account_id | The ID of the account to unlock |
| void logout | ( | const boost::uuids::uuid & | account_id | ) |
Logs out a user by setting their online status to false.
This method updates the login_info table to mark the user as offline.
| account_id | The ID of the account to log out |
| std::invalid_argument | If account does not exist |
| 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.
Username cannot be changed. This creates a new version of the account in the temporal history.
Note: Role assignments are managed via authorization_service::assign_role() and revoke_role().
| account_id | The ID of the account to update |
| The new email address | |
| recorded_by | The username making the change |
| change_reason_code | The change reason code for audit trail |
| change_commentary | Free-text commentary explaining the change |
| std::invalid_argument | If account does not exist |
| std::vector< domain::account > get_account_history | ( | const std::string & | username | ) |
Retrieves all historical versions of an account by username.
Returns all versions of the account from the temporal history, ordered from newest to oldest.
| username | The username of the account |
| bool set_password_reset_required | ( | const boost::uuids::uuid & | account_id | ) |
Sets the password_reset_required flag on an account.
When this flag is set, the user will be forced to change their password on their next login.
| account_id | The ID of the account to flag for password reset |
| std::string change_password | ( | const boost::uuids::uuid & | account_id, |
| const std::string & | new_password | ||
| ) |
Changes the password for an account.
Validates password strength, hashes the new password, updates the account, and clears the password_reset_required flag.
| account_id | The ID of the account to update |
| new_password | The new plaintext password (will be hashed) |
| domain::login_info get_login_info | ( | const boost::uuids::uuid & | account_id | ) |
Retrieves the login_info for a specific account.
| account_id | The ID of the account |
| std::runtime_error | If login_info not found |
| 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.
This is for self-service email updates. Validates email format.
| account_id | The ID of the account to update |
| new_email | The new email address |