Skip to main content

ruma_identity_service_api/association/email/
validate_email.rs

1//! `POST /_matrix/identity/*/validate/email/submitToken`
2//!
3//! Validate an email ID after creation of a session.
4
5pub mod v2 {
6    //! `/v2/` ([spec])
7    //!
8    //! [spec]: https://spec.matrix.org/v1.19/identity-service-api/#post_matrixidentityv2validateemailsubmittoken
9
10    use ruma_common::{
11        OwnedClientSecret, OwnedSessionId,
12        api::{request, response},
13        metadata,
14    };
15
16    use crate::IdentityServiceToken;
17
18    metadata! {
19        method: POST,
20        rate_limited: false,
21        authentication: IdentityServiceToken,
22        history: {
23            1.0 => "/_matrix/identity/v2/validate/email/submitToken",
24        }
25    }
26
27    /// Request type for the `validate_email` endpoint.
28    #[request]
29    pub struct Request {
30        /// The session ID, generated by the `requestToken` call.
31        pub sid: OwnedSessionId,
32
33        /// The client secret that was supplied to the `requestToken` call.
34        pub client_secret: OwnedClientSecret,
35
36        /// The token generated by the `requestToken` call and emailed to the user.
37        pub token: String,
38    }
39
40    /// Response type for the `validate_email` endpoint.
41    #[response]
42    pub struct Response {
43        /// Whether the validation was successful or not.
44        pub success: bool,
45    }
46
47    impl Request {
48        /// Create a new `Request` with the given session ID, client secret and token.
49        pub fn new(sid: OwnedSessionId, client_secret: OwnedClientSecret, token: String) -> Self {
50            Self { sid, client_secret, token }
51        }
52    }
53
54    impl Response {
55        /// Create a new `Response` with the success status.
56        pub fn new(success: bool) -> Self {
57            Self { success }
58        }
59    }
60}