Implement async db access in admin
This commit is contained in:
@ -8,6 +8,7 @@ import bcrypt
|
||||
import jwt
|
||||
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy.orm import Session
|
||||
from sshecret_admin.core.settings import AdminServerSettings
|
||||
|
||||
@ -72,6 +73,16 @@ def check_password(plain_password: str, hashed_password: str) -> None:
|
||||
raise AuthenticationFailedError()
|
||||
|
||||
|
||||
async def authenticate_user_async(session: AsyncSession, username: str, password: str) -> User | None:
|
||||
"""Authenticate user async."""
|
||||
user = (await session.scalars(select(User).where(User.username == username))).first()
|
||||
if not user:
|
||||
return None
|
||||
if not verify_password(password, user.hashed_password):
|
||||
return None
|
||||
return user
|
||||
|
||||
|
||||
def authenticate_user(session: Session, username: str, password: str) -> User | None:
|
||||
"""Authenticate user."""
|
||||
user = session.scalars(select(User).where(User.username == username)).first()
|
||||
|
||||
Reference in New Issue
Block a user