mirror of
https://github.com/maxdorninger/MediaManager.git
synced 2026-04-19 00:54:12 +02:00
making progress
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import os
|
||||
import uuid
|
||||
from typing import Optional
|
||||
|
||||
@@ -9,6 +10,7 @@ from fastapi_users.authentication import (
|
||||
CookieTransport, JWTStrategy,
|
||||
)
|
||||
from fastapi_users.db import SQLAlchemyUserDatabase
|
||||
from httpx_oauth.oauth2 import OAuth2
|
||||
|
||||
import auth.config
|
||||
from auth.db import User, get_user_db
|
||||
@@ -17,6 +19,19 @@ config = auth.config.AuthConfig()
|
||||
SECRET = config.token_secret
|
||||
LIFETIME = config.session_lifetime
|
||||
|
||||
if os.getenv("OAUTH_ENABLED") == "True":
|
||||
oauth2_config = auth.config.OAuth2Config()
|
||||
|
||||
oauth_client = OAuth2(
|
||||
client_id=oauth2_config.client_id,
|
||||
client_secret=oauth2_config.client_secret,
|
||||
name=oauth2_config.name,
|
||||
authorize_endpoint=oauth2_config.authorize_endpoint,
|
||||
access_token_endpoint=oauth2_config.access_token_endpoint,
|
||||
)
|
||||
else:
|
||||
oauth_client = None
|
||||
|
||||
|
||||
# TODO: implement on_xxx methods
|
||||
class UserManager(UUIDIDMixin, BaseUserManager[User, uuid.UUID]):
|
||||
@@ -31,11 +46,19 @@ class UserManager(UUIDIDMixin, BaseUserManager[User, uuid.UUID]):
|
||||
):
|
||||
print(f"User {user.id} has forgot their password. Reset token: {token}")
|
||||
|
||||
async def on_after_reset_password(self, user: User, request: Optional[Request] = None):
|
||||
print(f"User {user.id} has reset their password.")
|
||||
|
||||
async def on_after_request_verify(
|
||||
self, user: User, token: str, request: Optional[Request] = None
|
||||
):
|
||||
print(f"Verification requested for user {user.id}. Verification token: {token}")
|
||||
|
||||
async def on_after_verify(
|
||||
self, user: User, request: Optional[Request] = None
|
||||
):
|
||||
print(f"User {user.id} has been verified")
|
||||
|
||||
|
||||
async def get_user_manager(user_db: SQLAlchemyUserDatabase = Depends(get_user_db)):
|
||||
yield UserManager(user_db)
|
||||
|
||||
Reference in New Issue
Block a user