Close #3: forgot/reset password routes

This commit is contained in:
François Voron
2019-10-13 12:05:10 +02:00
parent ef1f60d7e5
commit 49daeff869
9 changed files with 305 additions and 37 deletions

View File

@ -1,6 +1,6 @@
"""Ready-to-use and customizable users management for FastAPI."""
from typing import Callable, Type
from typing import Any, Callable, Type
from fastapi import APIRouter
@ -17,6 +17,9 @@ class FastAPIUsers:
:param db: Database adapter instance.
:param auth: Authentication logic instance.
:param user_model: Pydantic model of a user.
:param on_after_forgot_password: Hook called after a forgot password request.
:param reset_password_token_secret: Secret to encode reset password token.
:param reset_password_token_lifetime_seconds: Lifetime of reset password token.
:attribute router: FastAPI router exposing authentication routes.
:attribute get_current_user: Dependency callable to inject authenticated user.
@ -28,11 +31,24 @@ class FastAPIUsers:
get_current_user: Callable[..., BaseUserDB]
def __init__(
self, db: BaseUserDatabase, auth: BaseAuthentication, user_model: Type[BaseUser]
self,
db: BaseUserDatabase,
auth: BaseAuthentication,
user_model: Type[BaseUser],
on_after_forgot_password: Callable[[BaseUserDB, str], Any],
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)
self.router = get_user_router(
self.db,
user_model,
self.auth,
on_after_forgot_password,
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