Ejemplo n.º 1
0
    def __init__(
        self,
        db: BaseUserDatabase,
        auth: BaseAuthentication,
        user_model: Type[BaseUser],
        reset_password_token_secret: str,
        reset_password_token_lifetime_seconds: int = 3600,
    ):
        self.db = db
        self.auth = auth
        self.router = get_user_router(
            self.db,
            user_model,
            self.auth,
            reset_password_token_secret,
            reset_password_token_lifetime_seconds,
        )

        get_current_user = self.auth.get_current_user(self.db)
        self.get_current_user = get_current_user  # type: ignore

        get_current_active_user = self.auth.get_current_active_user(self.db)
        self.get_current_active_user = get_current_active_user  # type: ignore

        get_current_superuser = self.auth.get_current_superuser(self.db)
        self.get_current_superuser = get_current_superuser  # type: ignore
Ejemplo n.º 2
0
    def __init__(
        self,
        db: BaseUserDatabase,
        auth_backends: Sequence[BaseAuthentication],
        user_model: Type[models.BaseUser],
        user_create_model: Type[models.BaseUserCreate],
        user_update_model: Type[models.BaseUserUpdate],
        user_db_model: Type[models.BaseUserDB],
        reset_password_token_secret: str,
        reset_password_token_lifetime_seconds: int = 3600,
    ):
        self.db = db
        self.authenticator = Authenticator(auth_backends, db)
        self.router = get_user_router(
            self.db,
            user_model,
            user_create_model,
            user_update_model,
            user_db_model,
            self.authenticator,
            reset_password_token_secret,
            reset_password_token_lifetime_seconds,
        )
        self.oauth_routers = []
        self._user_db_model = user_db_model
        self._event_handlers = defaultdict(list)

        self.get_current_user = self.authenticator.get_current_user
        self.get_current_active_user = self.authenticator.get_current_active_user
        self.get_current_superuser = self.authenticator.get_current_superuser
def test_app_client(mock_user_db, mock_authentication, event_handler) -> TestClient:
    mock_authentication_bis = MockAuthentication(name="mock-bis")
    authenticator = Authenticator(
        [mock_authentication, mock_authentication_bis], mock_user_db
    )

    user_router = get_user_router(
        mock_user_db,
        User,
        UserCreate,
        UserUpdate,
        UserDB,
        authenticator,
        SECRET,
        LIFETIME,
    )

    user_router.add_event_handler(Event.ON_AFTER_REGISTER, event_handler)
    user_router.add_event_handler(Event.ON_AFTER_FORGOT_PASSWORD, event_handler)
    user_router.add_event_handler(Event.ON_AFTER_UPDATE, event_handler)

    app = FastAPI()
    app.include_router(user_router)

    return TestClient(app)
Ejemplo n.º 4
0
def test_app_client(mock_user_db, mock_authentication,
                    event_handler) -> TestClient:
    class User(BaseUser):
        pass

    userRouter = get_user_router(mock_user_db, User, mock_authentication,
                                 SECRET, LIFETIME)

    userRouter.add_event_handler(Event.ON_AFTER_REGISTER, event_handler)
    userRouter.add_event_handler(Event.ON_AFTER_FORGOT_PASSWORD, event_handler)

    app = FastAPI()
    app.include_router(userRouter)

    return TestClient(app)