tests, reset_password first steps
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import smtplib
|
||||
import ssl
|
||||
from email.message import EmailMessage
|
||||
|
||||
from src.models.configs_read.env import env_settings
|
||||
from src.service.email.jinja_env import jinja_env
|
||||
|
||||
|
||||
class ResetEmailSender:
|
||||
|
||||
async def send_email(self, target_email: str, temp_password: str) -> None:
|
||||
context = ssl.create_default_context()
|
||||
with smtplib.SMTP_SSL(
|
||||
env_settings.SMTP_SERVER, env_settings.EMAIL_PORT, context=context
|
||||
) as server:
|
||||
server.login(env_settings.EMAIL_LOGIN, env_settings.EMAIL_PASSWORD)
|
||||
msg = await self.build_email_message(target_email, temp_password)
|
||||
server.send_message(msg)
|
||||
|
||||
async def build_email_message(self, target_email: str, temp_password: str) -> EmailMessage:
|
||||
template = jinja_env.get_template("reset.html")
|
||||
html_body = template.render(temp_password=temp_password)
|
||||
|
||||
text_body = (
|
||||
"Пароль от вашей учётной записи в «The DisExcel» был сброшен.\n\n"
|
||||
f"Временный пароль: {temp_password}\n\n"
|
||||
"Рекомендуем сменить его на свой сразу после входа в аккаунт. "
|
||||
"Если вы не запрашивали сброс пароля, срочно свяжитесь с поддержкой."
|
||||
)
|
||||
|
||||
msg = EmailMessage()
|
||||
msg["to"] = target_email
|
||||
msg["from"] = env_settings.EMAIL_LOGIN
|
||||
msg["subject"] = "Пароль сброшен"
|
||||
msg.set_content(text_body)
|
||||
msg.add_alternative(html_body, subtype="html")
|
||||
return msg
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
<tr>
|
||||
<td style="padding:20px; text-align:center;">
|
||||
<span style="display:block; margin:0 0 4px 0; color:#9ca3af; font-size:12px; text-transform:uppercase; letter-spacing:0.05em;">Новый пароль</span>
|
||||
<span style="display:inline-block; font-family: 'Courier New', monospace; font-size:20px; font-weight:700; color:#111827; letter-spacing:0.05em;">Тест1234!</span>
|
||||
<span style="display:inline-block; font-family: 'Courier New', monospace; font-size:20px; font-weight:700; color:#111827; letter-spacing:0.05em;">{{ temp_password }}</span>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
Reference in New Issue
Block a user