Spaces:
Runtime error
Runtime error
Commit
Β·
b60b60f
1
Parent(s):
e2f0611
Update email client to yagmail
Browse files
TechdocsAPI/backend/__init__.py
CHANGED
@@ -13,6 +13,9 @@ 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",
|
@@ -65,6 +68,14 @@ try:
|
|
65 |
app.state.mail_client = FastMail(conf)
|
66 |
app.state.templates = Jinja2Templates(directory="./backend/templates")
|
67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
|
69 |
|
70 |
except mysql.connector.Error as err:
|
|
|
13 |
from langchain.prompts import PromptTemplate
|
14 |
|
15 |
from fastapi_mail import ConnectionConfig, FastMail
|
16 |
+
import yagmail
|
17 |
+
from jinja2 import Environment, FileSystemLoader
|
18 |
+
import os
|
19 |
|
20 |
app = FastAPI(title="Techdocs",
|
21 |
version="V0.0.1",
|
|
|
68 |
app.state.mail_client = FastMail(conf)
|
69 |
app.state.templates = Jinja2Templates(directory="./backend/templates")
|
70 |
|
71 |
+
#testing yagmail
|
72 |
+
yag = yagmail.SMTP(config.MAIL_USERNAME, config.MAIL_PASSWORD)
|
73 |
+
app.state.yagmail = yag
|
74 |
+
env = Environment(
|
75 |
+
loader=FileSystemLoader('./backend/templates/'))
|
76 |
+
app.state.jinjaenv = env
|
77 |
+
|
78 |
+
|
79 |
|
80 |
|
81 |
except mysql.connector.Error as err:
|
TechdocsAPI/backend/services/auth/ops.py
CHANGED
@@ -47,8 +47,13 @@ async def ops_signup(bgtasks: BackgroundTasks, response_result: GeneralResponse,
|
|
47 |
template_body=email_body_params,
|
48 |
subtype=MessageType.html
|
49 |
)
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
52 |
# await app.state.mail_client.send_message(message=message, template_name="email_verification.html")
|
53 |
|
54 |
DBQueries.insert_to_database('auth', (data.username, Auth.get_password_hash(data.password), "", 0),
|
@@ -143,6 +148,7 @@ def ops_verify_email(request: Request, response_result: GeneralResponse, token:s
|
|
143 |
payload = jwt.decode(
|
144 |
token, config.JWT_VERIFICATION_SECRET_KEY, algorithms=[config.ALGORITHM]
|
145 |
)
|
|
|
146 |
token_data = TokenPayload(**payload)
|
147 |
if datetime.fromtimestamp(token_data.exp)< datetime.now():
|
148 |
return app.state.templates.TemplateResponse("verification_failure.html", context={"request": request})
|
@@ -155,7 +161,7 @@ def ops_verify_email(request: Request, response_result: GeneralResponse, token:s
|
|
155 |
print(registered_email[0][0])
|
156 |
if registered_email[0][0]:
|
157 |
return app.state.templates.TemplateResponse("verification_failure.html", context={"request": request})
|
158 |
-
|
159 |
|
160 |
DBQueries.update_data_in_database('auth','is_verified',f"username='{username}'", (True,))
|
161 |
DBQueries.update_data_in_database('auth','email',f"username='{username}'", email)
|
|
|
47 |
template_body=email_body_params,
|
48 |
subtype=MessageType.html
|
49 |
)
|
50 |
+
# username=adghasjd, verify_link=asdasd
|
51 |
+
# template = app.state.jinjaenv.get_template("email_verification.html")
|
52 |
+
# output = template.render(data=email_body_params)
|
53 |
+
email = "Hi {username} π\n\nWelcome to Techdocs! Please click on the link below to verify your account.\n\n<a href='{verify_link}'>Click Here</a>\n\nThanks,\nTechdocs Team".format(**email_body_params)
|
54 |
+
# bgtasks.add_task(app.state.mail_client.send_message, message=message, template_name="email_verification.html")
|
55 |
+
bgtasks.add_task(app.state.yagmail.send, to=data.email, subject="Welcome to Techdocs:[Account Verification]",
|
56 |
+
contents=email)
|
57 |
# await app.state.mail_client.send_message(message=message, template_name="email_verification.html")
|
58 |
|
59 |
DBQueries.insert_to_database('auth', (data.username, Auth.get_password_hash(data.password), "", 0),
|
|
|
148 |
payload = jwt.decode(
|
149 |
token, config.JWT_VERIFICATION_SECRET_KEY, algorithms=[config.ALGORITHM]
|
150 |
)
|
151 |
+
|
152 |
token_data = TokenPayload(**payload)
|
153 |
if datetime.fromtimestamp(token_data.exp)< datetime.now():
|
154 |
return app.state.templates.TemplateResponse("verification_failure.html", context={"request": request})
|
|
|
161 |
print(registered_email[0][0])
|
162 |
if registered_email[0][0]:
|
163 |
return app.state.templates.TemplateResponse("verification_failure.html", context={"request": request})
|
164 |
+
print("after")
|
165 |
|
166 |
DBQueries.update_data_in_database('auth','is_verified',f"username='{username}'", (True,))
|
167 |
DBQueries.update_data_in_database('auth','email',f"username='{username}'", email)
|
TechdocsAPI/backend/templates/email_verification.html
CHANGED
@@ -1,68 +1 @@
|
|
1 |
-
<!DOCTYPE html>
|
2 |
-
<html>
|
3 |
-
<head>
|
4 |
-
<title>Verify Email</title>
|
5 |
-
<style>
|
6 |
-
body {
|
7 |
-
font-family: Arial, sans-serif;
|
8 |
-
background-color: #f4f4f4;
|
9 |
-
margin: 0;
|
10 |
-
padding: 0;
|
11 |
-
}
|
12 |
-
|
13 |
-
.container {
|
14 |
-
width: 80%;
|
15 |
-
margin: 0 auto;
|
16 |
-
padding: 20px;
|
17 |
-
background-color: #fff;
|
18 |
-
border-radius: 8px;
|
19 |
-
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
20 |
-
}
|
21 |
-
|
22 |
-
h3 {
|
23 |
-
color: #333;
|
24 |
-
text-align: center;
|
25 |
-
}
|
26 |
-
|
27 |
-
p {
|
28 |
-
color: #555;
|
29 |
-
text-align: center;
|
30 |
-
margin-bottom: 20px;
|
31 |
-
}
|
32 |
-
|
33 |
-
a.button {
|
34 |
-
display: block;
|
35 |
-
width: 50%;
|
36 |
-
margin: 20px auto;
|
37 |
-
padding: 12px;
|
38 |
-
border-radius: 5px;
|
39 |
-
text-align: center;
|
40 |
-
text-decoration: none;
|
41 |
-
background-color: #0275d8;
|
42 |
-
color: #fff;
|
43 |
-
font-size: 1rem;
|
44 |
-
transition: background-color 0.3s;
|
45 |
-
}
|
46 |
-
|
47 |
-
a.button:hover {
|
48 |
-
background-color: #025aa5;
|
49 |
-
}
|
50 |
-
|
51 |
-
.disclaimer {
|
52 |
-
color: #777;
|
53 |
-
text-align: center;
|
54 |
-
}
|
55 |
-
</style>
|
56 |
-
</head>
|
57 |
-
<body>
|
58 |
-
<div class="container">
|
59 |
-
<h3>Account Verification</h3>
|
60 |
-
|
61 |
-
<p>Hi, {{username}}π. Thank you for registering with Techdocs. Please click the button below to verify your account:</p>
|
62 |
-
|
63 |
-
<a class="button" href="{{verify_link}}" target="_blank">Verify your email</a>
|
64 |
-
|
65 |
-
<p class="disclaimer">Please disregard this email if you did not register with Techdocs. Thank you.</p>
|
66 |
-
</div>
|
67 |
-
</body>
|
68 |
-
</html>
|
|
|
1 |
+
<!DOCTYPE html><html><head><title>Verify Email</title><style>body { font-family: Arial, sans-serif;background-color: #f4f4f4;margin: 0;padding: 0; } .container { width: 80%; margin: 0 auto; padding: 20px; background-color: #fff; border-radius: 8px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); } h3 { color: #333; text-align: center; } p { color: #555; text-align: center; margin-bottom: 20px; } a.button { display: block; width: 50%; margin: 20px auto; padding: 12px; border-radius: 5px; text-align: center; text-decoration: none; background-color: #0275d8; color: #fff; font-size: 1rem; transition: background-color 0.3s; } a.button:hover { background-color: #025aa5; } .disclaimer { color: #777; text-align: center; } </style> </head> <body> <div class="container"> <h3>Account Verification</h3> <p>Hi, {{username}}π. Thank you for registering with Techdocs. Please click the button below to verify your account:</p> <a class="button" href="{{verify_link}}" target="_blank">Verify your email</a> <p class="disclaimer">Please disregard this email if you did not register with Techdocs. Thank you.</p> </div> </body> </html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TechdocsAPI/requirements.txt
CHANGED
@@ -10,3 +10,4 @@ langchain
|
|
10 |
clarifai
|
11 |
Pillow
|
12 |
fastapi_mail==1.3.1
|
|
|
|
10 |
clarifai
|
11 |
Pillow
|
12 |
fastapi_mail==1.3.1
|
13 |
+
yagmail
|