-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* password reset * password email
- Loading branch information
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -170,6 +170,53 @@ def send_password_reset_email(verification_code: str, email: str): | |
return response | ||
|
||
|
||
|
||
def send_password_changed_email(email: str): | ||
ses_client = boto3.client("ses") | ||
TEXT_EMAIL_CONTENT = """ | ||
This email confirms you have successfully changed your password for you OpenAQ Explorer account. | ||
If you believe you have recieved this email in error please reach out to [email protected]. | ||
""" | ||
HTML_EMAIL_CONTENT = """ | ||
<html> | ||
<head></head> | ||
<body> | ||
<table width="100%" border="0" cellpadding="0" cellspacing="0"> | ||
<tr> | ||
<td bgcolor="#FFFFFF" style="padding:30px;"> | ||
<h1 style='text-align:center'>OpenAQ password reset</h1> | ||
<p>This email confirms you have successfully changed your password for you OpenAQ Explorer account.</p> | ||
<p>If you believe you have recieved this email in error please reach out to [email protected]</p> | ||
</td> | ||
</tr> | ||
</table> | ||
</body> | ||
</html> | ||
""" | ||
msg = EmailMessage() | ||
msg.set_content(TEXT_EMAIL_CONTENT) | ||
msg.add_alternative(HTML_EMAIL_CONTENT, subtype="html") | ||
msg["Subject"] = "OpenAQ Explorer - Reset password success" | ||
msg["From"] = settings.EMAIL_SENDER | ||
msg["To"] = email | ||
response = ses_client.send_raw_email( | ||
Source=settings.EMAIL_SENDER, | ||
Destinations=[f"<{email}>"], | ||
RawMessage={"Data": msg.as_string()}, | ||
) | ||
logger.info( | ||
SESEmailLog( | ||
detail=json.dumps( | ||
{ | ||
"email": email, | ||
"reponse": response, | ||
} | ||
) | ||
).model_dump_json() | ||
) | ||
return response | ||
|
||
class RegenerateTokenBody(JsonBase): | ||
users_id: int | ||
token: str | ||
|
@@ -229,6 +276,15 @@ async def request_password_reset_email( | |
logger.info(InfoLog(detail=json.dumps(response)).model_dump_json()) | ||
|
||
|
||
@router.post("/send-password-changed-email") | ||
async def password_changed_email( | ||
body: PasswordResetEmailBody, | ||
): | ||
email_address = body.email_address | ||
response = send_password_changed_email(email_address) | ||
logger.info(InfoLog(detail=json.dumps(response)).model_dump_json()) | ||
|
||
|
||
class VerifyBody(JsonBase): | ||
users_id: int | ||
|
||
|