123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- from django.conf import settings
- from django.contrib.auth.models import User
- from django.contrib.sites.shortcuts import get_current_site
- from django.core.mail import EmailMessage, send_mail, mail_admins
- from django.template.loader import render_to_string
- from django.utils.encoding import force_bytes
- from django.utils.http import urlsafe_base64_encode
- from . tokens import generate_token
- from users import parameter
-
-
- def send_activation_mail(new_user, request):
- email_subject = "Activate Account"
- message2 = render_to_string('users/email_activation.html', {
- 'name': new_user.first_name,
- 'base_url': request.build_absolute_uri('/')[:-1],
- 'pk': new_user.pk,
- })
- email = EmailMessage(
- email_subject,
- message2,
- settings.EMAIL_HOST_USER,
- )
- mail_admins(email_subject, message2, fail_silently=True)
-
-
- def send_validation_failed(uid, token):
- subject = "E-Mail validation failed!"
- message = f"uid = {uid}\ntoken = '{token}'"
- mail_admins(subject, message, fail_silently=True)
-
-
- def send_recover_failed(uid, token):
- subject = "Password recovery failed!"
- message = f"uid = {uid}\ntoken = '{token}'"
- mail_admins(subject, message, fail_silently=True)
-
-
- def send_welcome_mail(new_user: User):
- subject = "Welcome!"
- message = """Hello %(username)s.
-
- Welcome!
-
- Thank you for registration.""" % {"username": new_user.first_name}
- message += "\n\n" + parameter.registration_flow_description(new_user.username)
- send_mail(subject, message, settings.EMAIL_FROM, [new_user.email], fail_silently=True)
-
-
- def send_validation_mail(new_user, request):
- email_subject = "Confirm your Email"
- message2 = render_to_string('users/email_confirmation.html', {
- 'name': new_user.first_name,
- 'base_url': request.build_absolute_uri('/')[:-1],
- 'uid': urlsafe_base64_encode(force_bytes(new_user.pk)),
- 'token': generate_token.make_token(new_user)
- })
- email = EmailMessage(
- email_subject,
- message2,
- settings.EMAIL_HOST_USER,
- [new_user.email],
- )
- send_mail(email_subject, message2, settings.EMAIL_FROM, [new_user.email], fail_silently=True)
-
-
- def send_recover_mail(user, request):
- email_subject = "Password recovery"
- message2 = render_to_string('users/email_recover.html', {
- 'name': user.first_name,
- 'base_url': request.build_absolute_uri('/')[:-1],
- 'uid': urlsafe_base64_encode(force_bytes(user.pk)),
- 'token': generate_token.make_token(user)
- })
- email = EmailMessage(
- email_subject,
- message2,
- settings.EMAIL_HOST_USER,
- [user.email],
- )
- send_mail(email_subject, message2, settings.EMAIL_FROM, [user.email], fail_silently=True)
|