diff --git a/src/api/client/account/mod.rs b/src/api/client/account/mod.rs index b54ef029d..ac6a24096 100644 --- a/src/api/client/account/mod.rs +++ b/src/api/client/account/mod.rs @@ -49,39 +49,16 @@ pub(crate) async fn get_register_available_route( ClientIp(client): ClientIp, body: Ruma, ) -> Result { - // Validate user id - let user_id = - match UserId::parse_with_server_name(&body.username, services.globals.server_name()) { - | Ok(user_id) => { - if let Err(e) = user_id.validate_strict() { - return Err!(Request(InvalidUsername(debug_warn!( - "Username {} contains disallowed characters or spaces: {e}", - body.username - )))); - } - - user_id - }, - | Err(e) => { - return Err!(Request(InvalidUsername(debug_warn!( - "Username {} is not valid: {e}", - body.username - )))); - }, - }; - - // Check if username is creative enough - if services.users.exists(&user_id).await { - return Err!(Request(UserInUse("User ID is not available."))); - } - - if let Some(ClientIdentity::Appservice { appservice_info, .. }) = &body.identity - && !appservice_info.is_user_match(&user_id) - { - return Err!(Request(Exclusive("Username is not in an appservice namespace."))); - } else if services.appservice.is_exclusive_user_id(&user_id).await { - return Err!(Request(Exclusive("Username is reserved by an appservice."))); - } + let _ = services + .users + .determine_registration_user_id( + Some(body.username.clone()), + None, + body.identity + .as_ref() + .and_then(ClientIdentity::appservice_info), + ) + .await?; Ok(get_username_availability::v3::Response::new(true)) } @@ -109,8 +86,7 @@ pub(crate) async fn change_password_route( ClientIp(client): ClientIp, body: Ruma, ) -> Result { - let identity = if let Some(identity) = body.identity.as_ref() - { + let identity = if let Some(identity) = body.identity.as_ref() { // A signed-in user is trying to change their password, prompt them for their // existing one diff --git a/src/api/client/account/threepid.rs b/src/api/client/account/threepid.rs index 9594a0628..abe669523 100644 --- a/src/api/client/account/threepid.rs +++ b/src/api/client/account/threepid.rs @@ -122,7 +122,12 @@ pub(crate) async fn add_3pid_route( // Require password auth to add an email let _ = services .uiaa - .authenticate_password(&body.auth, body.identity.sender_user(), body.identity.sender_device(), None) + .authenticate_password( + &body.auth, + body.identity.sender_user(), + body.identity.sender_device(), + None, + ) .await?; let email = services diff --git a/src/api/client/well_known.rs b/src/api/client/well_known.rs index e7d35ca90..749571f99 100644 --- a/src/api/client/well_known.rs +++ b/src/api/client/well_known.rs @@ -3,8 +3,7 @@ use conduwuit::{Err, Result}; use ruma::{ api::client::discovery::{ discover_homeserver::{self, HomeserverInfo}, - discover_policy_server, - discover_support, + discover_policy_server, discover_support, }, assign, }; diff --git a/src/api/router/auth.rs b/src/api/router/auth.rs index 7d4f73c64..a2f4a4ad3 100644 --- a/src/api/router/auth.rs +++ b/src/api/router/auth.rs @@ -157,7 +157,9 @@ impl CheckAuth for AccessToken { query: AuthQueryParams, route: TypeId, ) -> Result { - if let Some((sender_user, sender_device, status)) = services.users.find_from_token(&output).await { + if let Some((sender_user, sender_device, status)) = + services.users.find_from_token(&output).await + { // If the token is expired we return a soft logout if matches!(status, AccessTokenStatus::Expired) { return Err(Error::Request( diff --git a/src/service/uiaa/mod.rs b/src/service/uiaa/mod.rs index 184d7d90f..be3eb5d52 100644 --- a/src/service/uiaa/mod.rs +++ b/src/service/uiaa/mod.rs @@ -5,7 +5,6 @@ use std::{ }; use conduwuit::{Err, Error, Result, error, utils}; -use futures::future::OptionFuture; use lettre::Address; use ruma::{ DeviceId, UserId, @@ -254,8 +253,7 @@ impl Service { let session_metadata = if let Some(initiator) = initiator { let is_oauth = if let Some(device_id) = initiator.device_id { - self - .services + self.services .oauth .get_session_info_for_device(initiator.user_id, device_id) .await