Use ruma-api-macros for the account endpoints.
This commit is contained in:
parent
30fbb891fd
commit
422043cf51
@ -29,4 +29,4 @@ rev = "3635fe51ac31b9ff899c70a0d1218caa8cf6a8dc"
|
|||||||
|
|
||||||
[dependencies.ruma-api-macros]
|
[dependencies.ruma-api-macros]
|
||||||
git = "https://github.com/ruma/ruma-api-macros"
|
git = "https://github.com/ruma/ruma-api-macros"
|
||||||
rev = "10f4647037c81cc3c35097f6156dd9706d38964a"
|
rev = "fc46b9a58b11d468d8b1ef51414d57d5e39f3332"
|
||||||
|
@ -17,9 +17,9 @@ extern crate serde;
|
|||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
#[macro_use] extern crate serde_derive;
|
#[macro_use] extern crate serde_derive;
|
||||||
|
|
||||||
// /// Endpoints for the r0.x.x versions of the client API specification.
|
/// Endpoints for the r0.x.x versions of the client API specification.
|
||||||
// pub mod r0 {
|
pub mod r0 {
|
||||||
// pub mod account;
|
pub mod account;
|
||||||
// pub mod alias;
|
// pub mod alias;
|
||||||
// pub mod config;
|
// pub mod config;
|
||||||
// pub mod contact;
|
// pub mod contact;
|
||||||
@ -42,6 +42,6 @@ extern crate serde_json;
|
|||||||
// pub mod tag;
|
// pub mod tag;
|
||||||
// pub mod typing;
|
// pub mod typing;
|
||||||
// pub mod voip;
|
// pub mod voip;
|
||||||
// }
|
}
|
||||||
|
|
||||||
pub mod unversioned;
|
pub mod unversioned;
|
||||||
|
@ -2,45 +2,76 @@
|
|||||||
|
|
||||||
/// [POST /_matrix/client/r0/register](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-register)
|
/// [POST /_matrix/client/r0/register](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-register)
|
||||||
pub mod register {
|
pub mod register {
|
||||||
|
use ruma_api_macros::ruma_api;
|
||||||
use ruma_identifiers::UserId;
|
use ruma_identifiers::UserId;
|
||||||
|
|
||||||
/// This API endpoint's body parameters.
|
ruma_api! {
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
metadata {
|
||||||
pub struct BodyParams {
|
description: "Register an account on this homeserver.",
|
||||||
/// If true, the server binds the email used for authentication
|
method: Method::Post,
|
||||||
/// to the Matrix ID with the ID Server.
|
name: "register",
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
path: "/_matrix/client/r0/register",
|
||||||
pub bind_email: Option<bool>,
|
rate_limited: true,
|
||||||
/// The desired password for the account.
|
requires_authentication: false,
|
||||||
///
|
}
|
||||||
/// Should only be empty for guest accounts.
|
|
||||||
// TODO: the spec says nothing about when it is actually required.
|
request {
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
/// If true, the server binds the email used for authentication
|
||||||
pub password: Option<String>,
|
/// to the Matrix ID with the ID Server.
|
||||||
/// local part of the desired Matrix ID.
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
///
|
pub bind_email: Option<bool>,
|
||||||
/// If omitted, the homeserver MUST generate a Matrix ID local part.
|
/// The desired password for the account.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
///
|
||||||
pub username: Option<String>,
|
/// Should only be empty for guest accounts.
|
||||||
/// ID of the client device.
|
// TODO: the spec says nothing about when it is actually required.
|
||||||
///
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
/// If this does not correspond to a known client device, a new device will be created.
|
pub password: Option<String>,
|
||||||
/// The server will auto-generate a device_id if this is not specified.
|
/// local part of the desired Matrix ID.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
///
|
||||||
pub device_id: Option<String>,
|
/// If omitted, the homeserver MUST generate a Matrix ID local part.
|
||||||
/// A display name to assign to the newly-created device.
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
///
|
pub username: Option<String>,
|
||||||
/// Ignored if `device_id` corresponds to a known device.
|
/// ID of the client device.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
///
|
||||||
pub initial_device_display_name: Option<String>,
|
/// If this does not correspond to a known client device, a new device will be created.
|
||||||
/// Additional authentication information for the user-interactive authentication API.
|
/// The server will auto-generate a device_id if this is not specified.
|
||||||
///
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
/// Note that this information is not used to define how the registered user should be
|
pub device_id: Option<String>,
|
||||||
/// authenticated, but is instead used to authenticate the register call itself.
|
/// A display name to assign to the newly-created device.
|
||||||
/// It should be left empty, or omitted, unless an earlier call returned an response
|
///
|
||||||
/// with status code 401.
|
/// Ignored if `device_id` corresponds to a known device.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub auth: Option<AuthenticationData>
|
pub initial_device_display_name: Option<String>,
|
||||||
|
/// Additional authentication information for the user-interactive authentication API.
|
||||||
|
///
|
||||||
|
/// Note that this information is not used to define how the registered user should be
|
||||||
|
/// authenticated, but is instead used to authenticate the register call itself.
|
||||||
|
/// It should be left empty, or omitted, unless an earlier call returned an response
|
||||||
|
/// with status code 401.
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub auth: Option<AuthenticationData>,
|
||||||
|
/// Kind of account to register
|
||||||
|
///
|
||||||
|
/// Defaults to `User` if ommited.
|
||||||
|
#[ruma_api(query)]
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub kind: Option<RegistrationKind>,
|
||||||
|
}
|
||||||
|
|
||||||
|
response {
|
||||||
|
/// An access token for the account.
|
||||||
|
///
|
||||||
|
/// This access token can then be used to authorize other requests.
|
||||||
|
pub access_token: String,
|
||||||
|
/// The hostname of the homeserver on which the account has been registered.
|
||||||
|
pub home_server: String,
|
||||||
|
/// The fully-qualified Matrix ID that has been registered.
|
||||||
|
pub user_id: UserId,
|
||||||
|
/// ID of the registered device.
|
||||||
|
///
|
||||||
|
/// Will be the same as the corresponding parameter in the request, if one was specified.
|
||||||
|
pub device_id: String,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Additional authentication information for the user-interactive authentication API.
|
/// Additional authentication information for the user-interactive authentication API.
|
||||||
@ -53,20 +84,6 @@ pub mod register {
|
|||||||
session: Option<String>
|
session: Option<String>
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Details about this API endpoint.
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
|
||||||
pub struct Endpoint;
|
|
||||||
|
|
||||||
/// This API endpoint's query string parameters.
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
||||||
pub struct QueryParams {
|
|
||||||
/// Kind of account to register
|
|
||||||
///
|
|
||||||
/// Defaults to `User` if ommited.
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub kind: Option<RegistrationKind>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The kind of account being registered.
|
/// The kind of account being registered.
|
||||||
#[derive(Copy, Clone, Debug, Deserialize, Serialize)]
|
#[derive(Copy, Clone, Debug, Deserialize, Serialize)]
|
||||||
pub enum RegistrationKind {
|
pub enum RegistrationKind {
|
||||||
@ -79,256 +96,110 @@ pub mod register {
|
|||||||
#[serde(rename="user")]
|
#[serde(rename="user")]
|
||||||
User,
|
User,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This API endpoint's response.
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
||||||
pub struct Response {
|
|
||||||
/// An access token for the account.
|
|
||||||
///
|
|
||||||
/// This access token can then be used to authorize other requests.
|
|
||||||
pub access_token: String,
|
|
||||||
/// The hostname of the homeserver on which the account has been registered.
|
|
||||||
pub home_server: String,
|
|
||||||
/// The fully-qualified Matrix ID that has been registered.
|
|
||||||
pub user_id: UserId,
|
|
||||||
/// ID of the registered device.
|
|
||||||
///
|
|
||||||
/// Will be the same as the corresponding parameter in the request, if one was specified.
|
|
||||||
pub device_id: String
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ::Endpoint for Endpoint {
|
|
||||||
type BodyParams = BodyParams;
|
|
||||||
type PathParams = ();
|
|
||||||
type QueryParams = QueryParams;
|
|
||||||
type Response = Response;
|
|
||||||
|
|
||||||
fn method() -> ::Method {
|
|
||||||
::Method::Post
|
|
||||||
}
|
|
||||||
|
|
||||||
fn request_path(_params: Self::PathParams) -> String {
|
|
||||||
Self::router_path().to_string()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn router_path() -> &'static str {
|
|
||||||
"/_matrix/client/r0/register"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn name() -> &'static str {
|
|
||||||
"register"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn description() -> &'static str {
|
|
||||||
"Register an account on this homeserver."
|
|
||||||
}
|
|
||||||
|
|
||||||
fn requires_authentication() -> bool {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rate_limited() -> bool {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// [POST /_matrix/client/r0/account/password/email/requestToken](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-password-email-requesttoken)
|
/// [POST /_matrix/client/r0/account/password/email/requestToken](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-password-email-requesttoken)
|
||||||
pub mod request_password_change_token {
|
pub mod request_password_change_token {
|
||||||
// TODO: according to the spec, this does not has any params
|
use ruma_api_macros::ruma_api;
|
||||||
// probably the spec's fault, as this would not make any sense.
|
|
||||||
// But the BodyParams here are probably wrong
|
|
||||||
/// This API endpoint's body parameters.
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
||||||
pub struct BodyParams {
|
|
||||||
pub client_secret: String,
|
|
||||||
pub email: String,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub id_server: Option<String>,
|
|
||||||
pub send_attempt: u64,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Details about this API endpoint.
|
ruma_api! {
|
||||||
#[derive(Clone, Copy, Debug)]
|
metadata {
|
||||||
pub struct Endpoint;
|
description: "Request that a password change token is sent to the given email address.",
|
||||||
|
method: Method::Post,
|
||||||
impl ::Endpoint for Endpoint {
|
name: "request_password_change_token",
|
||||||
type BodyParams = BodyParams;
|
path: "/_matrix/client/r0/account/password/email/requestToken",
|
||||||
type PathParams = ();
|
rate_limited: false,
|
||||||
type QueryParams = ();
|
requires_authentication: false,
|
||||||
type Response = ();
|
|
||||||
|
|
||||||
fn method() -> ::Method {
|
|
||||||
::Method::Post
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn request_path(_params: Self::PathParams) -> String {
|
request {
|
||||||
Self::router_path().to_string()
|
/// TODO: This parameter is not documented in the spec.
|
||||||
|
pub client_secret: String,
|
||||||
|
/// TODO: This parameter is not documented in the spec.
|
||||||
|
pub email: String,
|
||||||
|
/// TODO: This parameter is not documented in the spec.
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub id_server: Option<String>,
|
||||||
|
/// TODO: This parameter is not documented in the spec.
|
||||||
|
pub send_attempt: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn router_path() -> &'static str {
|
response {}
|
||||||
"/_matrix/client/r0/account/password/email/requestToken"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn name() -> &'static str {
|
|
||||||
"request_password_change_token"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn description() -> &'static str {
|
|
||||||
"Request that a password change token is sent to the given email address."
|
|
||||||
}
|
|
||||||
|
|
||||||
fn requires_authentication() -> bool {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rate_limited() -> bool {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// [POST /_matrix/client/r0/account/deactivate](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-deactivate)
|
/// [POST /_matrix/client/r0/account/deactivate](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-deactivate)
|
||||||
pub mod deactivate {
|
pub mod deactivate {
|
||||||
/// Details about this API endpoint.
|
// TODO: missing request parameters
|
||||||
#[derive(Clone, Copy, Debug)]
|
|
||||||
pub struct Endpoint;
|
|
||||||
|
|
||||||
// TODO: missing BodyParams
|
use ruma_api_macros::ruma_api;
|
||||||
|
|
||||||
impl ::Endpoint for Endpoint {
|
ruma_api! {
|
||||||
type BodyParams = ();
|
metadata {
|
||||||
type PathParams = ();
|
description: "Deactivate the current user's account.",
|
||||||
type QueryParams = ();
|
method: Method::Post,
|
||||||
type Response = ();
|
name: "deactivate",
|
||||||
|
path: "/_matrix/client/r0/account/deactivate",
|
||||||
fn method() -> ::Method {
|
rate_limited: true,
|
||||||
::Method::Post
|
requires_authentication: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn request_path(_params: Self::PathParams) -> String {
|
request {}
|
||||||
Self::router_path().to_string()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn router_path() -> &'static str {
|
response {}
|
||||||
"/_matrix/client/r0/account/deactivate"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn name() -> &'static str {
|
|
||||||
"deactivate"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn description() -> &'static str {
|
|
||||||
"Deactivate the current user's account."
|
|
||||||
}
|
|
||||||
|
|
||||||
fn requires_authentication() -> bool {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rate_limited() -> bool {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// [POST /_matrix/client/r0/account/password](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-password)
|
/// [POST /_matrix/client/r0/account/password](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-account-password)
|
||||||
pub mod change_password {
|
pub mod change_password {
|
||||||
/// This API endpoint's body parameters.
|
use ruma_api_macros::ruma_api;
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
||||||
pub struct BodyParams {
|
|
||||||
pub new_password: String,
|
|
||||||
// TODO: missing `auth` field
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Details about this API endpoint.
|
ruma_api! {
|
||||||
#[derive(Clone, Copy, Debug)]
|
metadata {
|
||||||
pub struct Endpoint;
|
description: "Change the password of the current user's account.",
|
||||||
|
method: Method::Post,
|
||||||
impl ::Endpoint for Endpoint {
|
name: "change_password",
|
||||||
type BodyParams = BodyParams;
|
path: "/_matrix/client/r0/account/password",
|
||||||
type PathParams = ();
|
rate_limited: true,
|
||||||
type QueryParams = ();
|
requires_authentication: true,
|
||||||
type Response = ();
|
|
||||||
|
|
||||||
fn method() -> ::Method {
|
|
||||||
::Method::Post
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn request_path(_params: Self::PathParams) -> String {
|
request {
|
||||||
Self::router_path().to_string()
|
/// The new password for the account.
|
||||||
|
pub new_password: String,
|
||||||
|
// TODO: missing `auth` field
|
||||||
}
|
}
|
||||||
|
|
||||||
fn router_path() -> &'static str {
|
response {}
|
||||||
"/_matrix/client/r0/account/password"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn name() -> &'static str {
|
|
||||||
"change_password"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn description() -> &'static str {
|
|
||||||
"Change the password of the current user's account."
|
|
||||||
}
|
|
||||||
|
|
||||||
fn requires_authentication() -> bool {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rate_limited() -> bool {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// [POST /_matrix/client/r0/register/email/requestToken](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-register-email-requesttoken)
|
/// [POST /_matrix/client/r0/register/email/requestToken](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-register-email-requesttoken)
|
||||||
pub mod request_register_token {
|
pub mod request_register_token {
|
||||||
/// This API endpoint's body parameters.
|
use ruma_api_macros::ruma_api;
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
||||||
pub struct BodyParams {
|
|
||||||
pub client_secret: String,
|
|
||||||
pub email: String,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub id_server: Option<String>,
|
|
||||||
pub send_attempt: u64,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Details about this API endpoint.
|
ruma_api! {
|
||||||
#[derive(Clone, Copy, Debug)]
|
metadata {
|
||||||
pub struct Endpoint;
|
description: "Request a register token with a 3rd party email.",
|
||||||
|
method: Method::Post,
|
||||||
impl ::Endpoint for Endpoint {
|
name: "request_register_token",
|
||||||
type BodyParams = BodyParams;
|
path: "/_matrix/client/r0/register/email/requestToken",
|
||||||
type PathParams = ();
|
rate_limited: true,
|
||||||
type QueryParams = ();
|
requires_authentication: true,
|
||||||
type Response = ();
|
|
||||||
|
|
||||||
fn method() -> ::Method {
|
|
||||||
::Method::Post
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn request_path(_params: Self::PathParams) -> String {
|
request {
|
||||||
Self::router_path().to_string()
|
/// Client-generated secret string used to protect this session.
|
||||||
|
pub client_secret: String,
|
||||||
|
/// The email address.
|
||||||
|
pub email: String,
|
||||||
|
/// The ID server to send the onward request to as a hostname with an appended colon and port number if the port is not the default.
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub id_server: Option<String>,
|
||||||
|
/// Used to distinguish protocol level retries from requests to re-send the email.
|
||||||
|
pub send_attempt: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn router_path() -> &'static str {
|
response {}
|
||||||
"/_matrix/client/r0/register/email/requestToken"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn name() -> &'static str {
|
|
||||||
"request_register_token"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn description() -> &'static str {
|
|
||||||
"Request a register token with a 3rd party email."
|
|
||||||
}
|
|
||||||
|
|
||||||
fn requires_authentication() -> bool {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rate_limited() -> bool {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user