diff options
Diffstat (limited to 'src/api/client_server/account.rs')
-rw-r--r-- | src/api/client_server/account.rs | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/src/api/client_server/account.rs b/src/api/client_server/account.rs index 7459254..4655130 100644 --- a/src/api/client_server/account.rs +++ b/src/api/client_server/account.rs @@ -74,7 +74,10 @@ pub async fn get_register_available_route( /// - Creates a new account and populates it with default account data /// - If `inhibit_login` is false: Creates a device and returns device id and access_token pub async fn register_route(body: Ruma<register::v3::Request>) -> Result<register::v3::Response> { - if !services().globals.allow_registration() && !body.from_appservice { + if !services().globals.allow_registration() + && !body.from_appservice + && services().globals.config.registration_token.is_none() + { return Err(Error::BadRequest( ErrorKind::Forbidden, "Registration has been disabled.", @@ -121,7 +124,11 @@ pub async fn register_route(body: Ruma<register::v3::Request>) -> Result<registe // UIAA let mut uiaainfo = UiaaInfo { flows: vec![AuthFlow { - stages: vec![AuthType::Dummy], + stages: if services().globals.config.registration_token.is_some() { + vec![AuthType::RegistrationToken] + } else { + vec![AuthType::Dummy] + }, }], completed: Vec::new(), params: Default::default(), @@ -129,7 +136,7 @@ pub async fn register_route(body: Ruma<register::v3::Request>) -> Result<registe auth_error: None, }; - if !body.from_appservice { + if !body.from_appservice && !is_guest { if let Some(auth) = &body.auth { let (worked, uiaainfo) = services().uiaa.try_auth( &UserId::parse_with_server_name("", services().globals.server_name()) @@ -222,11 +229,13 @@ pub async fn register_route(body: Ruma<register::v3::Request>) -> Result<registe )?; info!("New user {} registered on this server.", user_id); - services() - .admin - .send_message(RoomMessageEventContent::notice_plain(format!( - "New user {user_id} registered on this server." - ))); + if !body.from_appservice && !is_guest { + services() + .admin + .send_message(RoomMessageEventContent::notice_plain(format!( + "New user {user_id} registered on this server." + ))); + } // If this is the first real user, grant them admin privileges // Note: the server user, @conduit:servername, is generated first |