mirror of
https://git.ngram.ca/OpenJam/rc-servers
synced 2026-08-23 23:08:52 +00:00
Add config flag to disable registration
This commit is contained in:
@@ -20,8 +20,9 @@ async fn main() -> std::io::Result<()> {
|
|||||||
env_logger::init();
|
env_logger::init();
|
||||||
let cli_args = cli::CliArgs::get();
|
let cli_args = cli::CliArgs::get();
|
||||||
|
|
||||||
|
let conf = oj_rc_core::ConfigImpl::load(&cli_args.assets_robocraft)?;
|
||||||
|
|
||||||
if cli_args.validate {
|
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) {
|
let res = if conf.self_validate(&cli_args.data_robocraft) {
|
||||||
log::info!("Config validated successfully (exit success)");
|
log::info!("Config validated successfully (exit success)");
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -31,6 +32,8 @@ async fn main() -> std::io::Result<()> {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let server_settings = actix_web::web::Data::new(<oj_rc_core::ConfigImpl as oj_rc_core::ConfigProvider<()>>::server_config(&conf));
|
||||||
|
|
||||||
let cli_args2 = actix_web::web::Data::new(cli_args.clone());
|
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 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)?);
|
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(internal_auth.clone())
|
||||||
.app_data(user_registry.clone())
|
.app_data(user_registry.clone())
|
||||||
.app_data(handlebars_ref.clone())
|
.app_data(handlebars_ref.clone())
|
||||||
|
.app_data(server_settings.clone())
|
||||||
.service(index)
|
.service(index)
|
||||||
.service(robocraft::registration::form_submit)
|
.service(robocraft::registration::form_submit)
|
||||||
.service(robocraft::registration::form_load)
|
.service(robocraft::registration::form_load)
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ struct Context {
|
|||||||
error: Option<String>,
|
error: Option<String>,
|
||||||
version: String,
|
version: String,
|
||||||
source_url: String,
|
source_url: String,
|
||||||
|
is_registration_allowed: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
@@ -60,6 +61,7 @@ fn registration_ok(form: RegisterForm, renderer: &handlebars::Handlebars<'_>) ->
|
|||||||
error: None,
|
error: None,
|
||||||
version: version_string(),
|
version: version_string(),
|
||||||
source_url: env!("CARGO_PKG_REPOSITORY").to_owned(),
|
source_url: env!("CARGO_PKG_REPOSITORY").to_owned(),
|
||||||
|
is_registration_allowed: true,
|
||||||
}).unwrap();
|
}).unwrap();
|
||||||
Html::new(rendered)
|
Html::new(rendered)
|
||||||
}
|
}
|
||||||
@@ -70,12 +72,27 @@ fn registration_err(form: RegisterForm, error: String , renderer: &handlebars::H
|
|||||||
error: Some(error),
|
error: Some(error),
|
||||||
version: version_string(),
|
version: version_string(),
|
||||||
source_url: env!("CARGO_PKG_REPOSITORY").to_owned(),
|
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();
|
}).unwrap();
|
||||||
Html::new(rendered)
|
Html::new(rendered)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/register")]
|
#[post("/register")]
|
||||||
pub async fn form_submit(form: Form<RegisterForm>, config: Data<super::RcConfig>, handlebars_ref: Data<handlebars::Handlebars<'_>>) -> Result<Html, actix_web::error::Error> {
|
pub async fn form_submit(form: Form<RegisterForm>, config: Data<super::RcConfig>, handlebars_ref: Data<handlebars::Handlebars<'_>>, server_conf: Data<oj_rc_core::persist::config::ServerConfig>) -> Result<Html, actix_web::error::Error> {
|
||||||
|
if !server_conf.allow_signup {
|
||||||
|
return Ok(registration_disabled(form.into_inner(), &handlebars_ref));
|
||||||
|
}
|
||||||
// password confirmation validation
|
// password confirmation validation
|
||||||
if form.password != form.password_c {
|
if form.password != form.password_c {
|
||||||
return Ok(registration_err(form.into_inner(), "Passwords do not match".to_owned(), &handlebars_ref));
|
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<RegisterForm>, config: Data<super::RcConfig>
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[get("/register")]
|
#[get("/register")]
|
||||||
pub async fn form_load(handlebars_ref: Data<handlebars::Handlebars<'_>>) -> Html {
|
pub async fn form_load(handlebars_ref: Data<handlebars::Handlebars<'_>>, server_conf: Data<oj_rc_core::persist::config::ServerConfig>) -> Html {
|
||||||
registration_ok(RegisterForm {
|
if server_conf.allow_signup {
|
||||||
display_name: "".to_owned(),
|
registration_ok(RegisterForm {
|
||||||
password: "".to_owned(),
|
display_name: "".to_owned(),
|
||||||
password_c: "".to_owned(),
|
password: "".to_owned(),
|
||||||
email: None,
|
password_c: "".to_owned(),
|
||||||
steam_id: None,
|
email: None,
|
||||||
}, &handlebars_ref)
|
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<super::RcConfig>) -> impl Responder {
|
async fn favicon_impl(config: Data<super::RcConfig>) -> impl Responder {
|
||||||
|
|||||||
@@ -293,6 +293,7 @@ impl <C: Clone + Send> super::ConfigProvider<C> for CubeConfig {
|
|||||||
super::ServerConfig {
|
super::ServerConfig {
|
||||||
database: self.settings.server.database.clone(),
|
database: self.settings.server.database.clone(),
|
||||||
auto_signup: self.settings.server.auto_signup,
|
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()),
|
queue_mode: super::QueueChangeMode::from_persist(self.settings.server.queue_mode.clone()),
|
||||||
domain: self.settings.server.domain.to_owned(),
|
domain: self.settings.server.domain.to_owned(),
|
||||||
cdn_url: self.settings.server.cdn_url.trim_end_matches('/').to_owned(),
|
cdn_url: self.settings.server.cdn_url.trim_end_matches('/').to_owned(),
|
||||||
|
|||||||
@@ -92,6 +92,7 @@ pub struct TypedDevMessage<C> {
|
|||||||
pub struct ServerConfig {
|
pub struct ServerConfig {
|
||||||
pub database: String,
|
pub database: String,
|
||||||
pub auto_signup: bool,
|
pub auto_signup: bool,
|
||||||
|
pub allow_signup: bool,
|
||||||
pub queue_mode: QueueChangeMode,
|
pub queue_mode: QueueChangeMode,
|
||||||
pub domain: String,
|
pub domain: String,
|
||||||
pub cdn_url: String,
|
pub cdn_url: String,
|
||||||
|
|||||||
@@ -83,6 +83,8 @@ pub struct ServerSettings {
|
|||||||
pub database: String,
|
pub database: String,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub auto_signup: bool,
|
pub auto_signup: bool,
|
||||||
|
#[serde(default = "default_true")]
|
||||||
|
pub allow_signup: bool,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub queue_mode: QueueMode,
|
pub queue_mode: QueueMode,
|
||||||
#[serde(default = "default_domain_root")]
|
#[serde(default = "default_domain_root")]
|
||||||
@@ -123,6 +125,7 @@ fn default_server_conf() -> ServerSettings {
|
|||||||
ServerSettings {
|
ServerSettings {
|
||||||
database: default_db_conn(),
|
database: default_db_conn(),
|
||||||
auto_signup: false,
|
auto_signup: false,
|
||||||
|
allow_signup: true,
|
||||||
queue_mode: QueueMode::Notify,
|
queue_mode: QueueMode::Notify,
|
||||||
domain: default_domain_root(),
|
domain: default_domain_root(),
|
||||||
cdn_url: default_cdn_root_url(),
|
cdn_url: default_cdn_root_url(),
|
||||||
|
|||||||
Reference in New Issue
Block a user