From 0d243414b83b0fa6bf16ce5ac98244fbd014965b Mon Sep 17 00:00:00 2001 From: Daniel Gray Date: Fri, 19 Jul 2024 08:05:59 +0200 Subject: [PATCH] updating user management --- app/accounts/service/active_email.py | 32 ++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 app/accounts/service/active_email.py diff --git a/app/accounts/service/active_email.py b/app/accounts/service/active_email.py new file mode 100644 index 00000000..d43181a9 --- /dev/null +++ b/app/accounts/service/active_email.py @@ -0,0 +1,32 @@ +from django.contrib.sites.shortcuts import get_current_site +from django.core.mail import EmailMultiAlternatives +from django.template.loader import render_to_string +from django.utils.encoding import force_bytes +from django.utils.http import urlsafe_base64_encode + +from accounts.tokens import account_activation_token + + +class SendActiveEmailService: + @staticmethod + def send_activation_email(request, user): + if user and request: + current_site = get_current_site(request) + mail_subject = "Activate your account." + message = render_to_string( + "accounts/email/activation_email.html", + { + "user": user, + "domain": current_site.domain, + "uid": urlsafe_base64_encode(force_bytes(user.pk)), + "token": account_activation_token.make_token(user), + }, + ) + text_content = ( + "Please activate your account by clicking the link provided in the email." + ) + email = EmailMultiAlternatives( + mail_subject, text_content, "your-email@example.com", [user.email] + ) + email.attach_alternative(message, "text/html") + email.send()