feat: allow disabling of registration
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful

This commit is contained in:
Radical 2025-05-26 23:41:20 +02:00
parent 1cda34d16b
commit b8cf21903e
3 changed files with 14 additions and 0 deletions

View file

@ -67,6 +67,10 @@ pub async fn res(
account_information: web::Json<AccountInformation>, account_information: web::Json<AccountInformation>,
data: web::Data<Data>, data: web::Data<Data>,
) -> Result<HttpResponse, Error> { ) -> Result<HttpResponse, Error> {
if !data.config.instance.registration {
return Err(Error::Forbidden("registration is disabled on this instance".to_string()))
}
let uuid = Uuid::now_v7(); let uuid = Uuid::now_v7();
if !EMAIL_REGEX.is_match(&account_information.email) { if !EMAIL_REGEX.is_match(&account_information.email) {

View file

@ -10,6 +10,7 @@ pub struct ConfigBuilder {
database: Database, database: Database,
cache_database: CacheDatabase, cache_database: CacheDatabase,
web: Option<WebBuilder>, web: Option<WebBuilder>,
instance: Option<Instance>,
bunny: BunnyBuilder, bunny: BunnyBuilder,
} }
@ -38,6 +39,11 @@ struct WebBuilder {
_ssl: Option<bool>, _ssl: Option<bool>,
} }
#[derive(Debug, Deserialize, Clone)]
pub struct Instance {
pub registration: bool,
}
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
struct BunnyBuilder { struct BunnyBuilder {
api_key: String, api_key: String,
@ -93,6 +99,7 @@ impl ConfigBuilder {
database: self.database, database: self.database,
cache_database: self.cache_database, cache_database: self.cache_database,
web, web,
instance: self.instance.unwrap_or(Instance { registration: true }),
bunny, bunny,
} }
} }
@ -103,6 +110,7 @@ pub struct Config {
pub database: Database, pub database: Database,
pub cache_database: CacheDatabase, pub cache_database: CacheDatabase,
pub web: Web, pub web: Web,
pub instance: Instance,
pub bunny: Bunny, pub bunny: Bunny,
} }

View file

@ -61,6 +61,8 @@ pub enum Error {
#[error("{0}")] #[error("{0}")]
Unauthorized(String), Unauthorized(String),
#[error("{0}")] #[error("{0}")]
Forbidden(String),
#[error("{0}")]
InternalServerError(String), InternalServerError(String),
} }