當前位置: 首頁>>代碼示例>>Python>>正文


Python fastapi.APIRouter方法代碼示例

本文整理匯總了Python中fastapi.APIRouter方法的典型用法代碼示例。如果您正苦於以下問題:Python fastapi.APIRouter方法的具體用法?Python fastapi.APIRouter怎麽用?Python fastapi.APIRouter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在fastapi的用法示例。


在下文中一共展示了fastapi.APIRouter方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_register_router

# 需要導入模塊: import fastapi [as 別名]
# 或者: from fastapi import APIRouter [as 別名]
def get_register_router(
        self, after_register: Optional[Callable[[models.UD, Request], None]] = None,
    ) -> APIRouter:
        """
        Return a router with a register route.

        :param after_register: Optional function called
        after a successful registration.
        """
        return get_register_router(
            self.db,
            self._user_model,
            self._user_create_model,
            self._user_db_model,
            after_register,
        ) 
開發者ID:frankie567,項目名稱:fastapi-users,代碼行數:18,代碼來源:fastapi_users.py

示例2: get_reset_password_router

# 需要導入模塊: import fastapi [as 別名]
# 或者: from fastapi import APIRouter [as 別名]
def get_reset_password_router(
        self,
        reset_password_token_secret: str,
        reset_password_token_lifetime_seconds: int = 3600,
        after_forgot_password: Optional[
            Callable[[models.UD, str, Request], None]
        ] = None,
    ) -> APIRouter:
        """
        Return a reset password process router.

        :param reset_password_token_secret: Secret to encode reset password token.
        :param reset_password_token_lifetime_seconds: Lifetime of reset password token.
        :param after_forgot_password: Optional function called after a successful
        forgot password request.
        """
        return get_reset_password_router(
            self.db,
            reset_password_token_secret,
            reset_password_token_lifetime_seconds,
            after_forgot_password,
        ) 
開發者ID:frankie567,項目名稱:fastapi-users,代碼行數:24,代碼來源:fastapi_users.py

示例3: get_users_router

# 需要導入模塊: import fastapi [as 別名]
# 或者: from fastapi import APIRouter [as 別名]
def get_users_router(
        self,
        after_update: Optional[
            Callable[[models.UD, Dict[str, Any], Request], None]
        ] = None,
    ) -> APIRouter:
        """
        Return a router with routes to manage users.

        :param after_update: Optional function called
        after a successful user update.
        """
        return get_users_router(
            self.db,
            self._user_model,
            self._user_update_model,
            self._user_db_model,
            self.authenticator,
            after_update,
        ) 
開發者ID:frankie567,項目名稱:fastapi-users,代碼行數:22,代碼來源:fastapi_users.py

示例4: get_auth_router

# 需要導入模塊: import fastapi [as 別名]
# 或者: from fastapi import APIRouter [as 別名]
def get_auth_router(self, backend: BaseAuthentication) -> APIRouter:
        """
        Return an auth router for a given authentication backend.

        :param backend: The authentication backend instance.
        """
        return get_auth_router(backend, self.db, self.authenticator) 
開發者ID:frankie567,項目名稱:fastapi-users,代碼行數:9,代碼來源:fastapi_users.py

示例5: get_oauth_router

# 需要導入模塊: import fastapi [as 別名]
# 或者: from fastapi import APIRouter [as 別名]
def get_oauth_router(
        self,
        oauth_client: BaseOAuth2,
        state_secret: str,
        redirect_url: str = None,
        after_register: Optional[Callable[[models.UD, Request], None]] = None,
    ) -> APIRouter:
        """
        Return an OAuth router for a given OAuth client.

        :param oauth_client: The HTTPX OAuth client instance.
        :param state_secret: Secret used to encode the state JWT.
        :param redirect_url: Optional arbitrary redirect URL for the OAuth2 flow.
        If not given, the URL to the callback endpoint will be generated.
        :param after_register: Optional function called
        after a successful registration.
        """
        return get_oauth_router(
            oauth_client,
            self.db,
            self._user_db_model,
            self.authenticator,
            state_secret,
            redirect_url,
            after_register,
        ) 
開發者ID:frankie567,項目名稱:fastapi-users,代碼行數:28,代碼來源:fastapi_users.py

示例6: get_register_router

# 需要導入模塊: import fastapi [as 別名]
# 或者: from fastapi import APIRouter [as 別名]
def get_register_router(
    user_db: BaseUserDatabase[models.BaseUserDB],
    user_model: Type[models.BaseUser],
    user_create_model: Type[models.BaseUserCreate],
    user_db_model: Type[models.BaseUserDB],
    after_register: Optional[Callable[[models.UD, Request], None]] = None,
) -> APIRouter:
    """Generate a router with the register route."""
    router = APIRouter()

    @router.post(
        "/register", response_model=user_model, status_code=status.HTTP_201_CREATED
    )
    async def register(request: Request, user: user_create_model):  # type: ignore
        user = cast(models.BaseUserCreate, user)  # Prevent mypy complain
        existing_user = await user_db.get_by_email(user.email)

        if existing_user is not None:
            raise HTTPException(
                status_code=status.HTTP_400_BAD_REQUEST,
                detail=ErrorCode.REGISTER_USER_ALREADY_EXISTS,
            )

        hashed_password = get_password_hash(user.password)
        db_user = user_db_model(
            **user.create_update_dict(), hashed_password=hashed_password
        )
        created_user = await user_db.create(db_user)

        if after_register:
            await run_handler(after_register, created_user, request)

        return created_user

    return router 
開發者ID:frankie567,項目名稱:fastapi-users,代碼行數:37,代碼來源:register.py


注:本文中的fastapi.APIRouter方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。