Skip to main content

tuwunel_api/client/register/
token_validity.rs

1use axum::extract::State;
2use ruma::api::client::account::check_registration_token_validity;
3use tuwunel_core::{Err, Result};
4
5use crate::Ruma;
6
7/// # `GET /_matrix/client/v1/register/m.login.registration_token/validity`
8///
9/// Checks if the provided registration token is valid at the time of checking
10///
11/// Currently does not have any ratelimiting, and this isn't very practical as
12/// there is only one registration token allowed.
13pub(crate) async fn check_registration_token_validity(
14	State(services): State<crate::State>,
15	body: Ruma<check_registration_token_validity::v1::Request>,
16) -> Result<check_registration_token_validity::v1::Response> {
17	if !services.registration_tokens.is_enabled().await {
18		return Err!(Request(Forbidden("Server does not allow token registration")));
19	}
20
21	let valid = services
22		.registration_tokens
23		.is_token_valid(&body.token)
24		.await
25		.is_ok();
26
27	Ok(check_registration_token_validity::v1::Response { valid })
28}