refactor logging module, add welcome and reset daemons, changed structure of the rabbitmq queues
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
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 DaemonEmailSender:
|
||||
def __init__(self) -> None:
|
||||
pass
|
||||
|
||||
async def send_email(self, target_email: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)
|
||||
server.send_message(msg)
|
||||
|
||||
async def build_email_message(self, target_email: str) -> EmailMessage:
|
||||
template = jinja_env.get_template("welcome.html")
|
||||
html_body = template.render(name=target_email)
|
||||
|
||||
text_body = (
|
||||
f"Добро пожаловать, {target_email}!\n\n"
|
||||
"Спасибо за регистрацию на проекте «The DisExcel». "
|
||||
"Мы рады, что вы с нами — учётная запись уже готова к работе.\n\n"
|
||||
"Если вы не регистрировались на The DisExcel, просто проигнорируйте это письмо."
|
||||
)
|
||||
|
||||
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
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
|
||||
jinja_env = Environment(
|
||||
loader=FileSystemLoader("src/service/email/templates"),
|
||||
autoescape=True,
|
||||
)
|
||||
@@ -0,0 +1,55 @@
|
||||
<!doctype html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Пароль сброшен</title>
|
||||
</head>
|
||||
<body style="margin:0; padding:0; background-color:#f4f4f7; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;">
|
||||
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="background-color:#f4f4f7; padding:40px 0;">
|
||||
<tr>
|
||||
<td align="center">
|
||||
<table role="presentation" width="480" cellpadding="0" cellspacing="0" style="background-color:#ffffff; border-radius:12px; overflow:hidden; box-shadow:0 2px 8px rgba(0,0,0,0.06);">
|
||||
|
||||
<tr>
|
||||
<td style="background-color:#dc2626; padding:32px 40px; text-align:center;">
|
||||
<h1 style="margin:0; color:#ffffff; font-size:22px; font-weight:600;">The DisExcel</h1>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td style="padding:40px;">
|
||||
<h2 style="margin:0 0 16px 0; color:#111827; font-size:20px;">Пароль был сброшен</h2>
|
||||
<p style="margin:0 0 24px 0; color:#4b5563; font-size:15px; line-height:1.6;">
|
||||
Пароль от вашей учётной записи в «The DisExcel» был сброшен. Ниже — временный пароль для входа. Рекомендуем сменить его на свой сразу после входа в аккаунт.
|
||||
</p>
|
||||
|
||||
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="background-color:#f9fafb; border:1px solid #e5e7eb; border-radius:8px;">
|
||||
<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>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<p style="margin:24px 0 0 0; color:#9ca3af; font-size:13px; line-height:1.5;">
|
||||
Если вы не запрашивали сброс пароля, срочно свяжитесь с поддержкой — возможно, кто-то получил доступ к вашей учётной записи.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td style="padding:24px 40px; background-color:#f9fafb; border-top:1px solid #e5e7eb;">
|
||||
<p style="margin:0; color:#9ca3af; font-size:12px; line-height:1.5;">
|
||||
Это автоматическое уведомление от The DisExcel. Не пересылайте это письмо никому.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,52 @@
|
||||
<!doctype html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Добро пожаловать</title>
|
||||
</head>
|
||||
<body style="margin:0; padding:0; background-color:#f4f4f7; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;">
|
||||
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="background-color:#f4f4f7; padding:40px 0;">
|
||||
<tr>
|
||||
<td align="center">
|
||||
<table role="presentation" width="480" cellpadding="0" cellspacing="0" style="background-color:#ffffff; border-radius:12px; overflow:hidden; box-shadow:0 2px 8px rgba(0,0,0,0.06);">
|
||||
|
||||
<tr>
|
||||
<td style="background-color:#4f46e5; padding:32px 40px; text-align:center;">
|
||||
<h1 style="margin:0; color:#ffffff; font-size:22px; font-weight:600;">The DisExcel</h1>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td style="padding:40px;">
|
||||
<h2 style="margin:0 0 16px 0; color:#111827; font-size:20px;">Добро пожаловать, {{ name }}</h2>
|
||||
<p style="margin:0 0 24px 0; color:#4b5563; font-size:15px; line-height:1.6;">
|
||||
Спасибо за регистрацию на проекте «The DisExcel». Мы рады, что вы с нами — учётная запись уже готова к работе.
|
||||
</p>
|
||||
|
||||
<table role="presentation" cellpadding="0" cellspacing="0" align="center" style="margin:0 auto;">
|
||||
<tr>
|
||||
<td style="border-radius:8px; background-color:#4f46e5;">
|
||||
<a href="#" style="display:inline-block; padding:12px 28px; color:#ffffff; font-size:14px; font-weight:600; text-decoration:none;">
|
||||
Перейти в аккаунт
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td style="padding:24px 40px; background-color:#f9fafb; border-top:1px solid #e5e7eb;">
|
||||
<p style="margin:0; color:#9ca3af; font-size:12px; line-height:1.5;">
|
||||
Если вы не регистрировались на The DisExcel, просто проигнорируйте это письмо.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user