Spaces:
Sleeping
Sleeping
File size: 1,505 Bytes
d3530f3 42cffde d3530f3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# from typing import Dict
# import jwt
# from datetime import datetime, timezone, timedelta
# from sqlalchemy.ext.asyncio import AsyncSession
# from src.utils.exceptions import BadRequestException
# from src.utils.password import PasswordUtils
# from src.interfaces.auth import ILogin
# from src.repositories.auth import AuthRepository
# from src.dtos.user import UserDto
# from env import config
# class AuthService:
# def __init__(self, repo: AuthRepository):
# self.repo = repo
# async def authenticate(self, db: AsyncSession, data: ILogin) -> UserDto:
# user = await self.repo.find_by_username(db, data.username)
# if not user:
# raise BadRequestException('username_not_match')
# if not PasswordUtils.check_password(data.password, user.password):
# raise BadRequestException('password_not_match')
# return self.create_access_token({
# "id": "1",
# "username": user.username,
# "email": user.email,
# })
# @staticmethod
# def create_access_token(data: Dict) -> UserDto:
# data_encoded = data.copy()
# data_encoded.update({"exp": datetime.now(timezone.utc) + timedelta(hours=config["jwt"]["expired_in"])})
# token = jwt.encode(data_encoded, config["jwt"]["secret_key"], algorithm=config["jwt"]["algorithm"])
# return token
# def get_auth_service() -> AuthService:
# auth_repo = AuthRepository()
# return AuthService(auth_repo)
|