コード例 #1
0
from datetime import timedelta

from fastapi import APIRouter, HTTPException
from starlette import status

from project.config import Config
from project.dal.retailer import RetailerRepository
from project.dtos.auth import Token, AuthData
from project.logger import Logger
from project.services.auth.auth_service import AuthService

config = Config()
logger = Logger()

router = APIRouter()
retailer_repository = RetailerRepository(config, logger)

auth_service = AuthService(config, logger, retailer_repository)


@router.post("/auth/token/", response_model=Token)
def login_for_access_token(auth_data: AuthData) -> Token:
    retailer = auth_service.authenticate_retailer(email=auth_data.email,
                                                  password=auth_data.password)

    if not retailer:
        raise HTTPException(
            status_code=status.HTTP_401_UNAUTHORIZED,
            detail="Incorrect username or password",
            headers={"WWW-Authenticate": "Bearer"},
        )
コード例 #2
0
ファイル: decorator.py プロジェクト: tkosht/template
def change_logger(logger_name='test'):
    global logger
    logger = Logger(logger_name)
コード例 #3
0
def logger() -> Logger:
    return Logger()
コード例 #4
0
ファイル: decorator.py プロジェクト: tkosht/template
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import functools
import traceback
from project.logger import Logger

logger_name = 'app'
logger = Logger(logger_name)


def change_logger(logger_name='test'):
    global logger
    logger = Logger(logger_name)


def trace(f: callable) -> callable:
    """ trace decorator

    Args:
        f: decorated function

    Returns:
        wrapper function

    >>> fn = lambda : print("hello")
    >>> lg = trace(fn)
    >>> type(lg)
    <class 'function'>
    >>> lg.__name__
    '<lambda>'
コード例 #5
0
ファイル: test_logger.py プロジェクト: tkosht/template
 def logger(self):
     return Logger(logger_name)