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