ORE Studio 0.0.4
Loading...
Searching...
No Matches
account_service.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2025 Marco Craveiro <marco.craveiro@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 3 of the License, or (at your option) any later
8 * version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20
21#ifndef ORES_IAM_SERVICE_ACCOUNT_SERVICE_HPP
22#define ORES_IAM_SERVICE_ACCOUNT_SERVICE_HPP
23
24#include <string>
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"
33
35
40private:
41 inline static std::string_view logger_name =
42 "ores.iam.service.account_service";
43
44 [[nodiscard]] static auto& lg() {
45 using namespace ores::logging;
46 static auto instance = make_logger(logger_name);
47 return instance;
48 }
49
50 static void throw_if_empty(const std::string& name, const std::string& value);
51
52public:
54
63
82 domain::account create_account(const std::string& username,
83 const std::string& email, const std::string& password,
84 const std::string& recorded_by,
85 const std::string& change_commentary = "Account created");
86
93 std::optional<domain::account> get_account(const boost::uuids::uuid& account_id);
94
100 std::vector<domain::account> list_accounts();
101
109 std::vector<domain::account> list_accounts(std::uint32_t offset,
110 std::uint32_t limit);
111
117 std::uint32_t get_total_account_count();
118
124 std::vector<domain::login_info> list_login_info();
125
131 void delete_account(const boost::uuids::uuid& account_id);
132
149 domain::account login(const std::string& username,
150 const std::string& password, const boost::asio::ip::address& ip_address);
151
161 bool lock_account(const boost::uuids::uuid& account_id);
162
173 bool unlock_account(const boost::uuids::uuid& account_id);
174
183 void logout(const boost::uuids::uuid& account_id);
184
202 bool update_account(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);
206
216 std::vector<domain::account> get_account_history(const std::string& username);
217
227 bool set_password_reset_required(const boost::uuids::uuid& account_id);
228
239 std::string change_password(const boost::uuids::uuid& account_id,
240 const std::string& new_password);
241
249 domain::login_info get_login_info(const boost::uuids::uuid& account_id);
250
260 std::string update_my_email(const boost::uuids::uuid& account_id,
261 const std::string& new_email);
262
263private:
264 repository::account_repository account_repo_;
265 repository::login_info_repository login_info_repo_;
266 utility::uuid::uuid_v7_generator uuid_generator_;
267};
268
269}
270
271#endif
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