Spaces:
Sleeping
Sleeping
Commit
·
4c88a77
1
Parent(s):
c598104
fix system user creation
Browse files
main.py
CHANGED
|
@@ -113,7 +113,7 @@ def create_device_token(username: str, user_agent: str) -> str:
|
|
| 113 |
def is_token_expired(expiration_time: datetime) -> bool:
|
| 114 |
return datetime.now(timezone.utc) > expiration_time
|
| 115 |
|
| 116 |
-
async def create_user(username: str, password: str, email: Optional[str] = None):
|
| 117 |
"""
|
| 118 |
Creates a new user in the database.
|
| 119 |
|
|
@@ -141,7 +141,7 @@ async def create_user(username: str, password: str, email: Optional[str] = None)
|
|
| 141 |
"password": password,
|
| 142 |
"email": email,
|
| 143 |
"date_joined": datetime.now(timezone.utc).isoformat(),
|
| 144 |
-
"access_level": "default",
|
| 145 |
}
|
| 146 |
|
| 147 |
inserted_user = supabase.table("users").insert(user_data).execute()
|
|
@@ -150,7 +150,7 @@ async def create_user(username: str, password: str, email: Optional[str] = None)
|
|
| 150 |
# Initialize system user
|
| 151 |
async def init_system_user():
|
| 152 |
try:
|
| 153 |
-
await create_user(SYSTEM_USER, hash_password(SYSTEM_PASSWORD), None)
|
| 154 |
except HTTPException as e:
|
| 155 |
if e.status_code == status.HTTP_400_BAD_REQUEST and "Username already exists" in e.detail:
|
| 156 |
print("System user already exists, continuing...")
|
|
|
|
| 113 |
def is_token_expired(expiration_time: datetime) -> bool:
|
| 114 |
return datetime.now(timezone.utc) > expiration_time
|
| 115 |
|
| 116 |
+
async def create_user(username: str, password: str, email: Optional[str] = None, access_level : Optional[str] = None):
|
| 117 |
"""
|
| 118 |
Creates a new user in the database.
|
| 119 |
|
|
|
|
| 141 |
"password": password,
|
| 142 |
"email": email,
|
| 143 |
"date_joined": datetime.now(timezone.utc).isoformat(),
|
| 144 |
+
"access_level": access_level or "default",
|
| 145 |
}
|
| 146 |
|
| 147 |
inserted_user = supabase.table("users").insert(user_data).execute()
|
|
|
|
| 150 |
# Initialize system user
|
| 151 |
async def init_system_user():
|
| 152 |
try:
|
| 153 |
+
await create_user(SYSTEM_USER, hash_password(SYSTEM_PASSWORD), None, "hush")
|
| 154 |
except HTTPException as e:
|
| 155 |
if e.status_code == status.HTTP_400_BAD_REQUEST and "Username already exists" in e.detail:
|
| 156 |
print("System user already exists, continuing...")
|