feat: added endpoints: auth, pofile, account, keyring

This commit is contained in:
TheNoxium
2025-04-17 15:36:52 +05:00
parent b2f65ba21f
commit 1333992dc5
27 changed files with 1297 additions and 160 deletions

36
api/api/services/auth.py Normal file
View 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