-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Eduard0803
committed
Nov 26, 2023
1 parent
e58b83f
commit c535aa3
Showing
4 changed files
with
57 additions
and
1 deletion.
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
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 |
---|---|---|
|
@@ -4,3 +4,7 @@ | |
class AuthUserDTO(BaseModel): | ||
registration: str | ||
password: str | ||
|
||
|
||
class RecoverPasswordDTO(BaseModel): | ||
email: str |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import os | ||
import smtplib | ||
import email.message | ||
import secrets | ||
import string | ||
|
||
|
||
def generate_password(length=8): | ||
characters = string.ascii_letters + string.digits | ||
password = "".join(secrets.choice(characters) for _ in range(length)) | ||
return password | ||
|
||
|
||
def send_email(user_name: str, user_email: str, user_message: str) -> None: | ||
|
||
email_data = { | ||
"email_address": os.getenv("EMAIL_ADDRESS"), | ||
"email_password": os.getenv("EMAIL_PASSWORD"), | ||
"email_subject": "recover-password SINDPOL-DF", | ||
"email_body": """ | ||
<p>recover-password<p> | ||
<p>name: {}<p> | ||
<p>new-password: {}<p> | ||
""", | ||
} | ||
|
||
msg = email.message.Message() | ||
msg["Subject"] = email_data["email_subject"] | ||
msg["From"] = email_data["email_address"] | ||
msg["To"] = user_email | ||
msg.add_header("Content-Type", "text/html") | ||
msg.set_payload(email_data["email_body"].format(user_name, user_message)) | ||
|
||
s = smtplib.SMTP("smtp.gmail.com: 587") | ||
s.starttls() | ||
s.login(msg["From"], email_data["email_password"]) | ||
s.sendmail(msg["From"], [msg["To"]], msg.as_string().encode("utf-8")) |
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