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]
|
||||
git = "https://github.com/ruma/ruma-api-macros"
|
||||
rev = "10f4647037c81cc3c35097f6156dd9706d38964a"
|
||||
rev = "fc46b9a58b11d468d8b1ef51414d57d5e39f3332"
|
||||
|
@ -17,9 +17,9 @@ extern crate serde;
|
||||
extern crate serde_json;
|
||||
#[macro_use] extern crate serde_derive;
|
||||
|
||||
// /// Endpoints for the r0.x.x versions of the client API specification.
|
||||
// pub mod r0 {
|
||||
// pub mod account;
|
||||
/// Endpoints for the r0.x.x versions of the client API specification.
|
||||
pub mod r0 {
|
||||
pub mod account;
|
||||
// pub mod alias;
|
||||
// pub mod config;
|
||||
// pub mod contact;
|
||||
@ -42,6 +42,6 @@ extern crate serde_json;
|
||||
// pub mod tag;
|
||||
// pub mod typing;
|
||||
// pub mod voip;
|
||||
// }
|
||||
}
|
||||
|
||||
pub mod unversioned;
|
||||
|
@ -2,11 +2,20 @@
|
||||
|
||||
/// [POST /_matrix/client/r0/register](https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-register)
|
||||
pub mod register {
|
||||
use ruma_api_macros::ruma_api;
|
||||
use ruma_identifiers::UserId;
|
||||
|
||||
/// This API endpoint's body parameters.
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct BodyParams {
|
||||
ruma_api! {
|
||||
metadata {
|
||||
description: "Register an account on this homeserver.",
|
||||
method: Method::Post,
|
||||
name: "register",
|
||||
path: "/_matrix/client/r0/register",
|
||||
rate_limited: true,
|
||||
requires_authentication: false,
|
||||
}
|
||||
|
||||
request {
|
||||
/// If true, the server binds the email used for authentication
|
||||
/// to the Matrix ID with the ID Server.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
@ -40,7 +49,29 @@ pub mod register {
|
||||
/// 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>
|
||||
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.
|
||||
@ -53,20 +84,6 @@ pub mod register {
|
||||
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.
|
||||
#[derive(Copy, Clone, Debug, Deserialize, Serialize)]
|
||||
pub enum RegistrationKind {
|
||||
@ -79,256 +96,110 @@ pub mod register {
|
||||
#[serde(rename="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)
|
||||
pub mod request_password_change_token {
|
||||
// TODO: according to the spec, this does not has any params
|
||||
// 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 {
|
||||
use ruma_api_macros::ruma_api;
|
||||
|
||||
ruma_api! {
|
||||
metadata {
|
||||
description: "Request that a password change token is sent to the given email address.",
|
||||
method: Method::Post,
|
||||
name: "request_password_change_token",
|
||||
path: "/_matrix/client/r0/account/password/email/requestToken",
|
||||
rate_limited: false,
|
||||
requires_authentication: false,
|
||||
}
|
||||
|
||||
request {
|
||||
/// 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,
|
||||
}
|
||||
|
||||
/// Details about this API endpoint.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct Endpoint;
|
||||
|
||||
impl ::Endpoint for Endpoint {
|
||||
type BodyParams = BodyParams;
|
||||
type PathParams = ();
|
||||
type QueryParams = ();
|
||||
type 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/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
|
||||
}
|
||||
response {}
|
||||
}
|
||||
}
|
||||
|
||||
/// [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 {
|
||||
/// Details about this API endpoint.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct Endpoint;
|
||||
// TODO: missing request parameters
|
||||
|
||||
// TODO: missing BodyParams
|
||||
use ruma_api_macros::ruma_api;
|
||||
|
||||
impl ::Endpoint for Endpoint {
|
||||
type BodyParams = ();
|
||||
type PathParams = ();
|
||||
type QueryParams = ();
|
||||
type Response = ();
|
||||
|
||||
fn method() -> ::Method {
|
||||
::Method::Post
|
||||
ruma_api! {
|
||||
metadata {
|
||||
description: "Deactivate the current user's account.",
|
||||
method: Method::Post,
|
||||
name: "deactivate",
|
||||
path: "/_matrix/client/r0/account/deactivate",
|
||||
rate_limited: true,
|
||||
requires_authentication: true,
|
||||
}
|
||||
|
||||
fn request_path(_params: Self::PathParams) -> String {
|
||||
Self::router_path().to_string()
|
||||
}
|
||||
request {}
|
||||
|
||||
fn router_path() -> &'static str {
|
||||
"/_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
|
||||
}
|
||||
response {}
|
||||
}
|
||||
}
|
||||
|
||||
/// [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 {
|
||||
/// This API endpoint's body parameters.
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct BodyParams {
|
||||
use ruma_api_macros::ruma_api;
|
||||
|
||||
ruma_api! {
|
||||
metadata {
|
||||
description: "Change the password of the current user's account.",
|
||||
method: Method::Post,
|
||||
name: "change_password",
|
||||
path: "/_matrix/client/r0/account/password",
|
||||
rate_limited: true,
|
||||
requires_authentication: true,
|
||||
}
|
||||
|
||||
request {
|
||||
/// The new password for the account.
|
||||
pub new_password: String,
|
||||
// TODO: missing `auth` field
|
||||
}
|
||||
|
||||
/// Details about this API endpoint.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct Endpoint;
|
||||
|
||||
impl ::Endpoint for Endpoint {
|
||||
type BodyParams = BodyParams;
|
||||
type PathParams = ();
|
||||
type QueryParams = ();
|
||||
type 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/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
|
||||
}
|
||||
response {}
|
||||
}
|
||||
}
|
||||
|
||||
/// [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 {
|
||||
/// This API endpoint's body parameters.
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct BodyParams {
|
||||
use ruma_api_macros::ruma_api;
|
||||
|
||||
ruma_api! {
|
||||
metadata {
|
||||
description: "Request a register token with a 3rd party email.",
|
||||
method: Method::Post,
|
||||
name: "request_register_token",
|
||||
path: "/_matrix/client/r0/register/email/requestToken",
|
||||
rate_limited: true,
|
||||
requires_authentication: true,
|
||||
}
|
||||
|
||||
request {
|
||||
/// 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,
|
||||
}
|
||||
|
||||
/// Details about this API endpoint.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct Endpoint;
|
||||
|
||||
impl ::Endpoint for Endpoint {
|
||||
type BodyParams = BodyParams;
|
||||
type PathParams = ();
|
||||
type QueryParams = ();
|
||||
type 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/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
|
||||
}
|
||||
response {}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user