Add admin account with user management endpoints
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user