From c49bba17ea5033880ae06b95601ccf10266be847 Mon Sep 17 00:00:00 2001 From: Nilanchal Panigrahy Date: Wed, 20 Dec 2023 23:41:41 +0000 Subject: [PATCH 1/2] Added account activation email and sending email reminders --- .../send_account_activation_reminders.py | 48 ++ bloggy/management/commands/send_card.py | 51 ++ bloggy/services/email_service.py | 4 +- bloggy/services/token_service.py | 4 +- bloggy/templates/email/acc_active_email.html | 520 ---------------- .../email/account_activation_email.html | 350 +++++++++++ .../account_activation_reminder_email.html | 362 +++++++++++ bloggy/templates/email/wish_card_email.html | 562 ++++++++++++++++++ bloggy/templates/pages/archive/posts.html | 4 +- bloggy/templates/pages/single/course.html | 1 + bloggy/templates/pages/single/lesson.html | 4 +- bloggy/templates/pages/single/quiz.html | 2 +- bloggy/templates/partials/header.html | 2 +- bloggy/templates/seo/header_scripts.html | 4 +- bloggy/views/register.py | 2 +- bloggy_frontend/assets/logo-santa.png | Bin 0 -> 39642 bytes 16 files changed, 1390 insertions(+), 530 deletions(-) create mode 100644 bloggy/management/commands/send_account_activation_reminders.py create mode 100644 bloggy/management/commands/send_card.py delete mode 100644 bloggy/templates/email/acc_active_email.html create mode 100644 bloggy/templates/email/account_activation_email.html create mode 100644 bloggy/templates/email/account_activation_reminder_email.html create mode 100644 bloggy/templates/email/wish_card_email.html create mode 100644 bloggy_frontend/assets/logo-santa.png diff --git a/bloggy/management/commands/send_account_activation_reminders.py b/bloggy/management/commands/send_account_activation_reminders.py new file mode 100644 index 0000000..a9e5607 --- /dev/null +++ b/bloggy/management/commands/send_account_activation_reminders.py @@ -0,0 +1,48 @@ +from django.core.management.base import BaseCommand +from django.urls import reverse + +from bloggy import settings +from bloggy.services import email_service +from bloggy.services.token_service import create_token +from bloggy.models import User + + +class Command(BaseCommand): + help = 'Send email reminders to users who have not activated their accounts' + + def handle(self, *args, **kwargs): + # Get a list of users who have not activated their accounts + inactive_users = User.objects.filter(is_active=False) + # inactive_users = User.objects.filter(email="nilanchala.p2007@gmail.com") + + email_count = 0 + for user in inactive_users: + subject = 'Reminder: Verify your email to activate your account' + + verification_token = create_token(user=user, token_type="signup") + verification_link = reverse("activate_account", args=[ + verification_token.uuid, + verification_token.token + ]) + + args = { + "email_subject": subject, + "app_name": settings.SITE_TITLE, + "verification_link": settings.SITE_URL + verification_link + } + + try: + email_service.send_custom_email( + subject, + [user.email], + "email/account_activation_reminder_email.html", + args) + print('Success: Account activation reminder mail sent to {}', user.email) + + except Exception as ex: + print('Error: sending email to {}: {}', user.email, ex) + + finally: + email_count = email_count + 1 + + self.stdout.write(self.style.SUCCESS(f"Reminder sent to {email_count} users")) diff --git a/bloggy/management/commands/send_card.py b/bloggy/management/commands/send_card.py new file mode 100644 index 0000000..9552874 --- /dev/null +++ b/bloggy/management/commands/send_card.py @@ -0,0 +1,51 @@ +from django.core.management.base import BaseCommand +from bloggy import settings +from bloggy.models.subscriber import Subscribers +from bloggy.services import email_service +from bloggy.models import User +from itertools import chain + + +# python3 manage.py send_card --cardImgUrl="https://media.stacktips.com/media/emails/christmas-card.gif" --subject="Merry Christmas." --targetLink="https://stacktips.com" +class Command(BaseCommand): + help = 'Send wish card to users' + + def add_arguments(self, parser): + parser.add_argument('--cardImgUrl', type=str, required=True, help='URL of the card') + parser.add_argument('--subject', type=str, required=True, help='Email subject') + parser.add_argument('--targetLink', type=str, required=True, help='Target link') + + def handle(self, *args, **options): + card_img_url = options['cardImgUrl'] + subject = options['subject'] + target_link = options['targetLink'] + + if card_img_url is None or target_link is None or subject is None: + self.stdout.write( + self.style.ERROR(f"Missing mandatory arguments --cardImgUrl or --subject or --targetLink")) + + else: + users = chain( + User.objects.all(), + Subscribers.objects.all(), + ) + + email_count = 0 + for user in users: + args = { + "user_name": user.name, + "email_subject": subject, + "app_name": settings.SITE_TITLE, + "card_img_url": card_img_url, + "card_target_link": target_link + } + + try: + email_service.send_custom_email(subject, [user.email], "email/wish_card_email.html", args) + print('Success: Card sent to {}', user.email) + except Exception as ex: + print('Error sending card to {}: {}', user.email, ex) + finally: + email_count = email_count + 1 + + self.stdout.write(self.style.SUCCESS(f"Reminder sent to {email_count} users")) diff --git a/bloggy/services/email_service.py b/bloggy/services/email_service.py index a0a556f..28c324c 100644 --- a/bloggy/services/email_service.py +++ b/bloggy/services/email_service.py @@ -40,7 +40,7 @@ def email_verification_token(request, new_user, token): send_custom_email(subject, [new_user.email], "email/login_code_email.html", args) -def email_registration_token(request, new_user, verification_token): +def send_account_activation_email(request, new_user, verification_token): subject = f'Welcome to {settings.SITE_TITLE}!' args = { "email_subject": subject, @@ -52,4 +52,4 @@ def email_registration_token(request, new_user, verification_token): ])) } - send_custom_email(subject, [new_user.email], "email/acc_active_email.html", args) + send_custom_email(subject, [new_user.email], "email/account_activation_email.html", args) \ No newline at end of file diff --git a/bloggy/services/token_service.py b/bloggy/services/token_service.py index 347f98a..ba08e71 100644 --- a/bloggy/services/token_service.py +++ b/bloggy/services/token_service.py @@ -11,7 +11,9 @@ def create_token(user, token_type): """ - Generate token:: Token and uuid will be generated automatically + Generate token:: Token and uuid will be generated automatically, + + if expired, it will automatically renew new token. """ token = VerificationToken.objects.filter(user=user, token_type=token_type).first() if token: diff --git a/bloggy/templates/email/acc_active_email.html b/bloggy/templates/email/acc_active_email.html deleted file mode 100644 index 1ddf2db..0000000 --- a/bloggy/templates/email/acc_active_email.html +++ /dev/null @@ -1,520 +0,0 @@ - - - - Welcome to StackTips - - - - - - - - - - - - - -
- -
- - - - - - -
- -
- - - - - - -
-
-
- Hey, {{ user_name }} -
- -
- Welcome to StackTips! -
-
-
-
- -
-
- -
- - - - - - -
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- Thank you for signing up and we are really excited to welcome you! -
-
-
- Click on the link below to complete your registration and get started! -
-
- - - - - - -
- Complete registration -
-
-
- Here is what you can do with your free account! -
-
- -
- -
- -
-
- Explore the unlimited learning opportunities! -
-
-
- Happy learning! -
-
-
- Team StackTips -
-
- - - - - - - -
- - - - - - -
- - twitter-logo - -
-
- - - - - - - -
- - - - - - -
- - facebook-logo - -
-
- - - - - - - -
- - - - - - -
- - github-logo - -
-
- - - - - - -
- - - - - - -
- - instagram-logo - -
-
- -
-
- -
-
- -
- - - - - - -
- -
- - - - - - - - - -
-

-

- -
-
- Have questions or need help? Email us at - hello@stacktips.com -
-
-
- -
-
- -
- - - - - - -
- -
- - - - - - -
- -
- -
-
- -
-
- -
- - \ No newline at end of file diff --git a/bloggy/templates/email/account_activation_email.html b/bloggy/templates/email/account_activation_email.html new file mode 100644 index 0000000..40b51f1 --- /dev/null +++ b/bloggy/templates/email/account_activation_email.html @@ -0,0 +1,350 @@ + + + +{{ email_subject }} + + + + + + + + + + + + + + + + + + + + +
+ +
+ \ No newline at end of file diff --git a/bloggy/templates/email/account_activation_reminder_email.html b/bloggy/templates/email/account_activation_reminder_email.html new file mode 100644 index 0000000..3d77408 --- /dev/null +++ b/bloggy/templates/email/account_activation_reminder_email.html @@ -0,0 +1,362 @@ + + + +{{ email_subject }} + + + + + + + + + + + + + + + + + + + + +
+ +
+ \ No newline at end of file diff --git a/bloggy/templates/email/wish_card_email.html b/bloggy/templates/email/wish_card_email.html new file mode 100644 index 0000000..17eb347 --- /dev/null +++ b/bloggy/templates/email/wish_card_email.html @@ -0,0 +1,562 @@ + + + + {{ email_subject }} + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ + + + + + + + + + + + +
+
+ + \ No newline at end of file diff --git a/bloggy/templates/pages/archive/posts.html b/bloggy/templates/pages/archive/posts.html index 328815e..d7e5362 100644 --- a/bloggy/templates/pages/archive/posts.html +++ b/bloggy/templates/pages/archive/posts.html @@ -20,7 +20,7 @@
{% include "partials/post_list_item.html" with post=post cssClass="card-rounded" %}
- {% if forloop.counter == 3 %} + {% if forloop.counter|divisibleby:3 %} {% include "widgets/ad-unit-in-feed.html" %} {% endif %} {% if forloop.counter == 2 %} @@ -37,6 +37,8 @@ diff --git a/bloggy/templates/pages/single/course.html b/bloggy/templates/pages/single/course.html index 6ff1963..d397a48 100644 --- a/bloggy/templates/pages/single/course.html +++ b/bloggy/templates/pages/single/course.html @@ -91,6 +91,7 @@

{% include 'widgets/ad-unit-vertical-responsive.html' %} + {% related_quizzes_widget limit=5 widget_title="Related Quizzes" %} {% endwith %} diff --git a/bloggy/templates/pages/single/lesson.html b/bloggy/templates/pages/single/lesson.html index 4deec4e..10958d8 100644 --- a/bloggy/templates/pages/single/lesson.html +++ b/bloggy/templates/pages/single/lesson.html @@ -59,9 +59,9 @@ {% include 'widgets/ad-unit-vertical-responsive.html' %} {% include 'partials/video_widget.html' %} {% include "partials/home_widget_contribute_cta.html" %} - {% include 'partials/newsletter.html' %} {% include 'partials/github_widget.html' with githubLink=post.github_link %} - {% related_quizzes_widget limit=15 widget_title="Related Quizzes" %} + {% related_quizzes_widget limit=5 widget_title="Related Quizzes" %} + {% include 'widgets/ad-unit-vertical-responsive.html' %} diff --git a/bloggy/templates/pages/single/quiz.html b/bloggy/templates/pages/single/quiz.html index 7cbb4f0..53dc9af 100644 --- a/bloggy/templates/pages/single/quiz.html +++ b/bloggy/templates/pages/single/quiz.html @@ -46,7 +46,7 @@

Related quizzes

- {% related_quizzes_widget limit=15 widget_title=widget_title widget_style="grid" %} + {% related_quizzes_widget limit=5 widget_title=widget_title widget_style="grid" %} {% endblock %} diff --git a/bloggy/templates/partials/header.html b/bloggy/templates/partials/header.html index b664f3b..24f0644 100644 --- a/bloggy/templates/partials/header.html +++ b/bloggy/templates/partials/header.html @@ -6,7 +6,7 @@