diff --git a/.env.example b/.env.example index beb5ada..218b65f 100644 --- a/.env.example +++ b/.env.example @@ -27,19 +27,6 @@ POSTGRES_PORT=5432 # ============================================================================= REDIS_HOST=redis -# ============================================================================= -# Frontend — used to build links in password-reset emails -# ============================================================================= -FRONTEND_URL="http://localhost:3000" - -# ============================================================================= -# Email / SMTP — password-reset and notification mail -# ============================================================================= -EMAIL_HOSTNAME="" -EMAIL_PORT= -EMAIL_USERNAME= -EMAIL_PASSWORD= - # ============================================================================= # SMS gateway — OTP + notifications # ============================================================================= diff --git a/api/management/__init__.py b/api/management/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/api/management/commands/__init__.py b/api/management/commands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/api/management/commands/seed.py b/api/management/commands/seed.py new file mode 100644 index 0000000..021e723 --- /dev/null +++ b/api/management/commands/seed.py @@ -0,0 +1,27 @@ +# api/management/commands/seed.py + +from django.core.management.base import BaseCommand +from api.models import Atoll, Island + + +class Command(BaseCommand): + help = "Seeds baseline reference data (atolls and islands) required for sign up." + + def handle(self, *args, **options): + atoll, atoll_created = Atoll.objects.get_or_create(name="Faafu") + self.stdout.write( + self.style.SUCCESS(f"Created atoll: {atoll.name}") + if atoll_created + else self.style.NOTICE(f"Atoll already exists: {atoll.name}") + ) + + island, island_created = Island.objects.get_or_create( + name="Dharanboodhoo", defaults={"atoll": atoll} + ) + self.stdout.write( + self.style.SUCCESS(f"Created island: {island.name} ({atoll.name})") + if island_created + else self.style.NOTICE(f"Island already exists: {island.name}") + ) + + self.stdout.write(self.style.SUCCESS("Seeding complete.")) diff --git a/api/signals.py b/api/signals.py index fcce786..8d3080b 100644 --- a/api/signals.py +++ b/api/signals.py @@ -1,8 +1,4 @@ -from django.core.mail import EmailMultiAlternatives from django.dispatch import receiver -from django.template.loader import render_to_string -from decouple import config -from django_rest_passwordreset.signals import reset_password_token_created from django.db.models.signals import post_save from api.models import User, TemporaryUser from django.contrib.auth.models import Permission @@ -44,44 +40,3 @@ def verify_user_with_person_api(sender, instance, created, **kwargs): if created: print(f"Temporary User Instance: {instance}") verify_user_with_person_api_task(instance.t_id) - - -@receiver(reset_password_token_created) -def password_reset_token_created( - sender, instance, reset_password_token, *args, **kwargs -): - """ - Handles password reset tokens - When a token is created, an e-mail needs to be sent to the user - :param sender: View Class that sent the signal - :param instance: View Instance that sent the signal - :param reset_password_token: Token Model Object - :param args: - :param kwargs: - :return: - """ - context = { - "current_user": reset_password_token.user, - "username": reset_password_token.user.username, - "email": reset_password_token.user.email, - "reset_password_url": f"{config('FRONTEND_URL')}/auth/reset-password-confirm/?token={reset_password_token.key}", - } - - # render email text - email_html_message = render_to_string("email/password_reset_email.html", context) - email_plaintext_message = ( - f"Here is your password reset link: {context['reset_password_url']}" - ) - - msg = EmailMultiAlternatives( - # title: - "Password Reset for {title}".format(title="Sarlink Portal"), - # message: - email_plaintext_message, # This is the plaintext version - # from: - "noreply@sarlink.net", - # to: - [reset_password_token.user.email], - ) - msg.attach_alternative(email_html_message, "text/html") - msg.send() diff --git a/api/templates/email/password_reset_email.html b/api/templates/email/password_reset_email.html deleted file mode 100644 index f183d56..0000000 --- a/api/templates/email/password_reset_email.html +++ /dev/null @@ -1,102 +0,0 @@ - - - -
- - - - - -