imbolc / async-django-user

Using django user with async frameworks like aiohttp, starlette, etc.
11 stars 3 forks source link

Add fastapi_app.py? #2

Closed jet10000 closed 4 years ago

jet10000 commented 4 years ago

https://github.com/tiangolo/fastapi

and possible to add aiosmtpd_app.py?

https://github.com/aio-libs/aiosmtpd

:)

imbolc commented 4 years ago

I use it with fastapi this way:

async def maybe_user(session=Depends(get_session)):
    return await auth_backend.get_user_from_session(session).load()

async def active_user(user: User = Depends(maybe_user)):
    if not user:
        raise HTTPException(401)
    if not user["is_active"]:
        raise HTTPException(403, "User isn't active")
    return user

async def staff_user(user: User = Depends(active_user)):
    if not user["is_staff"] and not user["is_superuser"]:
        raise HTTPException(403, "Staff user required")
    return user

I'll commit it a bit later if there won't be any pitfalls. Where would you add aiosmtpd?

jet10000 commented 4 years ago

A system built on django and postgreSQL, including web, mobile app, chat, and mailserver, accepts email and sends email through a web interface (equivalent to a simplified mail system, receive email checked by django's authentication system).

web -> django or starlette mobile app -> fastapi chat -> aiohttp websokcet mailserver -> aiosmtpd (similar to haraka, but combined with django user module and just receive email and send email)

https://haraka.github.io/

:)