-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
35 lines (28 loc) · 1.28 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from fastapi import FastAPI, status
from fastapi.exceptions import RequestValidationError, HTTPException
from fastapi.responses import PlainTextResponse
from models.auth_token import AuthToken
from services.function_helper import sendEmail, pipeToVCar
from services.encrypt_helper import decrypt_creds
vcar = FastAPI()
# TODO set up verification for jsons that do not match
# TODO set up logging
#TODO set up error when email that does not exists protection
@vcar.post("/api/v1/register", status_code=status.HTTP_201_CREATED)
async def register(gathered_information: AuthToken):
#save the credentials in the sqlite database
gathered_information.saveCredentials()
pipeToVCar(gathered_information)
cred_dict = decrypt_creds()
sender_email = cred_dict["email"]
sender_pass = cred_dict["password"]
#sends token to the embedded
sendEmail(gathered_information, sender_email, sender_pass)
#to validate the json being received
@vcar.exception_handler(RequestValidationError)
async def requestValidationExceptionHandler(request, exc):
return PlainTextResponse("Does not match!", status_code=400)
#to check for http exceptions
@vcar.exception_handler(HTTPException)
async def httpExceptionHandler(request, exc):
return PlainTextResponse("Error in HTTP", status_code=500)