ruma_client_api/account/
request_password_change_token_via_email.rs

1//! `POST /_matrix/client/*/account/password/email/requestToken`
2//!
3//! Request that a password change token is sent to the given email address.
4
5pub mod v3 {
6    //! `/v3/` ([spec])
7    //!
8    //! [spec]: https://spec.matrix.org/latest/client-server-api/#post_matrixclientv3accountpasswordemailrequesttoken
9
10    use js_int::UInt;
11    use ruma_common::{
12        api::{request, response, Metadata},
13        metadata, OwnedClientSecret, OwnedSessionId,
14    };
15
16    use crate::account::IdentityServerInfo;
17
18    const METADATA: Metadata = metadata! {
19        method: POST,
20        rate_limited: false,
21        authentication: None,
22        history: {
23            1.0 => "/_matrix/client/r0/account/password/email/requestToken",
24            1.1 => "/_matrix/client/v3/account/password/email/requestToken",
25        }
26    };
27
28    /// Request type for the `request_password_change_token_via_email` endpoint.
29    #[request(error = crate::Error)]
30    pub struct Request {
31        /// Client-generated secret string used to protect this session.
32        pub client_secret: OwnedClientSecret,
33
34        /// The email address.
35        pub email: String,
36
37        /// Used to distinguish protocol level retries from requests to re-send the email.
38        pub send_attempt: UInt,
39
40        /// Return URL for identity server to redirect the client back to.
41        #[serde(skip_serializing_if = "Option::is_none")]
42        pub next_link: Option<String>,
43
44        /// Optional identity server hostname and access token.
45        #[serde(flatten, skip_serializing_if = "Option::is_none")]
46        #[deprecated = "Since Matrix Client-Server API r0.6.0."]
47        pub identity_server_info: Option<IdentityServerInfo>,
48    }
49
50    /// Response type for the `request_password_change_token_via_email` endpoint.
51    #[response(error = crate::Error)]
52    pub struct Response {
53        /// The session identifier given by the identity server.
54        pub sid: OwnedSessionId,
55
56        /// URL to submit validation token to.
57        ///
58        /// If omitted, verification happens without client.
59        ///
60        /// If you activate the `compat-empty-string-null` feature, this field being an empty
61        /// string in JSON will result in `None` here during deserialization.
62        #[serde(skip_serializing_if = "Option::is_none")]
63        #[cfg_attr(
64            feature = "compat-empty-string-null",
65            serde(default, deserialize_with = "ruma_common::serde::empty_string_as_none")
66        )]
67        pub submit_url: Option<String>,
68    }
69
70    impl Request {
71        /// Creates a new `Request` with the given client secret, email address and send-attempt
72        /// counter.
73        #[allow(deprecated)]
74        pub fn new(client_secret: OwnedClientSecret, email: String, send_attempt: UInt) -> Self {
75            Self { client_secret, email, send_attempt, next_link: None, identity_server_info: None }
76        }
77    }
78
79    impl Response {
80        /// Creates a new `Response` with the given session identifier.
81        pub fn new(sid: OwnedSessionId) -> Self {
82            Self { sid, submit_url: None }
83        }
84    }
85}