Skip to content

Commit

Permalink
updating user management
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-gray-tangent committed Jul 19, 2024
1 parent 3e42042 commit 0d24341
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions app/accounts/service/active_email.py
Original file line number Diff line number Diff line change
@@ -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, "[email protected]", [user.email]
)
email.attach_alternative(message, "text/html")
email.send()

0 comments on commit 0d24341

Please sign in to comment.