From b8cf21903ebd2c362775f47b4804020caf7ce7cd Mon Sep 17 00:00:00 2001 From: Radical Date: Mon, 26 May 2025 23:41:20 +0200 Subject: [PATCH] feat: allow disabling of registration --- src/api/v1/auth/register.rs | 4 ++++ src/config.rs | 8 ++++++++ src/error.rs | 2 ++ 3 files changed, 14 insertions(+) diff --git a/src/api/v1/auth/register.rs b/src/api/v1/auth/register.rs index 75aeb9d..66be90a 100644 --- a/src/api/v1/auth/register.rs +++ b/src/api/v1/auth/register.rs @@ -67,6 +67,10 @@ pub async fn res( account_information: web::Json, data: web::Data, ) -> Result { + if !data.config.instance.registration { + return Err(Error::Forbidden("registration is disabled on this instance".to_string())) + } + let uuid = Uuid::now_v7(); if !EMAIL_REGEX.is_match(&account_information.email) { diff --git a/src/config.rs b/src/config.rs index 102318f..079ce35 100644 --- a/src/config.rs +++ b/src/config.rs @@ -10,6 +10,7 @@ pub struct ConfigBuilder { database: Database, cache_database: CacheDatabase, web: Option, + instance: Option, bunny: BunnyBuilder, } @@ -38,6 +39,11 @@ struct WebBuilder { _ssl: Option, } +#[derive(Debug, Deserialize, Clone)] +pub struct Instance { + pub registration: bool, +} + #[derive(Debug, Deserialize)] struct BunnyBuilder { api_key: String, @@ -93,6 +99,7 @@ impl ConfigBuilder { database: self.database, cache_database: self.cache_database, web, + instance: self.instance.unwrap_or(Instance { registration: true }), bunny, } } @@ -103,6 +110,7 @@ pub struct Config { pub database: Database, pub cache_database: CacheDatabase, pub web: Web, + pub instance: Instance, pub bunny: Bunny, } diff --git a/src/error.rs b/src/error.rs index 3907f7c..fb990c7 100644 --- a/src/error.rs +++ b/src/error.rs @@ -61,6 +61,8 @@ pub enum Error { #[error("{0}")] Unauthorized(String), #[error("{0}")] + Forbidden(String), + #[error("{0}")] InternalServerError(String), }