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