From 9ffbe59356f8c5ca03d8d6a00e8bd06398fd7231 Mon Sep 17 00:00:00 2001 From: abdulhade Date: Sun, 6 Apr 2025 12:11:43 +0300 Subject: [PATCH] Enhanced the user creation way. --- README.md | 4 ++-- scripts/manager.sh | 5 ++--- utils/scripts.py | 11 ++++++++--- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 0077c1d..d17de30 100644 --- a/README.md +++ b/README.md @@ -111,8 +111,8 @@ During installation, you will be prompted to configure the following variables: ### 3. HAS_LOCAL_DBS Determines how the middleware connects to databases: -- **Enter `0`** – If the database is hosted on a remote server. -- **Enter `1`** – If the database runs on the same machine. +- **Enter `0`** – If all the databases are hosted on a remote server. +- **Enter `1`** – If one or more of the database runs on the same machine. > **Note:** By default, Docker containers operate on an isolated network. If your database is local, the middleware must be configured to run on the same network to ensure connectivity. diff --git a/scripts/manager.sh b/scripts/manager.sh index c0fd5ba..73971fe 100755 --- a/scripts/manager.sh +++ b/scripts/manager.sh @@ -112,9 +112,8 @@ We can't execute commands inside it, you can run it with: # Execute the command in the container OUTPUT=$(docker exec "$CONTAINER_NAME" bash -c "$COMMAND" 2>&1) - local EXIT_CODE=$? - + # Check if the command succeeded if [[ $EXIT_CODE -eq 0 ]]; then EXECUTION_MESSAGE="$OUTPUT" # Return the output @@ -174,7 +173,7 @@ create_user(){ local RETURN_CODE=$? if [[ $RETURN_CODE -eq 0 ]]; then - print_header $EXECUTION_MESSAGE + print_header "$EXECUTION_MESSAGE" else print_header "Couldn't create the user due to the above error." fi diff --git a/utils/scripts.py b/utils/scripts.py index fa4f9bf..da6f834 100644 --- a/utils/scripts.py +++ b/utils/scripts.py @@ -74,15 +74,20 @@ def create_secret(): async def create_user_script_async(username:str|None=None, role_input:str|None=None): - username = username.strip() if username else input("Enter username: ").strip() + if not (username and role_input): + username = input("Enter username: ") + role_input = input("Enter role (admin/user): ") + print('\n') + + username = username.strip() + role_input = role_input.strip().lower() + if not username.isalnum(): print("> Invalid username. Please use alphanumerical characters only.") return if not re.match("[a-zA-Z]{1}[a-zA-Z0-0-9]{,15}", username): print("> Invalid username. Please use english characters and numbers only.") return - role_input = role_input.strip().lower() if role_input else input("Enter role (admin/user): ").strip().lower() - print('\n') if role_input not in UserRole._value2member_map_: print("> Invalid role. Please enter 'admin' or 'user'.") return