Skip to content

Commit

Permalink
Magical
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-XT committed May 9, 2024
1 parent b7a9ac5 commit 3c0285c
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 66 deletions.
68 changes: 2 additions & 66 deletions Server.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from MagicalAuth import MagicalAuth
from pydantic import BaseModel
from endpoints import Auth
import logging
import os

Expand All @@ -23,67 +22,4 @@
format="%(asctime)s | %(levelname)s | %(message)s",
)


class Register(BaseModel):
email: str
first_name: str
last_name: str
company_name: str
job_title: str


class Login(BaseModel):
email: str
token: str


class UserInfo(BaseModel):
first_name: str
last_name: str
company_name: str
job_title: str


@app.post("/register")
def register(
register: Register,
):
auth = MagicalAuth(email=register.email)
mfa_token = auth.register(
first_name=register.first_name,
last_name=register.last_name,
company_name=register.company_name,
job_title=register.job_title,
)
return {"mfa_token": mfa_token}


@app.post("/login")
def login(login: Login):
auth = MagicalAuth(email=login.email, token=login.token)
user = auth.login()
return {
"email": user.email,
"first_name": user.first_name,
"last_name": user.last_name,
"company_name": user.company_name,
"job_title": user.job_title,
}


@app.post("/send_magic_link")
def send_magic_link(login: Login):
auth = MagicalAuth(email=login.email)
magic_link = auth.send_magic_link(otp=login.token)
return {"message": magic_link}


@app.put("/update_user")
def update_user(update: UserInfo, login: Login):
auth = MagicalAuth(email=login.email, token=login.token)
user = auth.login()
user.first_name = update.first_name
user.last_name = update.last_name
user.company_name = update.company_name
user.job_title = update.job_title
return {"message": "User updated successfully."}
app.include_router(Auth.router)
71 changes: 71 additions & 0 deletions endpoints/Auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
from fastapi import APIRouter
from pydantic import BaseModel
from MagicalAuth import MagicalAuth


router = APIRouter()


class Register(BaseModel):
email: str
first_name: str
last_name: str
company_name: str
job_title: str


class Login(BaseModel):
email: str
token: str


class UserInfo(BaseModel):
first_name: str
last_name: str
company_name: str
job_title: str


@router.post("/register")
def register(
register: Register,
):
auth = MagicalAuth(email=register.email)
mfa_token = auth.register(
first_name=register.first_name,
last_name=register.last_name,
company_name=register.company_name,
job_title=register.job_title,
)
return {"mfa_token": mfa_token}


@router.post("/login")
def login(login: Login):
auth = MagicalAuth(email=login.email, token=login.token)
user = auth.login()
return {
"email": user.email,
"first_name": user.first_name,
"last_name": user.last_name,
"company_name": user.company_name,
"job_title": user.job_title,
}


@router.post("/send_magic_link")
def send_magic_link(login: Login):
auth = MagicalAuth(email=login.email)
magic_link = auth.send_magic_link(otp=login.token)
return {"message": magic_link}


@router.put("/update_user")
def update_user(update: UserInfo, login: Login):
auth = MagicalAuth(email=login.email, token=login.token)
user = auth.login()
user.first_name = update.first_name
user.last_name = update.last_name
user.company_name = update.company_name
user.job_title = update.job_title
return {"message": "User updated successfully."}

0 comments on commit 3c0285c

Please sign in to comment.