chore: migrate authifier into codebase (#658)
Co-authored-by: izzy <me@insrt.uk> Signed-off-by: Zomatree <me@zomatree.live> Signed-off-by: izzy <me@insrt.uk>
This commit is contained in:
70
crates/core/models/src/v0/accounts.rs
Normal file
70
crates/core/models/src/v0/accounts.rs
Normal file
@@ -0,0 +1,70 @@
|
||||
auto_derived!(
|
||||
/// # Change Email Data
|
||||
pub struct DataChangeEmail {
|
||||
/// Valid email address
|
||||
pub email: String,
|
||||
/// Current password
|
||||
pub current_password: String,
|
||||
}
|
||||
|
||||
/// # Change Data
|
||||
pub struct DataChangePassword {
|
||||
/// New password
|
||||
pub password: String,
|
||||
/// Current password
|
||||
pub current_password: String,
|
||||
}
|
||||
|
||||
/// # Account Deletion Token
|
||||
pub struct DataAccountDeletion {
|
||||
/// Deletion token
|
||||
pub token: String,
|
||||
}
|
||||
|
||||
/// # Account Data
|
||||
pub struct DataCreateAccount {
|
||||
/// Valid email address
|
||||
pub email: String,
|
||||
/// Password
|
||||
pub password: String,
|
||||
/// Invite code
|
||||
pub invite: Option<String>,
|
||||
/// Captcha verification code
|
||||
pub captcha: Option<String>,
|
||||
}
|
||||
|
||||
pub struct AccountInfo {
|
||||
#[serde(rename = "_id")]
|
||||
pub id: String,
|
||||
pub email: String,
|
||||
}
|
||||
|
||||
/// # Password Reset
|
||||
pub struct DataPasswordReset {
|
||||
/// Reset token
|
||||
pub token: String,
|
||||
|
||||
/// New password
|
||||
pub password: String,
|
||||
|
||||
/// Whether to logout all sessions
|
||||
#[serde(default)]
|
||||
pub remove_sessions: bool,
|
||||
}
|
||||
|
||||
/// # Resend Information
|
||||
pub struct DataResendVerification {
|
||||
/// Email associated with the account
|
||||
pub email: String,
|
||||
/// Captcha verification code
|
||||
pub captcha: Option<String>,
|
||||
}
|
||||
|
||||
/// # Reset Information
|
||||
pub struct DataSendPasswordReset {
|
||||
/// Email associated with the account
|
||||
pub email: String,
|
||||
/// Captcha verification code
|
||||
pub captcha: Option<String>,
|
||||
}
|
||||
);
|
||||
68
crates/core/models/src/v0/mfa_tickets.rs
Normal file
68
crates/core/models/src/v0/mfa_tickets.rs
Normal file
@@ -0,0 +1,68 @@
|
||||
auto_derived!(
|
||||
pub struct MFATicket {
|
||||
/// Unique Id
|
||||
#[serde(rename = "_id")]
|
||||
pub id: String,
|
||||
|
||||
/// Account Id
|
||||
pub account_id: String,
|
||||
|
||||
/// Unique Token
|
||||
pub token: String,
|
||||
|
||||
/// Whether this ticket has been validated
|
||||
/// (can be used for account actions)
|
||||
pub validated: bool,
|
||||
|
||||
/// Whether this ticket is authorised
|
||||
/// (can be used to log a user in)
|
||||
pub authorised: bool,
|
||||
|
||||
/// TOTP code at time of ticket creation
|
||||
pub last_totp_code: Option<String>,
|
||||
}
|
||||
|
||||
#[serde(untagged)]
|
||||
pub enum ResponseVerify {
|
||||
NoTicket,
|
||||
WithTicket {
|
||||
/// Authorised MFA ticket, can be used to log in
|
||||
ticket: MFATicket,
|
||||
},
|
||||
}
|
||||
|
||||
/// MFA response
|
||||
#[serde(untagged)]
|
||||
pub enum MFAResponse {
|
||||
Password { password: String },
|
||||
Recovery { recovery_code: String },
|
||||
Totp { totp_code: String },
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct MultiFactorStatus {
|
||||
#[serde(skip_serializing_if = "crate::if_false", default)]
|
||||
pub email_otp: bool,
|
||||
#[serde(skip_serializing_if = "crate::if_false", default)]
|
||||
pub trusted_handover: bool,
|
||||
#[serde(skip_serializing_if = "crate::if_false", default)]
|
||||
pub email_mfa: bool,
|
||||
#[serde(skip_serializing_if = "crate::if_false", default)]
|
||||
pub totp_mfa: bool,
|
||||
#[serde(skip_serializing_if = "crate::if_false", default)]
|
||||
pub security_key_mfa: bool,
|
||||
#[serde(skip_serializing_if = "crate::if_false", default)]
|
||||
pub recovery_active: bool,
|
||||
}
|
||||
|
||||
pub enum MFAMethod {
|
||||
Password,
|
||||
Recovery,
|
||||
Totp,
|
||||
}
|
||||
|
||||
/// # Totp Secret
|
||||
pub struct ResponseTotpSecret {
|
||||
pub secret: String,
|
||||
}
|
||||
);
|
||||
@@ -14,6 +14,9 @@ mod server_members;
|
||||
mod servers;
|
||||
mod user_settings;
|
||||
mod users;
|
||||
mod accounts;
|
||||
mod mfa_tickets;
|
||||
mod sessions;
|
||||
|
||||
pub use bots::*;
|
||||
pub use channel_invites::*;
|
||||
@@ -31,3 +34,6 @@ pub use server_members::*;
|
||||
pub use servers::*;
|
||||
pub use user_settings::*;
|
||||
pub use users::*;
|
||||
pub use accounts::*;
|
||||
pub use mfa_tickets::*;
|
||||
pub use sessions::*;
|
||||
88
crates/core/models/src/v0/sessions.rs
Normal file
88
crates/core/models/src/v0/sessions.rs
Normal file
@@ -0,0 +1,88 @@
|
||||
use iso8601_timestamp::Timestamp;
|
||||
|
||||
use crate::v0::{MFAMethod, MFAResponse};
|
||||
|
||||
auto_derived!(
|
||||
pub struct Session {
|
||||
/// Unique Id
|
||||
#[serde(rename = "_id")]
|
||||
pub id: String,
|
||||
|
||||
/// User Id
|
||||
pub user_id: String,
|
||||
|
||||
/// Session token
|
||||
pub token: String,
|
||||
|
||||
/// Display name
|
||||
pub name: String,
|
||||
|
||||
/// When the session was last logged in
|
||||
pub last_seen: Timestamp,
|
||||
|
||||
/// Where the session is originating from
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub origin: Option<String>,
|
||||
|
||||
/// Web Push subscription
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub subscription: Option<WebPushSubscription>,
|
||||
}
|
||||
|
||||
/// Web Push subscription
|
||||
pub struct WebPushSubscription {
|
||||
pub endpoint: String,
|
||||
pub p256dh: String,
|
||||
pub auth: String,
|
||||
}
|
||||
|
||||
/// # Edit Data
|
||||
pub struct DataEditSession {
|
||||
/// Session friendly name
|
||||
pub friendly_name: String,
|
||||
}
|
||||
|
||||
pub struct SessionInfo {
|
||||
#[serde(rename = "_id")]
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
/// # Login Data
|
||||
#[serde(untagged)]
|
||||
pub enum DataLogin {
|
||||
Email {
|
||||
/// Email
|
||||
email: String,
|
||||
/// Password
|
||||
password: String,
|
||||
/// Friendly name used for the session
|
||||
friendly_name: Option<String>,
|
||||
},
|
||||
MFA {
|
||||
/// Unvalidated or authorised MFA ticket
|
||||
///
|
||||
/// Used to resolve the correct account
|
||||
mfa_ticket: String,
|
||||
/// Valid MFA response
|
||||
///
|
||||
/// This will take precedence over the `password` field where applicable
|
||||
mfa_response: Option<MFAResponse>,
|
||||
/// Friendly name used for the session
|
||||
friendly_name: Option<String>,
|
||||
},
|
||||
}
|
||||
|
||||
#[serde(tag = "result")]
|
||||
pub enum ResponseLogin {
|
||||
Success(Session),
|
||||
MFA {
|
||||
ticket: String,
|
||||
allowed_methods: Vec<MFAMethod>,
|
||||
},
|
||||
Disabled {
|
||||
user_id: String,
|
||||
},
|
||||
}
|
||||
|
||||
);
|
||||
Reference in New Issue
Block a user