-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3e42042
commit 0d24341
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |