mirror of
https://github.com/fastapi-users/fastapi-users.git
synced 2025-08-15 03:04:27 +08:00
21 lines
584 B
Python
21 lines
584 B
Python
from fastapi import APIRouter
|
|
|
|
from .db import UserDBInterface
|
|
from .models import UserCreate, UserDB
|
|
from .password import get_password_hash
|
|
|
|
|
|
class UserRouter:
|
|
|
|
def __new__(cls, userDB: UserDBInterface) -> APIRouter:
|
|
router = APIRouter()
|
|
|
|
@router.post('/register')
|
|
async def register(user: UserCreate):
|
|
hashed_password = get_password_hash(user.password)
|
|
db_user = UserDB(**user.dict(), hashed_password=hashed_password)
|
|
created_user = await userDB.create(db_user)
|
|
return created_user
|
|
|
|
return router
|