Skip to main content

proto_blue_api/generated/com/atproto/server/
resetPassword.rs

1// Generated by atproto-codegen. Do not edit.
2//! Lexicon: com.atproto.server.resetPassword
3
4use serde::{Deserialize, Serialize};
5
6/// Reset a user account password using a token.
7/// XRPC Procedure: com.atproto.server.resetPassword
8#[derive(Debug, Clone, Serialize, Deserialize)]
9#[serde(rename_all = "camelCase")]
10pub struct Input {
11    pub password: String,
12    pub token: String,
13}
14
15/// Errors a `call()` on this method can return.
16#[derive(Debug, thiserror::Error)]
17pub enum CallError {
18    #[error("ExpiredToken")]
19    ExpiredToken,
20    #[error("InvalidToken")]
21    InvalidToken,
22    #[error("{0}")]
23    Xrpc(proto_blue_xrpc::XrpcError),
24    #[error(transparent)]
25    Transport(#[from] proto_blue_xrpc::Error),
26    #[error(transparent)]
27    Json(#[from] serde_json::Error),
28}
29
30fn map_xrpc_error(err: proto_blue_xrpc::XrpcError) -> CallError {
31    match err.error.as_deref() {
32        Some("ExpiredToken") => CallError::ExpiredToken,
33        Some("InvalidToken") => CallError::InvalidToken,
34        _ => CallError::Xrpc(err),
35    }
36}
37
38/// Execute the procedure.
39pub async fn call(
40    client: &proto_blue_xrpc::XrpcClient,
41    input: &Input,
42    opts: Option<&proto_blue_xrpc::CallOptions>,
43) -> Result<serde_json::Value, CallError> {
44    let qp_ref: Option<&proto_blue_xrpc::QueryParams> = None;
45    let body = proto_blue_xrpc::XrpcBody::Json(serde_json::to_value(input)?);
46    let response = match client.procedure("com.atproto.server.resetPassword", qp_ref, Some(body), opts).await {
47        Ok(r) => r,
48        Err(proto_blue_xrpc::Error::Xrpc(x)) => return Err(map_xrpc_error(x)),
49        Err(e) => return Err(CallError::Transport(e)),
50    };
51    Ok(response.data)
52}
53
54/// Register a typed handler for this procedure on an [`XrpcServer`].
55#[cfg(feature = "server")]
56pub fn register<F, Fut>(
57server: proto_blue_xrpc::XrpcServer,
58handler: F,
59) -> proto_blue_xrpc::XrpcServer
60where
61    F: Fn(proto_blue_xrpc::HandlerContext, Option<Input>) -> Fut + Send + Sync + 'static,
62    Fut: std::future::Future<Output = Result<serde_json::Value, proto_blue_xrpc::XrpcServerError>> + Send + 'static,
63{
64    let handler = std::sync::Arc::new(handler);
65    server.procedure("com.atproto.server.resetPassword", move |ctx| {
66        let handler = handler.clone();
67        async move {
68            let input = match ctx.json_body()? {
69                Some(v) => Some(serde_json::from_value::<Input>(v).map_err(|e| proto_blue_xrpc::XrpcServerError::new(proto_blue_xrpc::ResponseType::InvalidRequest, format!("input deserialize: {e}")))?),
70                None => None,
71            };
72            let out = handler(ctx, input).await?;
73            Ok::<_, proto_blue_xrpc::XrpcServerError>(out)
74        }
75    })
76}
77