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();
|
||||
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(<oj_rc_core::ConfigImpl as oj_rc_core::ConfigProvider<()>>::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)
|
||||
|
||||
@@ -27,6 +27,7 @@ struct Context {
|
||||
error: Option<String>,
|
||||
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<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
|
||||
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<RegisterForm>, config: Data<super::RcConfig>
|
||||
}
|
||||
|
||||
#[get("/register")]
|
||||
pub async fn form_load(handlebars_ref: Data<handlebars::Handlebars<'_>>) -> 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<handlebars::Handlebars<'_>>, server_conf: Data<oj_rc_core::persist::config::ServerConfig>) -> 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<super::RcConfig>) -> impl Responder {
|
||||
|
||||
@@ -293,6 +293,7 @@ impl <C: Clone + Send> super::ConfigProvider<C> 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(),
|
||||
|
||||
@@ -92,6 +92,7 @@ pub struct TypedDevMessage<C> {
|
||||
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,
|
||||
|
||||
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user