remove email related code
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 9s
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 9s
This commit is contained in:
@@ -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
|
||||
# =============================================================================
|
||||
|
||||
@@ -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."))
|
||||
@@ -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()
|
||||
|
||||
@@ -1,102 +0,0 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="description" content="Instructions to reset your password." />
|
||||
<meta name="keywords" content="password, reset, email, instructions" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
|
||||
<title>Password Reset Email</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
background-color: #f5f5f5;
|
||||
margin: 0;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 600px;
|
||||
margin: 0 auto;
|
||||
background-color: #ffffff;
|
||||
border-radius: 8px;
|
||||
padding: 30px;
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.header {
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.logo {
|
||||
color: #2c3e50;
|
||||
font-size: 24px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.message {
|
||||
color: #6c757d;
|
||||
font-size: 16px;
|
||||
line-height: 1.5;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.footer {
|
||||
margin-top: 30px;
|
||||
color: #6c757d;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.button {
|
||||
display: inline-block;
|
||||
padding: 10px 20px;
|
||||
background-color: #007bff;
|
||||
color: #ffffff !important;
|
||||
text-decoration: none;
|
||||
border-radius: 5px;
|
||||
margin: 20px 0;
|
||||
}
|
||||
|
||||
.button:hover {
|
||||
background-color: #0056b3;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #007bff;
|
||||
text-decoration: underline;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<div class="logo">Password Reset Instructions</div>
|
||||
</div>
|
||||
|
||||
<p class="message">
|
||||
Hello {{ username }},
|
||||
</p>
|
||||
<p class="message">
|
||||
We received a request to reset your password. Click the button below to create a new password:
|
||||
</p>
|
||||
|
||||
<a href="{{ reset_password_url }}" class="button">Reset Password</a>
|
||||
|
||||
<p class="message">
|
||||
If the button doesn't work, you can copy and paste this link into your browser:
|
||||
<br>
|
||||
<a href="{{ reset_password_url }}">{{ reset_password_url }}</a>
|
||||
</p>
|
||||
|
||||
<p class="message">
|
||||
If you did not request this password reset, you can safely ignore
|
||||
this email.
|
||||
</p>
|
||||
|
||||
<p class="footer">Best regards,<br>SARLink</p>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -10,7 +10,6 @@ from .views import (
|
||||
ListUserView,
|
||||
UserDetailAPIView,
|
||||
healthcheck,
|
||||
test_email,
|
||||
ListAtollView,
|
||||
CreateAtollView,
|
||||
RetrieveUpdateDestroyAtollView,
|
||||
@@ -49,7 +48,6 @@ urlpatterns = [
|
||||
),
|
||||
path("users/<int:pk>/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(
|
||||
|
||||
@@ -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()
|
||||
|
||||
+1
-16
@@ -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",
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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")),
|
||||
|
||||
+2
-1
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user