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.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"
33
34namespace ores::iam::service {
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& modified_by,
85 const std::string& change_commentary = "Account created");
86
101 domain::account create_service_account(const std::string& username,
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");
105
112 std::optional<domain::account> get_account(const boost::uuids::uuid& account_id);
113
119 std::vector<domain::account> list_accounts();
120
128 std::vector<domain::account> list_accounts(std::uint32_t offset,
129 std::uint32_t limit);
130
136 std::uint32_t get_total_account_count();
137
143 std::vector<domain::login_info> list_login_info();
144
150 void delete_account(const boost::uuids::uuid& account_id);
151
168 domain::account login(const std::string& username,
169 const std::string& password, const boost::asio::ip::address& ip_address);
170
180 bool lock_account(const boost::uuids::uuid& account_id);
181
192 bool unlock_account(const boost::uuids::uuid& account_id);
193
202 void logout(const boost::uuids::uuid& account_id);
203
221 bool update_account(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);
225
235 std::optional<domain::account> find_account_by_username(
236 const std::string& username);
237
247 std::vector<domain::account> get_account_history(const std::string& username);
248
258 bool set_password_reset_required(const boost::uuids::uuid& account_id);
259
270 std::string change_password(const boost::uuids::uuid& account_id,
271 const std::string& new_password);
272
280 domain::login_info get_login_info(const boost::uuids::uuid& account_id);
281
291 std::string update_my_email(const boost::uuids::uuid& account_id,
292 const std::string& new_email);
293
294private:
295 repository::account_repository account_repo_;
296 repository::login_info_repository login_info_repo_;
297 utility::uuid::uuid_v7_generator uuid_generator_;
298};
299
300}
301
302#endif
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