chore: Move registration notice logic

This commit is contained in:
timedout committed 2026-07-27 16:46:36 +01:00
1 parent 7fdc7f9216
commit 399005abc6
5 files changed
+39 -33

No files matched your search

+7 -1
View File
@@ -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}`"))
+7 -21
View File
@@ -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(&notice).await;
}
}
Ok(assign!(register::v3::Response::new(user_id), {
access_token: token.map(DeviceToken::into_token),
+1 -1
View File
@@ -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}");
+22 -1
View File
@@ -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<HashedPassword>,
email: Option<Address>,
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(&notice).await;
}
}
// Set an initial display name
{
let mut displayname = user_id.localpart().to_owned();
+2 -9
View File
@@ -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<Redirect> {
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(&notice).await;
}
let user_session = UserSession { user_id, last_login: SystemTime::now() };
session_store