Backend: ADD User Auth

This commit is contained in:
Kentai Radiquum 2024-04-17 17:13:40 +05:00
parent c82b6e7265
commit 23ac963dee
Signed by: Radiquum
GPG key ID: 858E8EE696525EED
4 changed files with 51 additions and 0 deletions

View file

@ -2,11 +2,13 @@ import uvicorn
from fastapi import FastAPI
from modules.pages import index
from modules.release import release
from modules.user import auth
from modules.user import profile
app = FastAPI()
app.include_router(profile.router, prefix="/profile")
app.include_router(auth.router, prefix="/auth")
app.include_router(release.router, prefix="/release")

View file

@ -8,6 +8,7 @@ ENDPOINTS = {
"release": f"{API_URL}/release",
"profile": f"{API_URL}/profile",
"filter": f"{API_URL}/filter",
"auth": f"{API_URL}/auth/signIn",
}
USER_AGENT = "AnixartApp/8.2.1-23121216 (Android 11; SDK 30; arm64-v8a;)"

View file

@ -0,0 +1,47 @@
from typing import Annotated
import requests
from fastapi import APIRouter
from fastapi import Form
from fastapi import Request
from modules.proxy import ENDPOINTS
from modules.proxy import USER_AGENT
router = APIRouter()
@router.post("", summary="logging in")
async def userSignIn(
request: Request,
email: Annotated[str, Form()],
password: Annotated[str, Form()],
short: bool = False,
):
headers = {
"User-Agent": USER_AGENT,
"Sign": "9aa5c7af74e8cd70c86f7f9587bde23d",
"Content-Type": "application/x-www-form-urlencoded",
}
r = requests.post(
# noqa: E501
f"{ENDPOINTS['auth']}",
headers=headers,
data={"login": email, "password": password},
)
if r.status_code != 200:
return {"error": r.text}
res = r.json()
if short is True:
return {
"code": res["code"],
"profile": {
"id": res["profile"]["id"],
"login": res["profile"]["login"],
"avatar": res["profile"]["avatar"],
},
"profileToken": {
"id": res["profileToken"]["id"],
"token": res["profileToken"]["token"],
},
}
return res

View file

@ -2,3 +2,4 @@ requests == 2.31.0
fastAPI == 0.110.1
uvicorn[standard]
pre-commit
python-multipart