Skip to main content

tuwunel_api/client/admin/users/
reset_password.rs

1use axum::extract::State;
2use futures::StreamExt;
3use synapse_admin_api::users::reset_password::v1 as reset_password;
4use tuwunel_core::{Err, Result, utils::stream::automatic_width};
5
6use crate::{Ruma, client::admin::require_admin};
7
8/// # `POST /_synapse/admin/v1/reset_password/{user_id}`
9pub(crate) async fn admin_reset_password_route(
10	State(services): State<crate::State>,
11	body: Ruma<reset_password::Request>,
12) -> Result<reset_password::Response> {
13	require_admin(&services, body.sender_user()).await?;
14
15	if !services.users.exists(&body.user_id).await {
16		return Err!(Request(NotFound("User not found")));
17	}
18
19	services
20		.users
21		.set_password(&body.user_id, Some(&body.new_password))
22		.await?;
23
24	if body.logout_devices {
25		services
26			.users
27			.all_device_ids(&body.user_id)
28			.map(ToOwned::to_owned)
29			.for_each_concurrent(automatic_width(), async |device_id| {
30				services
31					.users
32					.remove_device(&body.user_id, &device_id)
33					.await;
34			})
35			.await;
36	}
37
38	Ok(reset_password::Response::new())
39}