tsk-61: Registration configuration #73

Merged
phoenix merged 8 commits from tsk-61 into main 2025-10-20 16:48:49 +00:00
Showing only changes of commit 3db7bc330b - Show all commits

View File

@@ -52,7 +52,20 @@ pub async fn register_user(
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
Json(payload): Json<request::Request>,
) -> (StatusCode, Json<response::Response>) {
if is_registration_enabled() {
let registration_enabled = match is_registration_enabled().await {
Ok(value) => {
value
}
Err(err) => {
eprintln!("Error: {err:?}");
return (axum::http::StatusCode::INTERNAL_SERVER_ERROR, Json(response::Response{
message: String::from("Registration check failed"),
data: Vec::new()
}));
}
};
if registration_enabled {
let mut user = icarus_models::user::User {
username: payload.username.clone(),
password: payload.password.clone(),
@@ -119,7 +132,22 @@ pub async fn register_user(
} else {
(axum::http::StatusCode::NOT_ACCEPTABLE, Json(response::Response{
message: String::from("Registration is not enabled"),
data:: Vec::new()
data: Vec::new()
}))
}
}
/// Checks to see if registration is enabled
async fn is_registration_enabled() -> Result<bool, std::io::Error> {
let key = String::from("ENABLE_REGISTRATION");
let var = icarus_envy::environment::get_env(&key).await;
let parsed_value = var.value.to_uppercase();
if parsed_value == "TRUE" {
Ok(true)
} else if parsed_value == "FALSE" {
Ok(false)
} else {
Err(std::io::Error::other("Could not determine value of ENABLE_REGISTRATION"))
}
}