Create super user account if it does not exist (#1688)
* fix: temp create account for `super_user_id` if missing * chore: remove dumb import * refactor: move logic outside `crud` * feat: add uuid4 conversion * fix: require valid string in .env file * fix: update the `settings.super_user` value in case or normalisation for UUID4 * fix: allow long super_user * chore: code format * fix: add UI redirect with the normalized user * fix: normalize `super_user` up one level * fix: should normalize user in non-ui mode also
This commit is contained in:
+10
-3
@@ -2,7 +2,7 @@ import datetime
|
||||
import json
|
||||
from typing import Any, Dict, List, Optional
|
||||
from urllib.parse import urlparse
|
||||
from uuid import uuid4
|
||||
from uuid import UUID, uuid4
|
||||
|
||||
import shortuuid
|
||||
|
||||
@@ -18,8 +18,15 @@ from .models import BalanceCheck, Payment, PaymentFilters, TinyURL, User, Wallet
|
||||
# --------
|
||||
|
||||
|
||||
async def create_account(conn: Optional[Connection] = None) -> User:
|
||||
user_id = uuid4().hex
|
||||
async def create_account(
|
||||
conn: Optional[Connection] = None, user_id: Optional[str] = None
|
||||
) -> User:
|
||||
if user_id:
|
||||
user_uuid4 = UUID(hex=user_id, version=4)
|
||||
assert user_uuid4.hex == user_id, "User ID is not valid UUID4 hex string"
|
||||
else:
|
||||
user_id = uuid4().hex
|
||||
|
||||
await (conn or db).execute("INSERT INTO accounts (id) VALUES (?)", (user_id,))
|
||||
|
||||
new_account = await get_account(user_id=user_id, conn=conn)
|
||||
|
||||
Reference in New Issue
Block a user