Skip to main content

revolt_models/v0/
sessions.rs

1use iso8601_timestamp::Timestamp;
2
3use crate::v0::{MFAMethod, MFAResponse};
4
5auto_derived!(
6    pub struct Session {
7        /// Unique Id
8        #[serde(rename = "_id")]
9        pub id: String,
10
11        /// User Id
12        pub user_id: String,
13
14        /// Session token
15        pub token: String,
16
17        /// Display name
18        pub name: String,
19
20        /// When the session was last logged in
21        pub last_seen: Timestamp,
22
23        /// Where the session is originating from
24        #[serde(skip_serializing_if = "Option::is_none")]
25        pub origin: Option<String>,
26
27        /// Web Push subscription
28        #[serde(skip_serializing_if = "Option::is_none")]
29        pub subscription: Option<WebPushSubscription>,
30    }
31
32    /// Web Push subscription
33    pub struct WebPushSubscription {
34        pub endpoint: String,
35        pub p256dh: String,
36        pub auth: String,
37    }
38
39    /// # Edit Data
40    pub struct DataEditSession {
41        /// Session friendly name
42        pub friendly_name: String,
43    }
44
45    pub struct SessionInfo {
46        #[serde(rename = "_id")]
47        pub id: String,
48        pub name: String,
49    }
50
51    /// # Login Data
52    #[serde(untagged)]
53    pub enum DataLogin {
54        Email {
55            /// Email
56            email: String,
57            /// Password
58            password: String,
59            /// Friendly name used for the session
60            friendly_name: Option<String>,
61        },
62        MFA {
63            /// Unvalidated or authorised MFA ticket
64            ///
65            /// Used to resolve the correct account
66            mfa_ticket: String,
67            /// Valid MFA response
68            ///
69            /// This will take precedence over the `password` field where applicable
70            mfa_response: Option<MFAResponse>,
71            /// Friendly name used for the session
72            friendly_name: Option<String>,
73        },
74    }
75
76    #[serde(tag = "result")]
77    pub enum ResponseLogin {
78        Success(Session),
79        MFA {
80            ticket: String,
81            allowed_methods: Vec<MFAMethod>,
82        },
83        Disabled {
84            user_id: String,
85        },
86    }
87
88);