ORE Studio 0.0.4
Loading...
Searching...
No Matches
login_protocol.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#ifndef ORES_IAM_MESSAGING_LOGIN_PROTOCOL_HPP
21#define ORES_IAM_MESSAGING_LOGIN_PROTOCOL_HPP
22
23#include <span>
24#include <iosfwd>
25#include <vector>
26#include <expected>
27#include <boost/asio/ip/address.hpp>
28#include <boost/uuid/uuid.hpp>
29#include "ores.comms/messaging/message_types.hpp"
30#include "ores.comms/messaging/message_traits.hpp"
31#include "ores.iam/domain/login_info.hpp"
32
33namespace ores::iam::messaging {
34
38struct login_request final {
39 std::string username;
40 std::string password;
41
51 std::vector<std::byte> serialize() const;
52
56 static std::expected<login_request, ores::utility::serialization::error_code>
57 deserialize(std::span<const std::byte> data);
58};
59
60std::ostream& operator<<(std::ostream& s, const login_request& v);
61
68struct login_response final {
69 bool success = false;
70 std::string error_message;
71 boost::uuids::uuid account_id;
72 std::string username;
73 std::string email;
74 bool password_reset_required = false;
75
90 std::vector<std::byte> serialize() const;
91
95 static std::expected<login_response, ores::utility::serialization::error_code>
96 deserialize(std::span<const std::byte> data);
97};
98
99std::ostream& operator<<(std::ostream& s, const login_response& v);
100
105 std::vector<std::byte> serialize() const;
106 static std::expected<list_login_info_request, ores::utility::serialization::error_code>
107 deserialize(std::span<const std::byte> data);
108};
109
110std::ostream& operator<<(std::ostream& s, const list_login_info_request& v);
111
116 std::vector<domain::login_info> login_infos;
117
118 std::vector<std::byte> serialize() const;
119 static std::expected<list_login_info_response, ores::utility::serialization::error_code>
120 deserialize(std::span<const std::byte> data);
121};
122
123std::ostream& operator<<(std::ostream& s, const list_login_info_response& v);
124
133struct logout_request final {
139 std::vector<std::byte> serialize() const;
140
144 static std::expected<logout_request, ores::utility::serialization::error_code>
145 deserialize(std::span<const std::byte> data);
146};
147
148std::ostream& operator<<(std::ostream& s, const logout_request& v);
149
153struct logout_response final {
154 bool success = false;
155 std::string message;
156
165 std::vector<std::byte> serialize() const;
166
170 static std::expected<logout_response, ores::utility::serialization::error_code>
171 deserialize(std::span<const std::byte> data);
172};
173
174std::ostream& operator<<(std::ostream& s, const logout_response& v);
175
176}
177
178namespace ores::comms::messaging {
179
183template<>
184struct message_traits<iam::messaging::login_request> {
187 static constexpr message_type request_message_type =
188 message_type::login_request;
189};
190
194template<>
195struct message_traits<iam::messaging::list_login_info_request> {
198 static constexpr message_type request_message_type =
199 message_type::list_login_info_request;
200};
201
205template<>
206struct message_traits<iam::messaging::logout_request> {
209 static constexpr message_type request_message_type =
210 message_type::logout_request;
211};
212
213}
214
215#endif
Contains messaging related infrastructure in the comms library.
Definition assets_protocol.hpp:122
Network messaging infrastructure for the IAM module.
Definition account_history_protocol.hpp:33
Traits template for mapping request types to their response types and message type enum values.
Definition message_traits.hpp:66
Request to authenticate a user.
Definition login_protocol.hpp:38
std::vector< std::byte > serialize() const
Serialize request to bytes.
Definition login_protocol.cpp:36
static std::expected< login_request, ores::utility::serialization::error_code > deserialize(std::span< const std::byte > data)
Deserialize request from bytes.
Definition login_protocol.cpp:44
Response containing authentication result and account information.
Definition login_protocol.hpp:68
std::vector< std::byte > serialize() const
Serialize response to bytes.
Definition login_protocol.cpp:64
static std::expected< login_response, ores::utility::serialization::error_code > deserialize(std::span< const std::byte > data)
Deserialize response from bytes.
Definition login_protocol.cpp:76
Request to retrieve all login info records.
Definition login_protocol.hpp:104
Response containing all login info records.
Definition login_protocol.hpp:115
Request to logout the current session.
Definition login_protocol.hpp:133
std::vector< std::byte > serialize() const
Serialize request to bytes.
Definition login_protocol.cpp:216
static std::expected< logout_request, ores::utility::serialization::error_code > deserialize(std::span< const std::byte > data)
Deserialize request from bytes.
Definition login_protocol.cpp:222
Response indicating logout result.
Definition login_protocol.hpp:153
static std::expected< logout_response, ores::utility::serialization::error_code > deserialize(std::span< const std::byte > data)
Deserialize response from bytes.
Definition login_protocol.cpp:241
std::vector< std::byte > serialize() const
Serialize response to bytes.
Definition login_protocol.cpp:233