ruma_client_api/account/
request_password_change_token_via_msisdn.rs

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