From 6de195c1f24a398d5f9ca0a3115b574117ff5be7 Mon Sep 17 00:00:00 2001 From: "NG (Graham)" Date: Tue, 24 Mar 2026 17:19:18 -0400 Subject: [PATCH] Add config flag to disable registration --- rc_auth/src/main.rs | 6 +++- rc_auth/src/robocraft/registration.rs | 45 +++++++++++++++++++----- rc_core/src/persist/config/cubes_json.rs | 1 + rc_core/src/persist/config/traits.rs | 1 + rc_core/src/persist/settings.rs | 3 ++ 5 files changed, 46 insertions(+), 10 deletions(-) diff --git a/rc_auth/src/main.rs b/rc_auth/src/main.rs index 8d34f8f..7b623a4 100644 --- a/rc_auth/src/main.rs +++ b/rc_auth/src/main.rs @@ -20,8 +20,9 @@ async fn main() -> std::io::Result<()> { env_logger::init(); let cli_args = cli::CliArgs::get(); + let conf = oj_rc_core::ConfigImpl::load(&cli_args.assets_robocraft)?; + if cli_args.validate { - let conf = oj_rc_core::ConfigImpl::load(cli_args.assets_robocraft)?; let res = if conf.self_validate(&cli_args.data_robocraft) { log::info!("Config validated successfully (exit success)"); Ok(()) @@ -31,6 +32,8 @@ async fn main() -> std::io::Result<()> { return res; } + let server_settings = actix_web::web::Data::new(>::server_config(&conf)); + let cli_args2 = actix_web::web::Data::new(cli_args.clone()); let rc_preloaded = actix_web::web::Data::new(cli_args.clone().preloaded().await); let internal_auth = actix_web::web::Data::new(crate::robocraft::intercom::IntercomAuth::new(&cli_args.data_robocraft)?); @@ -61,6 +64,7 @@ async fn main() -> std::io::Result<()> { .app_data(internal_auth.clone()) .app_data(user_registry.clone()) .app_data(handlebars_ref.clone()) + .app_data(server_settings.clone()) .service(index) .service(robocraft::registration::form_submit) .service(robocraft::registration::form_load) diff --git a/rc_auth/src/robocraft/registration.rs b/rc_auth/src/robocraft/registration.rs index 1263baa..e70149a 100644 --- a/rc_auth/src/robocraft/registration.rs +++ b/rc_auth/src/robocraft/registration.rs @@ -27,6 +27,7 @@ struct Context { error: Option, version: String, source_url: String, + is_registration_allowed: bool, } #[derive(Serialize)] @@ -60,6 +61,7 @@ fn registration_ok(form: RegisterForm, renderer: &handlebars::Handlebars<'_>) -> error: None, version: version_string(), source_url: env!("CARGO_PKG_REPOSITORY").to_owned(), + is_registration_allowed: true, }).unwrap(); Html::new(rendered) } @@ -70,12 +72,27 @@ fn registration_err(form: RegisterForm, error: String , renderer: &handlebars::H error: Some(error), version: version_string(), source_url: env!("CARGO_PKG_REPOSITORY").to_owned(), + is_registration_allowed: true, + }).unwrap(); + Html::new(rendered) +} + +fn registration_disabled(form: RegisterForm, renderer: &handlebars::Handlebars<'_>) -> Html { + let rendered = renderer.render(FORM_NAME, &Context { + form, + error: Some("Registration not allowed".to_owned()), + version: version_string(), + source_url: env!("CARGO_PKG_REPOSITORY").to_owned(), + is_registration_allowed: false, }).unwrap(); Html::new(rendered) } #[post("/register")] -pub async fn form_submit(form: Form, config: Data, handlebars_ref: Data>) -> Result { +pub async fn form_submit(form: Form, config: Data, handlebars_ref: Data>, server_conf: Data) -> Result { + if !server_conf.allow_signup { + return Ok(registration_disabled(form.into_inner(), &handlebars_ref)); + } // password confirmation validation if form.password != form.password_c { return Ok(registration_err(form.into_inner(), "Passwords do not match".to_owned(), &handlebars_ref)); @@ -180,14 +197,24 @@ pub async fn form_submit(form: Form, config: Data } #[get("/register")] -pub async fn form_load(handlebars_ref: Data>) -> Html { - registration_ok(RegisterForm { - display_name: "".to_owned(), - password: "".to_owned(), - password_c: "".to_owned(), - email: None, - steam_id: None, - }, &handlebars_ref) +pub async fn form_load(handlebars_ref: Data>, server_conf: Data) -> Html { + if server_conf.allow_signup { + registration_ok(RegisterForm { + display_name: "".to_owned(), + password: "".to_owned(), + password_c: "".to_owned(), + email: None, + steam_id: None, + }, &handlebars_ref) + } else { + registration_disabled(RegisterForm { + display_name: "".to_owned(), + password: "".to_owned(), + password_c: "".to_owned(), + email: None, + steam_id: None, + }, &handlebars_ref) + } } async fn favicon_impl(config: Data) -> impl Responder { diff --git a/rc_core/src/persist/config/cubes_json.rs b/rc_core/src/persist/config/cubes_json.rs index 28fb35b..9a13f13 100644 --- a/rc_core/src/persist/config/cubes_json.rs +++ b/rc_core/src/persist/config/cubes_json.rs @@ -293,6 +293,7 @@ impl super::ConfigProvider for CubeConfig { super::ServerConfig { database: self.settings.server.database.clone(), auto_signup: self.settings.server.auto_signup, + allow_signup: self.settings.server.allow_signup, queue_mode: super::QueueChangeMode::from_persist(self.settings.server.queue_mode.clone()), domain: self.settings.server.domain.to_owned(), cdn_url: self.settings.server.cdn_url.trim_end_matches('/').to_owned(), diff --git a/rc_core/src/persist/config/traits.rs b/rc_core/src/persist/config/traits.rs index 24bedab..9fc066f 100644 --- a/rc_core/src/persist/config/traits.rs +++ b/rc_core/src/persist/config/traits.rs @@ -92,6 +92,7 @@ pub struct TypedDevMessage { pub struct ServerConfig { pub database: String, pub auto_signup: bool, + pub allow_signup: bool, pub queue_mode: QueueChangeMode, pub domain: String, pub cdn_url: String, diff --git a/rc_core/src/persist/settings.rs b/rc_core/src/persist/settings.rs index 320594f..5361489 100644 --- a/rc_core/src/persist/settings.rs +++ b/rc_core/src/persist/settings.rs @@ -83,6 +83,8 @@ pub struct ServerSettings { pub database: String, #[serde(default)] pub auto_signup: bool, + #[serde(default = "default_true")] + pub allow_signup: bool, #[serde(default)] pub queue_mode: QueueMode, #[serde(default = "default_domain_root")] @@ -123,6 +125,7 @@ fn default_server_conf() -> ServerSettings { ServerSettings { database: default_db_conn(), auto_signup: false, + allow_signup: true, queue_mode: QueueMode::Notify, domain: default_domain_root(), cdn_url: default_cdn_root_url(),