-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of github.com:e2nIEE/pandahub into develop
- Loading branch information
Showing
23 changed files
with
804 additions
and
304 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
from fastapi import Depends | ||
|
||
from pandahub import PandaHub | ||
from .internal.models import UserDB | ||
from .internal.db import User | ||
from .internal.users import fastapi_users | ||
|
||
current_active_user = fastapi_users.current_user(active=True) | ||
|
||
|
||
def pandahub(user: UserDB = Depends(current_active_user)): | ||
def pandahub(user: User = Depends(current_active_user)): | ||
return PandaHub(user_id=str(user.id)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,40 @@ | ||
import asyncio | ||
import uuid | ||
|
||
import motor.motor_asyncio | ||
from fastapi_users.db import MongoDBUserDatabase | ||
from fastapi_users_db_mongodb.access_token import MongoDBAccessTokenDatabase | ||
from beanie import Document | ||
from fastapi_users.db import BeanieBaseUser, BeanieUserDatabase | ||
from fastapi_users_db_beanie.access_token import ( | ||
BeanieAccessTokenDatabase, | ||
BeanieBaseAccessToken, | ||
) | ||
|
||
from pandahub.api.internal import settings | ||
from pandahub.api.internal.models import AccessToken, UserDB | ||
from pydantic import Field | ||
|
||
mongo_client_args = {"host": settings.MONGODB_URL, "uuidRepresentation": "standard", "connect": False} | ||
if settings.MONGODB_USER: | ||
mongo_client_args |= {"username": settings.MONGODB_USER, "password": settings.MONGODB_PASSWORD} | ||
|
||
client = motor.motor_asyncio.AsyncIOMotorClient(**mongo_client_args) | ||
|
||
client.get_io_loop = asyncio.get_event_loop | ||
|
||
db = client["user_management"] | ||
collection = db["users"] | ||
access_tokens_collection = db["access_tokens"] | ||
|
||
class User(BeanieBaseUser, Document): | ||
# pass | ||
# id: Optional[UUID4] = Field(alias="id") | ||
id: uuid.UUID = Field(default_factory=uuid.uuid4) | ||
class Settings(BeanieBaseUser.Settings): | ||
name = "users" | ||
|
||
async def get_user_db(): | ||
if settings.COSMOSDB_COMPAT: | ||
yield MongoDBUserDatabaseCosmos(UserDB, collection) | ||
else: | ||
yield MongoDBUserDatabase(UserDB, collection) | ||
|
||
class AccessToken(BeanieBaseAccessToken, Document): | ||
user_id: uuid.UUID = Field(default_factory=uuid.uuid4) | ||
class Settings(BeanieBaseAccessToken.Settings): | ||
name = "access_tokens" | ||
|
||
async def get_user_db(): | ||
yield BeanieUserDatabase(User) | ||
|
||
async def get_access_token_db(): | ||
yield MongoDBAccessTokenDatabase(AccessToken, access_tokens_collection) | ||
|
||
class MongoDBUserDatabaseCosmos(MongoDBUserDatabase): | ||
from typing import Optional | ||
from fastapi_users.models import UD | ||
async def get_by_email(self, email: str) -> Optional[UD]: | ||
await self._initialize() | ||
|
||
user = await self.collection.find_one( | ||
{"email": email} | ||
) | ||
return self.user_db_model(**user) if user else None | ||
|
||
async def _initialize(self): | ||
if not self.initialized: | ||
if "email_1" not in await self.collection.index_information(): | ||
await self.collection.create_index("id", unique=True) | ||
await self.collection.create_index("email", unique=True) | ||
self.initialized = True | ||
yield BeanieAccessTokenDatabase(AccessToken) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import uuid | ||
|
||
from fastapi_users import schemas | ||
from pandahub.api.internal.settings import REGISTRATION_ADMIN_APPROVAL | ||
|
||
|
||
class UserRead(schemas.BaseUser[uuid.UUID]): | ||
pass | ||
|
||
class UserCreate(schemas.BaseUserCreate): | ||
is_active: bool = not REGISTRATION_ADMIN_APPROVAL | ||
|
||
class UserUpdate(schemas.BaseUserUpdate): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,20 @@ | ||
from fastapi import APIRouter | ||
|
||
from pandahub.api.internal.users import auth_backend, fastapi_users | ||
|
||
from pandahub.api.internal.schemas import UserCreate, UserRead | ||
from pandahub.api.internal.settings import REGISTRATION_ENABLED | ||
|
||
router = APIRouter( | ||
prefix="/auth", | ||
tags=["auth"] | ||
) | ||
router = APIRouter(prefix="/auth", tags=["auth"]) | ||
|
||
router.include_router( | ||
fastapi_users.get_auth_router(auth_backend) | ||
) | ||
router.include_router(fastapi_users.get_auth_router(auth_backend)) | ||
|
||
router.include_router( | ||
fastapi_users.get_reset_password_router() | ||
) | ||
router.include_router(fastapi_users.get_reset_password_router()) | ||
|
||
if REGISTRATION_ENABLED: | ||
router.include_router( | ||
fastapi_users.get_register_router() | ||
fastapi_users.get_register_router(UserRead, UserCreate), | ||
) | ||
|
||
router.include_router( | ||
fastapi_users.get_verify_router() | ||
fastapi_users.get_verify_router(UserRead), | ||
) |
Oops, something went wrong.