]> Untitled Git - lemmy.git/blob - crates/api_common/src/person.rs
Adding TOTP / 2FA to lemmy (#2741)
[lemmy.git] / crates / api_common / src / person.rs
1 use crate::sensitive::Sensitive;
2 use lemmy_db_schema::{
3   newtypes::{CommentReplyId, CommunityId, LanguageId, PersonId, PersonMentionId},
4   CommentSortType,
5   SortType,
6 };
7 use lemmy_db_views::structs::{CommentView, PostView};
8 use lemmy_db_views_actor::structs::{
9   CommentReplyView,
10   CommunityModeratorView,
11   PersonMentionView,
12   PersonView,
13 };
14 use serde::{Deserialize, Serialize};
15
16 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
17 pub struct Login {
18   pub username_or_email: Sensitive<String>,
19   pub password: Sensitive<String>,
20   pub totp_2fa_token: Option<String>,
21 }
22
23 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
24 pub struct Register {
25   pub username: String,
26   pub password: Sensitive<String>,
27   pub password_verify: Sensitive<String>,
28   pub show_nsfw: bool,
29   /// email is mandatory if email verification is enabled on the server
30   pub email: Option<Sensitive<String>>,
31   pub captcha_uuid: Option<String>,
32   pub captcha_answer: Option<String>,
33   pub honeypot: Option<String>,
34   /// An answer is mandatory if require application is enabled on the server
35   pub answer: Option<String>,
36 }
37
38 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
39 pub struct GetCaptcha {}
40
41 #[derive(Debug, Serialize, Deserialize, Clone)]
42 pub struct GetCaptchaResponse {
43   pub ok: Option<CaptchaResponse>, // Will be None if captchas are disabled
44 }
45
46 #[derive(Debug, Serialize, Deserialize, Clone)]
47 pub struct CaptchaResponse {
48   pub png: String, // A Base64 encoded png
49   pub wav: String, // A Base64 encoded wav audio
50   pub uuid: String,
51 }
52
53 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
54 pub struct SaveUserSettings {
55   pub show_nsfw: Option<bool>,
56   pub show_scores: Option<bool>,
57   pub theme: Option<String>,
58   pub default_sort_type: Option<i16>,
59   pub default_listing_type: Option<i16>,
60   pub interface_language: Option<String>,
61   pub avatar: Option<String>,
62   pub banner: Option<String>,
63   pub display_name: Option<String>,
64   pub email: Option<Sensitive<String>>,
65   pub bio: Option<String>,
66   pub matrix_user_id: Option<String>,
67   pub show_avatars: Option<bool>,
68   pub send_notifications_to_email: Option<bool>,
69   pub bot_account: Option<bool>,
70   pub show_bot_accounts: Option<bool>,
71   pub show_read_posts: Option<bool>,
72   pub show_new_post_notifs: Option<bool>,
73   pub discussion_languages: Option<Vec<LanguageId>>,
74   /// None leaves it as is, true will generate or regenerate it, false clears it out
75   pub generate_totp_2fa: Option<bool>,
76   pub auth: Sensitive<String>,
77 }
78
79 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
80 pub struct ChangePassword {
81   pub new_password: Sensitive<String>,
82   pub new_password_verify: Sensitive<String>,
83   pub old_password: Sensitive<String>,
84   pub auth: Sensitive<String>,
85 }
86
87 #[derive(Debug, Serialize, Deserialize, Clone)]
88 pub struct LoginResponse {
89   /// This is None in response to `Register` if email verification is enabled, or the server requires registration applications.
90   pub jwt: Option<Sensitive<String>>,
91   pub registration_created: bool,
92   pub verify_email_sent: bool,
93 }
94
95 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
96 pub struct GetPersonDetails {
97   pub person_id: Option<PersonId>, // One of these two are required
98   /// Example: dessalines , or dessalines@xyz.tld
99   pub username: Option<String>,
100   pub sort: Option<SortType>,
101   pub page: Option<i64>,
102   pub limit: Option<i64>,
103   pub community_id: Option<CommunityId>,
104   pub saved_only: Option<bool>,
105   pub auth: Option<Sensitive<String>>,
106 }
107
108 #[derive(Debug, Serialize, Deserialize, Clone)]
109 pub struct GetPersonDetailsResponse {
110   pub person_view: PersonView,
111   pub comments: Vec<CommentView>,
112   pub posts: Vec<PostView>,
113   pub moderates: Vec<CommunityModeratorView>,
114 }
115
116 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
117 pub struct GetRepliesResponse {
118   pub replies: Vec<CommentReplyView>,
119 }
120
121 #[derive(Debug, Serialize, Deserialize, Clone)]
122 pub struct GetPersonMentionsResponse {
123   pub mentions: Vec<PersonMentionView>,
124 }
125
126 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
127 pub struct MarkAllAsRead {
128   pub auth: Sensitive<String>,
129 }
130
131 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
132 pub struct AddAdmin {
133   pub person_id: PersonId,
134   pub added: bool,
135   pub auth: Sensitive<String>,
136 }
137
138 #[derive(Debug, Serialize, Deserialize, Clone)]
139 pub struct AddAdminResponse {
140   pub admins: Vec<PersonView>,
141 }
142
143 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
144 pub struct BanPerson {
145   pub person_id: PersonId,
146   pub ban: bool,
147   pub remove_data: Option<bool>,
148   pub reason: Option<String>,
149   pub expires: Option<i64>,
150   pub auth: Sensitive<String>,
151 }
152
153 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
154 pub struct GetBannedPersons {
155   pub auth: String,
156 }
157
158 #[derive(Debug, Serialize, Deserialize, Clone)]
159 pub struct BannedPersonsResponse {
160   pub banned: Vec<PersonView>,
161 }
162
163 #[derive(Debug, Serialize, Deserialize, Clone)]
164 pub struct BanPersonResponse {
165   pub person_view: PersonView,
166   pub banned: bool,
167 }
168
169 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
170 pub struct BlockPerson {
171   pub person_id: PersonId,
172   pub block: bool,
173   pub auth: Sensitive<String>,
174 }
175
176 #[derive(Debug, Serialize, Deserialize, Clone)]
177 pub struct BlockPersonResponse {
178   pub person_view: PersonView,
179   pub blocked: bool,
180 }
181
182 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
183 pub struct GetReplies {
184   pub sort: Option<CommentSortType>,
185   pub page: Option<i64>,
186   pub limit: Option<i64>,
187   pub unread_only: Option<bool>,
188   pub auth: Sensitive<String>,
189 }
190
191 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
192 pub struct GetPersonMentions {
193   pub sort: Option<CommentSortType>,
194   pub page: Option<i64>,
195   pub limit: Option<i64>,
196   pub unread_only: Option<bool>,
197   pub auth: Sensitive<String>,
198 }
199
200 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
201 pub struct MarkPersonMentionAsRead {
202   pub person_mention_id: PersonMentionId,
203   pub read: bool,
204   pub auth: Sensitive<String>,
205 }
206
207 #[derive(Debug, Serialize, Deserialize, Clone)]
208 pub struct PersonMentionResponse {
209   pub person_mention_view: PersonMentionView,
210 }
211
212 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
213 pub struct MarkCommentReplyAsRead {
214   pub comment_reply_id: CommentReplyId,
215   pub read: bool,
216   pub auth: Sensitive<String>,
217 }
218
219 #[derive(Debug, Serialize, Deserialize, Clone)]
220 pub struct CommentReplyResponse {
221   pub comment_reply_view: CommentReplyView,
222 }
223
224 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
225 pub struct DeleteAccount {
226   pub password: Sensitive<String>,
227   pub auth: Sensitive<String>,
228 }
229
230 #[derive(Debug, Serialize, Deserialize, Clone)]
231 pub struct DeleteAccountResponse {}
232
233 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
234 pub struct PasswordReset {
235   pub email: Sensitive<String>,
236 }
237
238 #[derive(Debug, Serialize, Deserialize, Clone)]
239 pub struct PasswordResetResponse {}
240
241 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
242 pub struct PasswordChangeAfterReset {
243   pub token: Sensitive<String>,
244   pub password: Sensitive<String>,
245   pub password_verify: Sensitive<String>,
246 }
247
248 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
249 pub struct GetReportCount {
250   pub community_id: Option<CommunityId>,
251   pub auth: Sensitive<String>,
252 }
253
254 #[derive(Debug, Serialize, Deserialize, Clone)]
255 pub struct GetReportCountResponse {
256   pub community_id: Option<CommunityId>,
257   pub comment_reports: i64,
258   pub post_reports: i64,
259   pub private_message_reports: Option<i64>,
260 }
261
262 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
263 pub struct GetUnreadCount {
264   pub auth: Sensitive<String>,
265 }
266
267 #[derive(Debug, Serialize, Deserialize, Clone)]
268 pub struct GetUnreadCountResponse {
269   pub replies: i64,
270   pub mentions: i64,
271   pub private_messages: i64,
272 }
273
274 #[derive(Serialize, Deserialize, Clone, Default, Debug)]
275 pub struct VerifyEmail {
276   pub token: String,
277 }
278
279 #[derive(Debug, Serialize, Deserialize, Clone)]
280 pub struct VerifyEmailResponse {}