Start to implement user registration using Lemmy as a back end

This commit is contained in:
Daoud Clarke 2022-12-06 22:36:38 +00:00
parent c0f89ba6c3
commit d8d7149f4a
3 changed files with 33 additions and 0 deletions

View file

@ -12,6 +12,7 @@ from mwmbl import background
from mwmbl.crawler import app as crawler
from mwmbl.indexer.batch_cache import BatchCache
from mwmbl.indexer.paths import INDEX_NAME, BATCH_DIR_NAME
from mwmbl.platform import user
from mwmbl.tinysearchengine import search
from mwmbl.tinysearchengine.completer import Completer
from mwmbl.tinysearchengine.indexer import TinyIndex, Document, NUM_PAGES, PAGE_SIZE
@ -72,6 +73,9 @@ def run():
crawler_router = crawler.get_router(batch_cache, url_queue)
app.include_router(crawler_router)
user_router = user.create_router()
app.include_router(user_router)
# Initialize uvicorn server using global app instance and server config params
uvicorn.run(app, host="0.0.0.0", port=5000)

View file

29
mwmbl/platform/user.py Normal file
View file

@ -0,0 +1,29 @@
import os
from urllib.parse import urljoin
import requests
from fastapi import APIRouter, Response
from pydantic import BaseModel
from starlette.responses import JSONResponse
LEMMY_URL = os.environ["LEMMY_URL"]
class Register(BaseModel):
username: str
email: str
password: str
password_verify: str
def create_router() -> APIRouter:
router = APIRouter(prefix="/user", tags=["user"])
@router.post("/register")
def register_user(register: Register) -> Response:
request = requests.post(urljoin(LEMMY_URL, "api/v3/user/register"), json=register.json())
print("Request", request)
# TODO: add in missing fields with null values from here: https://join-lemmy.org/api/classes/Register.html
return Response(content=request.content, status_code=request.status_code, media_type="text/json")
return router