cyaxon_authifier/models/
account.rs

1use iso8601_timestamp::Timestamp;
2
3use super::MultiFactorAuthentication;
4
5/// Email verification status
6#[derive(Debug, Serialize, Deserialize, Clone)]
7#[serde(tag = "status")]
8pub enum EmailVerification {
9	/// Account is verified
10	Verified,
11	/// Pending email verification
12	Pending { token: String, expiry: Timestamp },
13	/// Moving to a new email
14	Moving {
15		new_email: String,
16		token: String,
17		expiry: Timestamp,
18	},
19}
20
21/// Password reset information
22#[derive(Debug, Serialize, Deserialize, Clone)]
23pub struct PasswordReset {
24	/// Token required to change password
25	pub token: String,
26	/// Time at which this token expires
27	pub expiry: Timestamp,
28}
29
30/// Account deletion information
31#[derive(Debug, Serialize, Deserialize, Clone)]
32#[serde(tag = "status")]
33pub enum DeletionInfo {
34	/// The user must confirm deletion by email
35	WaitingForVerification { token: String, expiry: Timestamp },
36	/// The account is scheduled for deletion
37	Scheduled { after: Timestamp },
38	/// This account was deleted
39	Deleted,
40}
41
42/// Lockout information
43#[derive(Debug, Serialize, Deserialize, Clone)]
44pub struct Lockout {
45	/// Attempt counter
46	pub attempts: i32,
47	/// Time at which this lockout expires
48	pub expiry: Option<Timestamp>,
49}
50
51/// Account model
52#[derive(Debug, Serialize, Deserialize, Clone)]
53pub struct Account {
54	/// Unique Id
55	#[serde(rename = "_id")]
56	pub id: String,
57
58	/// User's email
59	pub email: String,
60
61	/// Normalized email
62	pub email_normalized: String,
63
64	/// Bcrypt hashed password
65	pub password: String,
66
67	/// Whether the account is disabled
68	#[serde(default)]
69	pub disabled: bool,
70
71	/// Email verification status
72	pub verification: EmailVerification,
73
74	/// Password reset information
75	pub password_reset: Option<PasswordReset>,
76
77	/// Account deletion information
78	pub deletion: Option<DeletionInfo>,
79
80	/// Account lockout
81	pub lockout: Option<Lockout>,
82
83	/// Multi-factor authentication information
84	pub mfa: MultiFactorAuthentication,
85}