1use sea_orm::entity::prelude::*;
2use serde::{Deserialize, Serialize};
3
4#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Serialize, Deserialize)]
5#[sea_orm(table_name = "yauth_users")]
6pub struct Model {
7 #[sea_orm(primary_key, auto_increment = false)]
8 pub id: Uuid,
9 #[sea_orm(unique)]
10 pub email: String,
11 pub display_name: Option<String>,
12 pub email_verified: bool,
13 pub role: String,
14 pub banned: bool,
15 pub banned_reason: Option<String>,
16 pub banned_until: Option<DateTimeWithTimeZone>,
17 pub created_at: DateTimeWithTimeZone,
18 pub updated_at: DateTimeWithTimeZone,
19}
20
21#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
22pub enum Relation {
23 #[sea_orm(has_many = "super::sessions::Entity")]
24 Sessions,
25 #[sea_orm(has_many = "super::audit_log::Entity")]
26 AuditLog,
27 #[cfg(feature = "email-password")]
28 #[sea_orm(has_one = "super::passwords::Entity")]
29 Password,
30 #[cfg(feature = "email-password")]
31 #[sea_orm(has_many = "super::email_verifications::Entity")]
32 EmailVerifications,
33 #[cfg(feature = "email-password")]
34 #[sea_orm(has_many = "super::password_resets::Entity")]
35 PasswordResets,
36 #[cfg(feature = "passkey")]
37 #[sea_orm(has_many = "super::webauthn_credentials::Entity")]
38 WebauthnCredentials,
39 #[cfg(feature = "mfa")]
40 #[sea_orm(has_one = "super::totp_secrets::Entity")]
41 TotpSecret,
42 #[cfg(feature = "mfa")]
43 #[sea_orm(has_many = "super::backup_codes::Entity")]
44 BackupCodes,
45 #[cfg(feature = "oauth")]
46 #[sea_orm(has_many = "super::oauth_accounts::Entity")]
47 OauthAccounts,
48 #[cfg(feature = "api-key")]
49 #[sea_orm(has_many = "super::api_keys::Entity")]
50 ApiKeys,
51 #[cfg(feature = "bearer")]
52 #[sea_orm(has_many = "super::refresh_tokens::Entity")]
53 RefreshTokens,
54 #[cfg(feature = "oauth2-server")]
55 #[sea_orm(has_many = "super::authorization_codes::Entity")]
56 AuthorizationCodes,
57 #[cfg(feature = "oauth2-server")]
58 #[sea_orm(has_many = "super::consents::Entity")]
59 Consents,
60}
61
62impl Related<super::sessions::Entity> for Entity {
63 fn to() -> RelationDef {
64 Relation::Sessions.def()
65 }
66}
67
68impl Related<super::audit_log::Entity> for Entity {
69 fn to() -> RelationDef {
70 Relation::AuditLog.def()
71 }
72}
73
74#[cfg(feature = "email-password")]
75impl Related<super::passwords::Entity> for Entity {
76 fn to() -> RelationDef {
77 Relation::Password.def()
78 }
79}
80
81#[cfg(feature = "email-password")]
82impl Related<super::email_verifications::Entity> for Entity {
83 fn to() -> RelationDef {
84 Relation::EmailVerifications.def()
85 }
86}
87
88#[cfg(feature = "email-password")]
89impl Related<super::password_resets::Entity> for Entity {
90 fn to() -> RelationDef {
91 Relation::PasswordResets.def()
92 }
93}
94
95#[cfg(feature = "passkey")]
96impl Related<super::webauthn_credentials::Entity> for Entity {
97 fn to() -> RelationDef {
98 Relation::WebauthnCredentials.def()
99 }
100}
101
102#[cfg(feature = "mfa")]
103impl Related<super::totp_secrets::Entity> for Entity {
104 fn to() -> RelationDef {
105 Relation::TotpSecret.def()
106 }
107}
108
109#[cfg(feature = "mfa")]
110impl Related<super::backup_codes::Entity> for Entity {
111 fn to() -> RelationDef {
112 Relation::BackupCodes.def()
113 }
114}
115
116#[cfg(feature = "oauth")]
117impl Related<super::oauth_accounts::Entity> for Entity {
118 fn to() -> RelationDef {
119 Relation::OauthAccounts.def()
120 }
121}
122
123#[cfg(feature = "api-key")]
124impl Related<super::api_keys::Entity> for Entity {
125 fn to() -> RelationDef {
126 Relation::ApiKeys.def()
127 }
128}
129
130#[cfg(feature = "bearer")]
131impl Related<super::refresh_tokens::Entity> for Entity {
132 fn to() -> RelationDef {
133 Relation::RefreshTokens.def()
134 }
135}
136
137#[cfg(feature = "oauth2-server")]
138impl Related<super::authorization_codes::Entity> for Entity {
139 fn to() -> RelationDef {
140 Relation::AuthorizationCodes.def()
141 }
142}
143
144#[cfg(feature = "oauth2-server")]
145impl Related<super::consents::Entity> for Entity {
146 fn to() -> RelationDef {
147 Relation::Consents.def()
148 }
149}
150
151impl ActiveModelBehavior for ActiveModel {}