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