示例#1
0
async def login_access_token(
        *,
        db: Session = Depends(deps.get_db),
        user_info: user.UserEmailAuth,
) -> Any:
    """
    用户登录
    :param db:
    :param user_info:
    :return:
    """

    # 验证用户
    user = curd_user.authenticate(db, email=user_info.username, password=user_info.password)
    if not user:
        logger.info(f"用户邮箱认证错误: email{user_info.username} password:{user_info.password}")
        return response_code.resp_500(message="用户名或者密码错误")
    elif not curd_user.is_active(user):
        return response_code.resp_500(message="用户邮箱未激活")

    access_token_expires = timedelta(minutes=settings.ACCESS_TOKEN_EXPIRE_MINUTES)

    return response_code.resp_200(data={
        "token": security.create_access_token(user.id, expires_delta=access_token_expires),
        "token_type": "Bearer",
    })
示例#2
0
 async def all_exception_handler(request: Request, exc: Exception):
     """
     全局所有异常
     :param request:
     :param exc:
     :return:
     """
     logger.error(f"全局异常\n{request.method}URL:{request.url}\nHeaders:{request.headers}\n{traceback.format_exc()}")
     return response_code.resp_500(message="服务器内部错误")
示例#3
0
 async def inner_validation_exception_handler(request: Request, exc: ValidationError):
     """
     内部参数验证异常
     :param request:
     :param exc:
     :return:
     """
     logger.error(f"内部参数验证错误\nURL:{request.url}\nHeaders:{request.headers}\n{traceback.format_exc()}")
     return response_code.resp_500(message=exc.errors())