diff --git a/src/admin/user/commands.rs b/src/admin/user/commands.rs index 78b0a5ba2..31460c7ce 100644 --- a/src/admin/user/commands.rs +++ b/src/admin/user/commands.rs @@ -59,7 +59,13 @@ impl crate::Context<'_> { self.services .users - .create_local_account(&user_id, Some(HashedPassword::new(password)?), None) + .create_local_account( + &user_id, + Some(HashedPassword::new(password)?), + None, + None, + None, + ) .await?; self.write_str(&format!("Created user {user_id} with password `{password}`")) diff --git a/src/api/client/account/register.rs b/src/api/client/account/register.rs index 6cc2c9ead..5a65429a0 100644 --- a/src/api/client/account/register.rs +++ b/src/api/client/account/register.rs @@ -95,7 +95,13 @@ pub(crate) async fn register_route( services .users - .create_local_account(&user_id, Some(password), identity.email) + .create_local_account( + &user_id, + Some(password), + identity.email, + Some(&client), + body.initial_device_display_name.as_deref(), + ) .await?; user_id @@ -132,26 +138,6 @@ pub(crate) async fn register_route( }; debug_info!(%user_id, ?device, "New account created via legacy registration"); - // Only log if the user wasn't registered via an appservice. - if body.identity.is_none() { - let notice = if device.is_some() - && let Some(device_name) = body.initial_device_display_name.as_ref() - { - format!( - "New user \"{user_id}\" registered on this server from IP {client} and device \ - display name \"{device_name}\" via legacy registration", - ) - } else { - format!( - "New user \"{user_id}\" registered on this server from IP {client} via legacy \ - registration." - ) - }; - info!("{notice}"); - if services.server.config.admin_room_notices { - services.admin.notice(¬ice).await; - } - } Ok(assign!(register::v3::Response::new(user_id), { access_token: token.map(DeviceToken::into_token), diff --git a/src/service/oidc/mod.rs b/src/service/oidc/mod.rs index 89769f552..831c0875b 100644 --- a/src/service/oidc/mod.rs +++ b/src/service/oidc/mod.rs @@ -367,7 +367,7 @@ impl Service { // Create a new shadow user self.services .users - .create_local_account(&user_id, None, None) + .create_local_account(&user_id, None, None, None, None) .await .map_err(|err| { error!("Failed to create a shadow user for {user_id}: {err}"); diff --git a/src/service/users/account.rs b/src/service/users/account.rs index f74c672a1..378e0de85 100644 --- a/src/service/users/account.rs +++ b/src/service/users/account.rs @@ -1,4 +1,7 @@ -use std::time::{Duration, SystemTime}; +use std::{ + net::IpAddr, + time::{Duration, SystemTime}, +}; use conduwuit::{ Err, Result, debug_error, debug_warn, err, error, info, trace, @@ -136,6 +139,8 @@ impl super::Service { user_id: &UserId, password: Option, email: Option
, + client: Option<&IpAddr>, + device_name: Option<&str>, ) -> Result<()> { self.create_shadow_account(user_id).await?; @@ -143,6 +148,22 @@ impl super::Service { self.convert_to_local_account(user_id, password).await?; } + if let Some(client) = client { + let notice = if let Some(device_name) = device_name { + format!( + "New user \"{user_id}\" registered on this server from IP {client} and \ + device display name \"{device_name}\".", + ) + } else { + format!("New user \"{user_id}\" registered on this server from IP {client}.") + }; + info!("{notice}"); + + if self.services.config.admin_room_notices { + self.services.admin.notice(¬ice).await; + } + } + // Set an initial display name { let mut displayname = user_id.localpart().to_owned(); diff --git a/src/web/pages/account/register.rs b/src/web/pages/account/register.rs index 145e22110..4f5f4f11a 100644 --- a/src/web/pages/account/register.rs +++ b/src/web/pages/account/register.rs @@ -7,7 +7,7 @@ use axum::{ routing::{get, on}, }; use conduwuit_api::client_ip::ClientIp; -use conduwuit_core::{config::TermsDocument, info, warn}; +use conduwuit_core::{config::TermsDocument, warn}; use conduwuit_service::{ mailer::messages, registration_tokens::ValidToken, @@ -527,7 +527,7 @@ async fn complete_registration( ) -> Result { services .users - .create_local_account(&user_id, Some(password_hash), email) + .create_local_account(&user_id, Some(password_hash), email, Some(client), None) .await?; if let Some(registration_token) = registration_token { @@ -536,13 +536,6 @@ async fn complete_registration( .mark_token_as_used(registration_token); } - let notice = format!("New user \"{user_id}\" registered on this server from IP {client}."); - - info!("{notice}"); - if services.server.config.admin_room_notices { - services.admin.notice(¬ice).await; - } - let user_session = UserSession { user_id, last_login: SystemTime::now() }; session_store