tuwunel_api/client/account/
change_password.rs1use axum::extract::State;
2use futures::StreamExt;
3use ruma::api::client::account::change_password;
4use tuwunel_core::{Result, info, utils::ReadyExt};
5
6use crate::{ClientIp, Ruma, router::auth_uiaa};
7
8#[tracing::instrument(skip_all, fields(%client), name = "change_password")]
26pub(crate) async fn change_password_route(
27 State(services): State<crate::State>,
28 ClientIp(client): ClientIp,
29 body: Ruma<change_password::v3::Request>,
30) -> Result<change_password::v3::Response> {
31 let ref sender_user = auth_uiaa(&services, &body).await?;
32
33 services
34 .users
35 .set_password(sender_user, Some(&body.new_password))
36 .await?;
37
38 if body.logout_devices {
39 services
41 .users
42 .all_device_ids(sender_user)
43 .ready_filter(|&id| Some(id) != body.sender_device.as_deref())
44 .for_each(|id| services.users.remove_device(sender_user, id))
45 .await;
46 }
47
48 info!("User {sender_user} changed their password.");
49
50 if services.server.config.admin_room_notices {
51 services
52 .admin
53 .notice(&format!("User {sender_user} changed their password."))
54 .await;
55 }
56
57 Ok(change_password::v3::Response {})
58}