Compare commits
2 Commits
76f7bbc9e2
...
6ee2db43d2
| Author | SHA1 | Date | |
|---|---|---|---|
|
6ee2db43d2
|
|||
|
3db7bc330b
|
@@ -52,7 +52,21 @@ 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(),
|
||||
@@ -117,9 +131,29 @@ pub async fn register_user(
|
||||
),
|
||||
}
|
||||
} else {
|
||||
(axum::http::StatusCode::NOT_ACCEPTABLE, Json(response::Response{
|
||||
(
|
||||
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",
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user