You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
2.7 KiB
72 lines
2.7 KiB
# -*- coding: utf-8 -*-
|
|
from django.template.loader import render_to_string
|
|
from django.core.mail import EmailMessage
|
|
from django.conf import settings
|
|
from celery import task
|
|
|
|
|
|
@task
|
|
def send_registration_email(user_email, confirm_url, site_url):
|
|
"""Отправить письмо о регистрации нового пользователя."""
|
|
template_name = 'emails/registration_email.txt'
|
|
subject = 'Регистрация на Документоре: подтверждение e-mail'
|
|
dict_context = {
|
|
'user_email': user_email,
|
|
'confirm_url': confirm_url,
|
|
'support_email': settings.SUPPORT_EMAIL,
|
|
'site_url': site_url
|
|
}
|
|
email_body = render_to_string(template_name, dict_context)
|
|
email = EmailMessage(subject=subject, to=(user_email,), body=email_body)
|
|
return email.send()
|
|
|
|
|
|
@task
|
|
def send_greeting_email(user_email, site_url):
|
|
"""
|
|
A greeting letter after signing up a new user on the create test licenses
|
|
"""
|
|
template_name = 'emails/greeting.txt'
|
|
subject = 'Документор: Добро пожаловать!'
|
|
|
|
dict_context = {
|
|
'user_email': user_email,
|
|
'support_email': settings.SUPPORT_EMAIL,
|
|
'robot_email': settings.EMAIL_ROBOT,
|
|
'site_url': site_url
|
|
}
|
|
email_body = render_to_string(template_name, dict_context)
|
|
email = EmailMessage(subject=subject, to=(user_email,), body=email_body)
|
|
return email.send()
|
|
|
|
|
|
@task
|
|
def send_reset_password_email(user_email, confirm_url, site_url):
|
|
"""Отправить письмо с ключём для восстановления пароля."""
|
|
template_name = 'emails/reset_key_email.txt'
|
|
subject = 'Документор: восстановление пароля'
|
|
dict_context = {
|
|
'user_email': user_email,
|
|
'confirm_url': confirm_url,
|
|
'support_email': settings.SUPPORT_EMAIL,
|
|
'site_url': site_url
|
|
}
|
|
email_body = render_to_string(template_name, dict_context)
|
|
email = EmailMessage(subject=subject, to=(user_email,), body=email_body)
|
|
return email.send()
|
|
|
|
|
|
@task
|
|
def send_new_password_email(user_email, new_password, site_url):
|
|
"""Отправить письмо с новым паролем."""
|
|
template_name = 'emails/reset_new_password_email.txt'
|
|
subject = 'Документор: новый пароль'
|
|
dict_context = {
|
|
'user_email': user_email,
|
|
'new_password': new_password,
|
|
'support_email': settings.SUPPORT_EMAIL,
|
|
'site_url': site_url
|
|
}
|
|
email_body = render_to_string(template_name, dict_context)
|
|
email = EmailMessage(subject=subject, to=(user_email,), body=email_body)
|
|
return email.send()
|
|
|