Compare commits

...

6 Commits

Author SHA1 Message Date
6ee2db43d2 tsk-61: code formatting
Some checks failed
Rust Build / Check (pull_request) Successful in 40s
Rust Build / Test Suite (pull_request) Failing after 1m25s
Rust Build / Rustfmt (pull_request) Successful in 30s
Rust Build / Clippy (pull_request) Successful in 39s
Rust Build / build (pull_request) Successful in 58s
2025-10-20 12:33:11 -04:00
3db7bc330b tsk-61: Added code to check registration status 2025-10-20 12:32:55 -04:00
76f7bbc9e2 tsk-61: Updating readme 2025-10-20 12:16:43 -04:00
34687dda7d tsk-61: Adding changes to make feature available 2025-10-20 12:16:31 -04:00
6c83e566bf tsk-61: Filename change 2025-10-20 12:12:19 -04:00
b74c0fc3b0 tsk-61: Added env variable 2025-10-20 12:11:52 -04:00
4 changed files with 102 additions and 55 deletions

View File

@@ -10,3 +10,4 @@ POSTGRES_AUTH_PASSWORD=password
POSTGRES_AUTH_DB=icarus_auth_db POSTGRES_AUTH_DB=icarus_auth_db
POSTGRES_AUTH_HOST=auth_db POSTGRES_AUTH_HOST=auth_db
DATABASE_URL=postgresql://${POSTGRES_AUTH_USER}:${POSTGRES_AUTH_PASSWORD}@${POSTGRES_AUTH_HOST}:5432/${POSTGRES_AUTH_DB} DATABASE_URL=postgresql://${POSTGRES_AUTH_USER}:${POSTGRES_AUTH_PASSWORD}@${POSTGRES_AUTH_HOST}:5432/${POSTGRES_AUTH_DB}
ENABLE_REGISTRATION=TRUE

View File

@@ -10,3 +10,4 @@ POSTGRES_AUTH_PASSWORD=password
POSTGRES_AUTH_DB=icarus_auth_test_db POSTGRES_AUTH_DB=icarus_auth_test_db
POSTGRES_AUTH_HOST=localhost POSTGRES_AUTH_HOST=localhost
DATABASE_URL=postgresql://${POSTGRES_AUTH_USER}:${POSTGRES_AUTH_PASSWORD}@${POSTGRES_AUTH_HOST}:5432/${POSTGRES_AUTH_DB} DATABASE_URL=postgresql://${POSTGRES_AUTH_USER}:${POSTGRES_AUTH_PASSWORD}@${POSTGRES_AUTH_HOST}:5432/${POSTGRES_AUTH_DB}
ENABLE_REGISTRATION=TRUE

View File

@@ -8,22 +8,26 @@ need to be modified. The `SECRET_KEY` variable should be changed since it will b
generation. The `SECRET_PASSPHASE` should also be changed when in production mode, but make sure generation. The `SECRET_PASSPHASE` should also be changed when in production mode, but make sure
the respective `passphrase` database table record exists. the respective `passphrase` database table record exists.
Build image To enable or disable registrations, use `TRUE` or `FALSE` for the `ENABLE_REGISTRATION` variable.
By default it is `TRUE`.
### Build image
``` ```
docker compose build docker compose build
``` ```
Start images ### Start images
``` ```
docker compose up -d --force-recreate docker compose up -d --force-recreate
``` ```
Bring it down ### Bring it down
``` ```
docker compose down -v docker compose down -v
``` ```
Pruning ### Pruning
``` ```
docker system prune -a docker system prune -a
``` ```

View File

@@ -52,6 +52,21 @@ pub async fn register_user(
axum::Extension(pool): axum::Extension<sqlx::PgPool>, axum::Extension(pool): axum::Extension<sqlx::PgPool>,
Json(payload): Json<request::Request>, Json(payload): Json<request::Request>,
) -> (StatusCode, Json<response::Response>) { ) -> (StatusCode, Json<response::Response>) {
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 { let mut user = icarus_models::user::User {
username: payload.username.clone(), username: payload.username.clone(),
password: payload.password.clone(), password: payload.password.clone(),
@@ -115,4 +130,30 @@ pub async fn register_user(
}), }),
), ),
} }
} else {
(
axum::http::StatusCode::NOT_ACCEPTABLE,
Json(response::Response {
message: String::from("Registration is not enabled"),
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",
))
}
} }