Add admin account with user management endpoints

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-24 20:45:19 -07:00
parent 7994cc5ff2
commit 48a15c54f6
10 changed files with 238 additions and 5 deletions

View File

@@ -17,9 +17,11 @@ def verify_password(plain: str, hashed: str) -> bool:
return pwd_context.verify(plain, hashed)
def create_token(user_id: int) -> str:
def create_token(user_id: int, admin_id: Optional[int] = None) -> str:
expire = datetime.now(timezone.utc) + timedelta(minutes=settings.access_token_expire_minutes)
payload = {"sub": str(user_id), "exp": expire}
payload: dict = {"sub": str(user_id), "exp": expire}
if admin_id is not None:
payload["admin_id"] = admin_id
return jwt.encode(payload, settings.secret_key, algorithm=settings.algorithm)
@@ -32,3 +34,10 @@ def decode_token(token: str) -> Optional[int]:
return int(user_id)
except JWTError:
return None
def decode_token_full(token: str) -> Optional[dict]:
try:
return jwt.decode(token, settings.secret_key, algorithms=[settings.algorithm])
except JWTError:
return None