forked from yaso_meth/mih-project
Add register and sign up with supertokens
This commit is contained in:
@@ -9,6 +9,14 @@ from supertokens_python.recipe.session.framework.fastapi import verify_session
|
||||
from supertokens_python.recipe.session import SessionContainer
|
||||
from fastapi import Depends
|
||||
|
||||
from supertokens_python.recipe.session.framework.fastapi import verify_session
|
||||
from supertokens_python.recipe.thirdparty.asyncio import (
|
||||
get_user_by_id as get_user_by_id_thirdparty,
|
||||
)
|
||||
from supertokens_python.recipe.passwordless.asyncio import (
|
||||
get_user_by_id as get_user_by_id_passwordless,
|
||||
)
|
||||
|
||||
origins = [
|
||||
"http://localhost",
|
||||
"http://localhost:80",
|
||||
@@ -60,6 +68,18 @@ def read_root():
|
||||
|
||||
return {"Session id": user_id}
|
||||
|
||||
@app.post('/get_user_info_api')
|
||||
async def get_user_info_api(session: SessionContainer = Depends(verify_session())):
|
||||
user_id = session.get_user_id()
|
||||
|
||||
thirdparty_user = await get_user_by_id_thirdparty(user_id)
|
||||
if thirdparty_user is None:
|
||||
passwordless_user = await get_user_by_id_passwordless(user_id)
|
||||
if passwordless_user is not None:
|
||||
print(passwordless_user)
|
||||
else:
|
||||
print(thirdparty_user)
|
||||
|
||||
def serverRunning():
|
||||
return {"Status": "Server is Up and Running"}
|
||||
|
||||
|
||||
@@ -7,6 +7,10 @@ router = APIRouter()
|
||||
class userRequest(BaseModel):
|
||||
email: str
|
||||
DocOfficeID: int
|
||||
|
||||
class userInsertRequest(BaseModel):
|
||||
email: str
|
||||
app_id: str
|
||||
|
||||
#get user by email & doc Office ID
|
||||
@router.get("/users/profile/{email}", tags="users")
|
||||
@@ -50,4 +54,47 @@ async def read_all_users():
|
||||
]
|
||||
cursor.close()
|
||||
db.close()
|
||||
return items
|
||||
return items
|
||||
|
||||
# Get List of all files
|
||||
@router.get("/user/{uid}", tags="users")
|
||||
async def read_all_users(uid: str):
|
||||
db = dbConnection.dbConnect()
|
||||
cursor = db.cursor()
|
||||
query = "SELECT * FROM users where app_id = %s"
|
||||
cursor.execute(query, (uid,))
|
||||
items = [
|
||||
{
|
||||
"idUser": item[0],
|
||||
"email": item[1],
|
||||
"docOffice_ID": item[2],
|
||||
"fname": item[3],
|
||||
"lname": item[4],
|
||||
"title": item[5],
|
||||
"app_id": item[6],
|
||||
}
|
||||
for item in cursor.fetchall()
|
||||
]
|
||||
cursor.close()
|
||||
db.close()
|
||||
return items[0]
|
||||
|
||||
# Insert Patient into table
|
||||
@router.post("/user/insert/", tags="user", status_code=201)
|
||||
async def insertPatient(itemRequest : userInsertRequest):
|
||||
db = dbConnection.dbConnect()
|
||||
cursor = db.cursor()
|
||||
query = "insert into users "
|
||||
query += "(email, app_id) "
|
||||
query += "values (%s, %s)"
|
||||
userData = (itemRequest.email,
|
||||
itemRequest.app_id)
|
||||
try:
|
||||
cursor.execute(query, userData)
|
||||
except Exception as error:
|
||||
raise HTTPException(status_code=404, detail="Failed to Create Record")
|
||||
#return {"message": "Failed to Create Record"}
|
||||
db.commit()
|
||||
cursor.close()
|
||||
db.close()
|
||||
return {"message": "Successfully Created Record"}
|
||||
Reference in New Issue
Block a user