Spaces:
Runtime error
Runtime error
Commit
·
ea406bd
1
Parent(s):
977adf2
Chang
Browse files
TechdocsAPI/backend/__init__.py
CHANGED
|
@@ -10,7 +10,9 @@ from backend.core.ConfigEnv import config
|
|
| 10 |
|
| 11 |
from langchain.llms import Clarifai
|
| 12 |
from langchain.chains import LLMChain
|
| 13 |
-
from langchain.prompts import PromptTemplate
|
|
|
|
|
|
|
| 14 |
|
| 15 |
app = FastAPI(title="Techdocs",
|
| 16 |
version="V0.0.1",
|
|
@@ -47,6 +49,25 @@ try:
|
|
| 47 |
app.state.templates = Jinja2Templates(directory="./backend/templates")
|
| 48 |
|
| 49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
except mysql.connector.Error as err:
|
| 52 |
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(err))
|
|
|
|
| 10 |
|
| 11 |
from langchain.llms import Clarifai
|
| 12 |
from langchain.chains import LLMChain
|
| 13 |
+
from langchain.prompts import PromptTemplate
|
| 14 |
+
|
| 15 |
+
from fastapi_mail import ConnectionConfig, FastMail
|
| 16 |
|
| 17 |
app = FastAPI(title="Techdocs",
|
| 18 |
version="V0.0.1",
|
|
|
|
| 49 |
app.state.templates = Jinja2Templates(directory="./backend/templates")
|
| 50 |
|
| 51 |
|
| 52 |
+
conf = ConnectionConfig(
|
| 53 |
+
MAIL_USERNAME=config.MAIL_USERNAME,
|
| 54 |
+
MAIL_PASSWORD=config.MAIL_PASSWORD,
|
| 55 |
+
MAIL_FROM=config.MAIL_FROM,
|
| 56 |
+
MAIL_PORT=2525,
|
| 57 |
+
MAIL_SERVER="smtp.gmail.com",
|
| 58 |
+
MAIL_STARTTLS=True,
|
| 59 |
+
MAIL_SSL_TLS=False,
|
| 60 |
+
TEMPLATE_FOLDER="server/templates",
|
| 61 |
+
USE_CREDENTIALS = True,
|
| 62 |
+
VALIDATE_CERTS = True
|
| 63 |
+
|
| 64 |
+
# MAIL_TLS=True,
|
| 65 |
+
# MAIL_SSL=False
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
+
app.state.mail_client = FastMail(conf)
|
| 69 |
+
|
| 70 |
+
|
| 71 |
|
| 72 |
except mysql.connector.Error as err:
|
| 73 |
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(err))
|
TechdocsAPI/backend/services/auth/ops.py
CHANGED
|
@@ -12,6 +12,8 @@ from fastapi import HTTPException, BackgroundTasks
|
|
| 12 |
from pydantic import ValidationError
|
| 13 |
from jose import jwt
|
| 14 |
|
|
|
|
|
|
|
| 15 |
async def ops_signup(bgtasks: BackgroundTasks, response_result: GeneralResponse, data: UserAuth):
|
| 16 |
"""Wrapper method to handle signup process.
|
| 17 |
|
|
@@ -44,9 +46,18 @@ async def ops_signup(bgtasks: BackgroundTasks, response_result: GeneralResponse,
|
|
| 44 |
"template_kwargs": email_body_params
|
| 45 |
}
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
|
| 52 |
|
|
|
|
| 12 |
from pydantic import ValidationError
|
| 13 |
from jose import jwt
|
| 14 |
|
| 15 |
+
from fastapi_mail import MessageSchema, MessageType
|
| 16 |
+
|
| 17 |
async def ops_signup(bgtasks: BackgroundTasks, response_result: GeneralResponse, data: UserAuth):
|
| 18 |
"""Wrapper method to handle signup process.
|
| 19 |
|
|
|
|
| 46 |
"template_kwargs": email_body_params
|
| 47 |
}
|
| 48 |
|
| 49 |
+
message = MessageSchema(
|
| 50 |
+
subject=details.subject,
|
| 51 |
+
recipients=details.recipients, # List of recipients, as many as you can pass
|
| 52 |
+
template_body=details.template_kwargs,
|
| 53 |
+
subtype=MessageType.html
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
await app.state.mail_client.send_message(message=message, template_name=details.template_name)
|
| 57 |
+
|
| 58 |
+
# status = post_request(url=config.MAIL_SERVER_URL, data=details, headers=None)
|
| 59 |
+
# if status != 200:
|
| 60 |
+
# raise EmailNotSentException()
|
| 61 |
|
| 62 |
|
| 63 |
|
TechdocsAPI/backend/services/auth/utils/functools.py
CHANGED
|
@@ -4,6 +4,6 @@ import json
|
|
| 4 |
|
| 5 |
def post_request(url: str, data: Dict[str, Any], headers: Dict[str, str]=None):
|
| 6 |
json_data = json.dumps(data)
|
| 7 |
-
headers =
|
| 8 |
-
response = requests.post(url, data=
|
| 9 |
return response.status_code
|
|
|
|
| 4 |
|
| 5 |
def post_request(url: str, data: Dict[str, Any], headers: Dict[str, str]=None):
|
| 6 |
json_data = json.dumps(data)
|
| 7 |
+
headers = {'Content-type': 'application/json', 'Accept': 'application/json'}
|
| 8 |
+
response = requests.post(url, data=json_data, headers=headers)
|
| 9 |
return response.status_code
|
TechdocsAPI/requirements.txt
CHANGED
|
@@ -10,3 +10,4 @@ langchain
|
|
| 10 |
clarifai
|
| 11 |
Pillow
|
| 12 |
jinja2
|
|
|
|
|
|
| 10 |
clarifai
|
| 11 |
Pillow
|
| 12 |
jinja2
|
| 13 |
+
fastapi-mail==1.3.1
|
temp.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
import json
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def post_request(url, data, headers=None):
|
| 6 |
+
data = json.dumps(data)
|
| 7 |
+
headers = {'Content-type': 'application/json', 'Accept': 'application/json'}
|
| 8 |
+
response = requests.post(url, data=data, headers=headers)
|
| 9 |
+
return response.status_code, response.json()
|
| 10 |
+
|
| 11 |
+
email_body_params = {
|
| 12 |
+
"username": "mayo",
|
| 13 |
+
"verify_link": "verification_link"
|
| 14 |
+
}
|
| 15 |
+
details = {
|
| 16 |
+
"recipient": ["[email protected]", "[email protected]"],
|
| 17 |
+
"subject": "Welcome to Techdocs:[Account Verification]",
|
| 18 |
+
"template_name": "email_verification.html",
|
| 19 |
+
"template_kwargs": email_body_params
|
| 20 |
+
}
|
| 21 |
+
print(post_request("https://email-server-five.vercel.app/api/send", details))
|