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_ACCOUNTS_MESSAGING_LOGIN_PROTOCOL_HPP
21#define ORES_ACCOUNTS_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.accounts/domain/login_info.hpp"
31
32namespace ores::accounts::messaging {
33
37struct login_request final {
38 std::string username;
39 std::string password;
40
50 std::vector<std::byte> serialize() const;
51
55 static std::expected<login_request, comms::messaging::error_code>
56 deserialize(std::span<const std::byte> data);
57};
58
59std::ostream& operator<<(std::ostream& s, const login_request& v);
60
64struct login_response final {
65 bool success = false;
66 std::string error_message;
67 boost::uuids::uuid account_id;
68 std::string username;
69 std::string email;
70 bool is_admin = false;
71 bool password_reset_required = false;
72
88 std::vector<std::byte> serialize() const;
89
93 static std::expected<login_response, comms::messaging::error_code>
94 deserialize(std::span<const std::byte> data);
95};
96
97std::ostream& operator<<(std::ostream& s, const login_response& v);
98
103 std::vector<std::byte> serialize() const;
104 static std::expected<list_login_info_request, comms::messaging::error_code>
105 deserialize(std::span<const std::byte> data);
106};
107
108std::ostream& operator<<(std::ostream& s, const list_login_info_request& v);
109
114 std::vector<domain::login_info> login_infos;
115
116 std::vector<std::byte> serialize() const;
117 static std::expected<list_login_info_response, comms::messaging::error_code>
118 deserialize(std::span<const std::byte> data);
119};
120
121std::ostream& operator<<(std::ostream& s, const list_login_info_response& v);
122
131struct logout_request final {
137 std::vector<std::byte> serialize() const;
138
142 static std::expected<logout_request, comms::messaging::error_code>
143 deserialize(std::span<const std::byte> data);
144};
145
146std::ostream& operator<<(std::ostream& s, const logout_request& v);
147
151struct logout_response final {
152 bool success = false;
153 std::string message;
154
163 std::vector<std::byte> serialize() const;
164
168 static std::expected<logout_response, comms::messaging::error_code>
169 deserialize(std::span<const std::byte> data);
170};
171
172std::ostream& operator<<(std::ostream& s, const logout_response& v);
173
174}
175
176#endif
Request to authenticate a user.
Definition login_protocol.hpp:37
std::vector< std::byte > serialize() const
Serialize request to bytes.
Definition login_protocol.cpp:35
static std::expected< login_request, comms::messaging::error_code > deserialize(std::span< const std::byte > data)
Deserialize request from bytes.
Definition login_protocol.cpp:43
Response containing authentication result and account information.
Definition login_protocol.hpp:64
std::vector< std::byte > serialize() const
Serialize response to bytes.
Definition login_protocol.cpp:63
static std::expected< login_response, comms::messaging::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:102
Response containing all login info records.
Definition login_protocol.hpp:113
Request to logout the current session.
Definition login_protocol.hpp:131
std::vector< std::byte > serialize() const
Serialize request to bytes.
Definition login_protocol.cpp:220
static std::expected< logout_request, comms::messaging::error_code > deserialize(std::span< const std::byte > data)
Deserialize request from bytes.
Definition login_protocol.cpp:226
Response indicating logout result.
Definition login_protocol.hpp:151
std::vector< std::byte > serialize() const
Serialize response to bytes.
Definition login_protocol.cpp:237
static std::expected< logout_response, comms::messaging::error_code > deserialize(std::span< const std::byte > data)
Deserialize response from bytes.
Definition login_protocol.cpp:245