Spaces:
Runtime error
Runtime error
Update email client to yagmail
Browse files
TechdocsAPI/backend/__init__.py
CHANGED
@@ -53,10 +53,10 @@ try:
|
|
53 |
MAIL_USERNAME=config.MAIL_USERNAME,
|
54 |
MAIL_PASSWORD=config.MAIL_PASSWORD,
|
55 |
MAIL_FROM=config.MAIL_FROM,
|
56 |
-
MAIL_PORT=
|
57 |
MAIL_SERVER="smtp.gmail.com",
|
58 |
-
MAIL_STARTTLS=
|
59 |
-
MAIL_SSL_TLS=
|
60 |
TEMPLATE_FOLDER="backend/templates",
|
61 |
USE_CREDENTIALS = True,
|
62 |
VALIDATE_CERTS = True
|
|
|
53 |
MAIL_USERNAME=config.MAIL_USERNAME,
|
54 |
MAIL_PASSWORD=config.MAIL_PASSWORD,
|
55 |
MAIL_FROM=config.MAIL_FROM,
|
56 |
+
MAIL_PORT=8080,
|
57 |
MAIL_SERVER="smtp.gmail.com",
|
58 |
+
MAIL_STARTTLS=False,
|
59 |
+
MAIL_SSL_TLS=True,
|
60 |
TEMPLATE_FOLDER="backend/templates",
|
61 |
USE_CREDENTIALS = True,
|
62 |
VALIDATE_CERTS = True
|
TechdocsAPI/backend/services/auth/ops.py
CHANGED
@@ -47,22 +47,24 @@ async def ops_signup(bgtasks: BackgroundTasks, response_result: GeneralResponse,
|
|
47 |
template_body=email_body_params,
|
48 |
subtype=MessageType.html
|
49 |
)
|
50 |
-
|
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),
|
60 |
['username', 'password', 'email', 'is_verified'])
|
61 |
|
62 |
|
63 |
|
64 |
response_result.status = 'success'
|
65 |
-
response_result.message = [f'Activate your account by clicking on the link sent to {data.email}.\nMake sure to check your spam folder.']
|
66 |
|
67 |
def ops_login(data:LoginCreds):
|
68 |
"""Wrapper method to handle login process.
|
@@ -91,8 +93,8 @@ def ops_login(data:LoginCreds):
|
|
91 |
# password is incorrect
|
92 |
raise InvalidCredentialsException(response_result)
|
93 |
|
94 |
-
if not user[2]:
|
95 |
-
|
96 |
|
97 |
# password is correct
|
98 |
return TokenSchema(access_token=Auth.create_access_token(data.username),
|
|
|
47 |
template_body=email_body_params,
|
48 |
subtype=MessageType.html
|
49 |
)
|
50 |
+
|
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 |
+
|
58 |
+
# bgtasks.add_task(app.state.mail_client.send_message, message=message, template_name="email_verification.html")
|
59 |
# await app.state.mail_client.send_message(message=message, template_name="email_verification.html")
|
60 |
|
61 |
+
DBQueries.insert_to_database('auth', (data.username, Auth.get_password_hash(data.password), data.email, 1),
|
62 |
['username', 'password', 'email', 'is_verified'])
|
63 |
|
64 |
|
65 |
|
66 |
response_result.status = 'success'
|
67 |
+
# response_result.message = [f'Activate your account by clicking on the link sent to {data.email}.\nMake sure to check your spam folder.']
|
68 |
|
69 |
def ops_login(data:LoginCreds):
|
70 |
"""Wrapper method to handle login process.
|
|
|
93 |
# password is incorrect
|
94 |
raise InvalidCredentialsException(response_result)
|
95 |
|
96 |
+
# if not user[2]:
|
97 |
+
# raise EmailNotVerifiedException()
|
98 |
|
99 |
# password is correct
|
100 |
return TokenSchema(access_token=Auth.create_access_token(data.username),
|