diff --git a/users/management/commands/send_password_reset_email.py b/users/management/commands/send_welcome_email.py similarity index 62% rename from users/management/commands/send_password_reset_email.py rename to users/management/commands/send_welcome_email.py index 6324382..aaa7d73 100644 --- a/users/management/commands/send_password_reset_email.py +++ b/users/management/commands/send_welcome_email.py @@ -2,15 +2,19 @@ from django.core.management.base import BaseCommand from django.contrib.auth import get_user_model from users.models import EmailVerification -from users.tasks import send_reset_email +from users.tasks import send_welcome_email UserModel = get_user_model() class Command(BaseCommand): + help = "Send a welcome email to a user; allowing them to set their password." def add_arguments(self, parser): parser.add_argument("--email", type=str, required=True) + parser.add_argument( + "--reason", type=str, required=True, + help="The reason the user was added; will be the first line of the email body.") def handle(self, *args, **options): email = options["email"] @@ -18,6 +22,6 @@ class Command(BaseCommand): # copy/paste from views.py (excluding the comments) verification = EmailVerification.objects.create(user=user, email=user.username) - send_reset_email.delay(user.username, verification.token) + send_welcome_email.delay(user.email, verification.token, options["reason"]) print("Email sent successfully (delayed task)") diff --git a/users/tasks.py b/users/tasks.py index 9a2cbd5..fadf51b 100644 --- a/users/tasks.py +++ b/users/tasks.py @@ -32,3 +32,18 @@ def send_reset_email(email, token): "reset_url": get_settings().BASE_URL + reverse("reset_password", kwargs={"token": token}), }, ) + + +@shared_task +def send_welcome_email(email, token, reason): + send_rendered_email( + subject="Welcome to Bugsink", + base_template_name="mails/welcome_email", + recipient_list=[email], + context={ + "site_title": get_settings().SITE_TITLE, + "base_url": get_settings().BASE_URL + "/", + "reset_url": get_settings().BASE_URL + reverse("reset_password", kwargs={"token": token}), + "reason": reason, + }, + ) diff --git a/users/templates/mails/welcome_email.html b/users/templates/mails/welcome_email.html new file mode 100644 index 0000000..fe06894 --- /dev/null +++ b/users/templates/mails/welcome_email.html @@ -0,0 +1,523 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/users/templates/mails/welcome_email.txt b/users/templates/mails/welcome_email.txt new file mode 100644 index 0000000..cc11c79 --- /dev/null +++ b/users/templates/mails/welcome_email.txt @@ -0,0 +1,5 @@ +{{ reason }} + +Follow the link below to a page where you can set your password. + +{{ reset_url }}