feat: added endpoints: auth, pofile, account, keyring
This commit is contained in:
36
api/api/services/auth.py
Normal file
36
api/api/services/auth.py
Normal file
@@ -0,0 +1,36 @@
|
||||
from datetime import datetime, timedelta
|
||||
from typing import Optional
|
||||
|
||||
from fastapi import Depends, HTTPException, Request, status
|
||||
# from fastapi_jwt_auth import AuthJWT
|
||||
# from fastapi_jwt_auth.exceptions import JWTDecodeError
|
||||
# from jose import JWTError, jwt
|
||||
from loguru import logger
|
||||
from sqlalchemy.ext.asyncio import AsyncConnection
|
||||
|
||||
from api.config import get_settings
|
||||
from api.db.connection.session import get_connection_dep
|
||||
from api.db.logic.auth import get_user
|
||||
|
||||
# # from backend.schemas.users.token import TokenData
|
||||
|
||||
from api.schemas.account.account import User,Status
|
||||
from api.schemas.account.account_keyring import AccountKeyring
|
||||
|
||||
from api.utils.hasher import Hasher
|
||||
|
||||
|
||||
|
||||
|
||||
async def authenticate_user(
|
||||
connection: AsyncConnection, username: str, password: str
|
||||
) -> Optional[User]:
|
||||
|
||||
sql_user,sql_password = await get_user(connection, username)
|
||||
|
||||
if not sql_user or sql_user.status != Status.ACTIVE :
|
||||
return None
|
||||
hasher = Hasher()
|
||||
if not hasher.verify_data(password, sql_password.key_value):
|
||||
return None
|
||||
return sql_user
|
Reference in New Issue
Block a user