1 #[cfg(feature = "full")]
2 use crate::schema::local_user;
4 newtypes::{LocalUserId, PersonId},
8 use serde::{Deserialize, Serialize};
9 use serde_with::skip_serializing_none;
10 #[cfg(feature = "full")]
12 use typed_builder::TypedBuilder;
14 #[skip_serializing_none]
15 #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
16 #[cfg_attr(feature = "full", derive(Queryable, Identifiable, TS))]
17 #[cfg_attr(feature = "full", diesel(table_name = local_user))]
18 #[cfg_attr(feature = "full", ts(export))]
20 pub struct LocalUser {
22 /// The person_id for the local user.
23 pub person_id: PersonId,
25 pub password_encrypted: String,
26 pub email: Option<String>,
27 /// Whether to show NSFW content.
30 pub default_sort_type: SortType,
31 pub default_listing_type: ListingType,
32 pub interface_language: String,
33 /// Whether to show avatars.
34 pub show_avatars: bool,
35 pub send_notifications_to_email: bool,
36 /// A validation ID used in logging out sessions.
37 pub validator_time: chrono::NaiveDateTime,
38 /// Whether to show comment / post scores.
39 pub show_scores: bool,
40 /// Whether to show bot accounts.
41 pub show_bot_accounts: bool,
42 /// Whether to show read posts.
43 pub show_read_posts: bool,
44 /// Whether to show new posts as notifications.
45 pub show_new_post_notifs: bool,
46 /// Whether their email has been verified.
47 pub email_verified: bool,
48 /// Whether their registration application has been accepted.
49 pub accepted_application: bool,
51 pub totp_2fa_secret: Option<String>,
52 /// A URL to add their 2-factor auth.
53 pub totp_2fa_url: Option<String>,
56 #[derive(Clone, TypedBuilder)]
57 #[builder(field_defaults(default))]
58 #[cfg_attr(feature = "full", derive(Insertable))]
59 #[cfg_attr(feature = "full", diesel(table_name = local_user))]
60 pub struct LocalUserInsertForm {
62 pub person_id: PersonId,
64 pub password_encrypted: String,
65 pub email: Option<String>,
66 pub show_nsfw: Option<bool>,
67 pub theme: Option<String>,
68 pub default_sort_type: Option<SortType>,
69 pub default_listing_type: Option<ListingType>,
70 pub interface_language: Option<String>,
71 pub show_avatars: Option<bool>,
72 pub send_notifications_to_email: Option<bool>,
73 pub show_bot_accounts: Option<bool>,
74 pub show_scores: Option<bool>,
75 pub show_read_posts: Option<bool>,
76 pub show_new_post_notifs: Option<bool>,
77 pub email_verified: Option<bool>,
78 pub accepted_application: Option<bool>,
79 pub totp_2fa_secret: Option<Option<String>>,
80 pub totp_2fa_url: Option<Option<String>>,
83 #[derive(Clone, TypedBuilder)]
84 #[builder(field_defaults(default))]
85 #[cfg_attr(feature = "full", derive(AsChangeset))]
86 #[cfg_attr(feature = "full", diesel(table_name = local_user))]
87 pub struct LocalUserUpdateForm {
88 pub password_encrypted: Option<String>,
89 pub email: Option<Option<String>>,
90 pub show_nsfw: Option<bool>,
91 pub theme: Option<String>,
92 pub default_sort_type: Option<SortType>,
93 pub default_listing_type: Option<ListingType>,
94 pub interface_language: Option<String>,
95 pub show_avatars: Option<bool>,
96 pub send_notifications_to_email: Option<bool>,
97 pub show_bot_accounts: Option<bool>,
98 pub show_scores: Option<bool>,
99 pub show_read_posts: Option<bool>,
100 pub show_new_post_notifs: Option<bool>,
101 pub email_verified: Option<bool>,
102 pub accepted_application: Option<bool>,
103 pub totp_2fa_secret: Option<Option<String>>,
104 pub totp_2fa_url: Option<Option<String>>,