Enhanced the user creation way.

This commit is contained in:
2025-04-06 12:11:43 +03:00
parent 91459ddabe
commit 9ffbe59356
3 changed files with 12 additions and 8 deletions

View File

@@ -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