Merge pull request 'Add environment variable to disable signup' (#159) from 157-add-environment-variable-to-disable-signup into main

Reviewed-on: LibreTunes/LibreTunes#159
This commit is contained in:
Ethan Girouard 2024-11-24 21:34:32 +00:00
commit fac33bb1f1
3 changed files with 7 additions and 0 deletions

View File

@ -18,3 +18,4 @@ DATABASE_URL=postgresql://libretunes:password@localhost:5432/libretunes
LIBRETUNES_AUDIO_PATH=assets/audio
LIBRETUNES_IMAGE_PATH=assets/images
LIBRETUNES_DISABLE_SIGNUP=true

View File

@ -15,6 +15,7 @@ services:
POSTGRES_DB: ${POSTGRES_DB}
LIBRETUNES_AUDIO_PATH: /assets/audio
LIBRETUNES_IMAGE_PATH: /assets/images
LIBRETUNES_DISABLE_SIGNUP: "true"
volumes:
- libretunes-audio:/assets/audio
- libretunes-images:/assets/images

View File

@ -19,6 +19,11 @@ use crate::users::UserCredentials;
/// Returns a Result with the error message if the user could not be created
#[server(endpoint = "signup")]
pub async fn signup(new_user: User) -> Result<(), ServerFnError> {
// Check LIBRETUNES_DISABLE_SIGNUP env var
if std::env::var("LIBRETUNES_DISABLE_SIGNUP").is_ok_and(|v| v == "true") {
return Err(ServerFnError::<NoCustomError>::ServerError("Signup is disabled".to_string()));
}
use crate::users::create_user;
// Ensure the user has no id, and is not a self-proclaimed admin