Skip to main content

ruma_identity_service_api/association/email/
create_email_validation_session.rs

1//! `POST /_matrix/identity/*/validate/email/requestToken`
2//!
3//! Create a session for validating an email.
4
5pub mod v2 {
6    //! `/v2/` ([spec])
7    //!
8    //! [spec]: https://spec.matrix.org/v1.19/identity-service-api/#post_matrixidentityv2validateemailrequesttoken
9
10    use js_int::UInt;
11    use ruma_common::{
12        OwnedClientSecret, OwnedSessionId,
13        api::{request, response},
14        metadata,
15    };
16
17    use crate::IdentityServiceToken;
18
19    metadata! {
20        method: POST,
21        rate_limited: false,
22        authentication: IdentityServiceToken,
23        history: {
24            1.0 => "/_matrix/identity/v2/validate/email/requestToken",
25        }
26    }
27
28    /// Request type for the `create_email_validation_session` endpoint.
29    #[request]
30    pub struct Request {
31        /// A unique string generated by the client, and used to identify the validation attempt.
32        pub client_secret: OwnedClientSecret,
33
34        /// The email address to validate.
35        pub email: String,
36
37        /// The server will only send an email if the send_attempt is a number greater than the
38        /// most recent one which it has seen, scoped to that email + client_secret pair.
39        pub send_attempt: UInt,
40
41        /// When the validation is completed, the identity server will redirect the user to this
42        /// URL.
43        #[serde(skip_serializing_if = "Option::is_none")]
44        pub next_link: Option<String>,
45    }
46
47    /// Response type for the `create_email_validation_session` endpoint.
48    #[response]
49    pub struct Response {
50        /// The session ID.
51        ///
52        /// Session IDs are opaque strings generated by the identity server.
53        pub sid: OwnedSessionId,
54    }
55
56    impl Request {
57        /// Create a new `Request` with the given client secret, email ID, `send_attempt` number,
58        /// and the link to redirect to after validation.
59        pub fn new(
60            client_secret: OwnedClientSecret,
61            email: String,
62            send_attempt: UInt,
63            next_link: Option<String>,
64        ) -> Self {
65            Self { client_secret, email, send_attempt, next_link }
66        }
67    }
68
69    impl Response {
70        /// Create a new `Response` with the given session ID.
71        pub fn new(sid: OwnedSessionId) -> Self {
72            Self { sid }
73        }
74    }
75}