Files
stoatchat/crates/core/models/src/v0/sessions.rs
Zomatree d27917b824 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>
2026-06-21 00:50:06 +01:00

88 lines
2.1 KiB
Rust

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,
},
}
);