From 00d25698c687e18d25ee69ea83b5c79099d757c4 Mon Sep 17 00:00:00 2001 From: Shihaam Abdul Rahman Date: Sun, 2 Aug 2026 14:25:41 +0500 Subject: [PATCH] remove email related code --- .env.example | 13 --- api/management/__init__.py | 0 api/management/commands/__init__.py | 0 api/management/commands/seed.py | 27 +++++ api/signals.py | 45 -------- api/templates/email/password_reset_email.html | 102 ------------------ api/urls.py | 2 - api/views.py | 14 --- apibase/settings.py | 17 +-- apibase/urls.py | 4 - compose.yml | 3 +- requirements.txt | 2 - 12 files changed, 30 insertions(+), 199 deletions(-) create mode 100644 api/management/__init__.py create mode 100644 api/management/commands/__init__.py create mode 100644 api/management/commands/seed.py delete mode 100644 api/templates/email/password_reset_email.html 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 @@ - - - - - - - - - - Password Reset Email - - - - -
-
- -
- -

- Hello {{ username }}, -

-

- We received a request to reset your password. Click the button below to create a new password: -

- - Reset Password - -

- If the button doesn't work, you can copy and paste this link into your browser: -
- {{ reset_password_url }} -

- -

- If you did not request this password reset, you can safely ignore - this email. -

- - -
- - - \ No newline at end of file diff --git a/api/urls.py b/api/urls.py index 3805b3d..5415739 100644 --- a/api/urls.py +++ b/api/urls.py @@ -10,7 +10,6 @@ from .views import ( ListUserView, UserDetailAPIView, healthcheck, - test_email, ListAtollView, CreateAtollView, RetrieveUpdateDestroyAtollView, @@ -49,7 +48,6 @@ urlpatterns = [ ), path("users//reject/", UserRejectAPIView.as_view(), name="user-reject"), path("healthcheck/", healthcheck, name="healthcheck"), - path("test/", test_email, name="testemail"), path("atolls/", ListAtollView.as_view(), name="atolls"), path("atolls/new/", CreateAtollView.as_view(), name="atoll-new"), path( diff --git a/api/views.py b/api/views.py index 9df2061..85efbf2 100644 --- a/api/views.py +++ b/api/views.py @@ -29,7 +29,6 @@ from knox.views import LoginView as KnoxLoginView from knox.models import AuthToken from django_filters.rest_framework import DjangoFilterBackend from typing import cast, Dict, Any -from django.core.mail import send_mail from django.db.models import Q from api.notifications import send_otp from .utils import check_person_api_verification @@ -550,19 +549,6 @@ class UserDetailAPIView(StaffEditorPermissionMixin, generics.RetrieveAPIView): return Response(data) -@api_view(["POST"]) -@permission_classes((permissions.AllowAny,)) -def test_email(request): - send_mail( - "Subject here", - "Here is the message.", - "noreply@sarlink.net", - ["shihaam@shihaam.me"], - fail_silently=False, - ) - return Response({"status": "ok"}, status=status.HTTP_200_OK) - - class CreateAtollView(StaffEditorPermissionMixin, generics.CreateAPIView): serializer_class = AtollSerializer queryset = Atoll.objects.all() diff --git a/apibase/settings.py b/apibase/settings.py index 06dd21b..cf1f363 100644 --- a/apibase/settings.py +++ b/apibase/settings.py @@ -52,10 +52,8 @@ INSTALLED_APPS = [ "django.contrib.sessions", "django.contrib.messages", "rest_framework", - "django_rest_passwordreset", "djangopasswordlessknox", "django_extensions", - "django_seed", "storages", "whitenoise.runserver_nostatic", "django.contrib.staticfiles", @@ -339,24 +337,11 @@ logging.config.dictConfig( ) -EMAIL_BACKEND = ( - "django.core.mail.backends.smtp.EmailBackend" # Replace with your preferred backend -) -EMAIL_HOST = env("EMAIL_HOSTNAME", default="") # type: ignore -EMAIL_PORT = env("EMAIL_PORT", cast=int, default=25) # type: ignore -EMAIL_HOST_USER = env("EMAIL_USERNAME", default="") # type: ignore -EMAIL_HOST_PASSWORD = env("EMAIL_PASSWORD", default="") # type: ignore -# DEFAULT_FROM_EMAIL = "noreply@sarlink.net" -EMAIL_USE_TLS = True - - PASSWORDLESS_AUTH = { - # 'PASSWORDLESS_EMAIL_TOKEN_HTML_TEMPLATE_NAME': "password_reset_email.html", - "PASSWORDLESS_AUTH_TYPES": ["EMAIL", "MOBILE"], + "PASSWORDLESS_AUTH_TYPES": ["MOBILE"], "PASSWORDLESS_USER_MOBILE_FIELD_NAME": "mobile", "PASSWORDLESS_TEST_SUPPRESSION": False, "PASSWORDLESS_REGISTER_NEW_USERS": True, - "PASSWORDLESS_EMAIL_NOREPLY_ADDRESS": "noreply@sarlink.net", } diff --git a/apibase/urls.py b/apibase/urls.py index 7f1763a..3bdc0c8 100644 --- a/apibase/urls.py +++ b/apibase/urls.py @@ -27,10 +27,6 @@ from drf_spectacular.views import ( urlpatterns = [ path("admin/", admin.site.urls), - path( - "api/password_reset/", - include("django_rest_passwordreset.urls", namespace="password_reset"), - ), path("", include("djangopasswordlessknox.urls")), # Authentication path("api/auth/", include("api.urls")), diff --git a/compose.yml b/compose.yml index 99f9d2e..b709b83 100644 --- a/compose.yml +++ b/compose.yml @@ -6,7 +6,8 @@ services: volumes: - ./:/app ports: - - 5000:5000 + # host 8000 -> container 5000 (host :5000 is taken by the local macvendor-api) + - 8000:5000 env_file: - .env depends_on: diff --git a/requirements.txt b/requirements.txt index fd928b7..263275f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -36,8 +36,6 @@ django-extensions==3.2.3 django-filter==23.5 django-redis==5.4.0 django-rest-knox==4.2.0 -django-rest-passwordreset==1.5.0 -django-seed==0.3.1 django-storages==1.14.4 django-stubs==5.1.1 django-stubs-ext==5.1.1