feat: allow disabling of registration
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful
This commit is contained in:
parent
1cda34d16b
commit
b8cf21903e
3 changed files with 14 additions and 0 deletions
|
@ -67,6 +67,10 @@ pub async fn res(
|
|||
account_information: web::Json<AccountInformation>,
|
||||
data: web::Data<Data>,
|
||||
) -> 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();
|
||||
|
||||
if !EMAIL_REGEX.is_match(&account_information.email) {
|
||||
|
|
|
@ -10,6 +10,7 @@ pub struct ConfigBuilder {
|
|||
database: Database,
|
||||
cache_database: CacheDatabase,
|
||||
web: Option<WebBuilder>,
|
||||
instance: Option<Instance>,
|
||||
bunny: BunnyBuilder,
|
||||
}
|
||||
|
||||
|
@ -38,6 +39,11 @@ struct WebBuilder {
|
|||
_ssl: Option<bool>,
|
||||
}
|
||||
|
||||
#[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,
|
||||
}
|
||||
|
||||
|
|
|
@ -61,6 +61,8 @@ pub enum Error {
|
|||
#[error("{0}")]
|
||||
Unauthorized(String),
|
||||
#[error("{0}")]
|
||||
Forbidden(String),
|
||||
#[error("{0}")]
|
||||
InternalServerError(String),
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue