From ab501dca397a30fdf46551ee20974ce5663d5346 Mon Sep 17 00:00:00 2001 From: MaxIsJoe <34368774+MaxIsJoe@users.noreply.github.com> Date: Sun, 21 Jan 2024 21:24:47 +0200 Subject: [PATCH] email --- src/accounts/api/views.py | 13 +++++++++++++ src/central_command/settings.py | 1 + 2 files changed, 14 insertions(+) diff --git a/src/accounts/api/views.py b/src/accounts/api/views.py index 1d60933..1bf0013 100644 --- a/src/accounts/api/views.py +++ b/src/accounts/api/views.py @@ -1,6 +1,8 @@ from uuid import uuid4 +from central_command import settings from django.core.exceptions import ObjectDoesNotExist, PermissionDenied +from django.core.mail import send_mail from knox.models import AuthToken from knox.views import LoginView as KnoxLoginView from rest_framework import status @@ -225,4 +227,15 @@ def post(self, request): return Response(data={"detail": "Operation Done."}, status=status.HTTP_200_OK) serializer.save() + send_mail( + "Password Reset Request", + "A password reset request has been made for your account.\n" + + "Please visit the following link to reset your password: " + + settings.APP_URL + + serializer.data["token"] + + "\n\nIf you have not made this request, please ignore this email. The link will expire within 35 minutes.", + settings.EMAIL_FROM_ADDRESS, + [serializer.data["account"].email], + fail_silently=False, + ) return Response(data={"detail": "Operation Done."}, status=status.HTTP_200_OK) diff --git a/src/central_command/settings.py b/src/central_command/settings.py index 4d5a060..173356d 100644 --- a/src/central_command/settings.py +++ b/src/central_command/settings.py @@ -123,6 +123,7 @@ EMAIL_ADDRESS = os.environ.get("EMAIL_HOST_USER") EMAIL_FROM_ADDRESS = os.environ.get("EMAIL_HOST_USER") EMAIL_PASSWORD = os.environ.get("EMAIL_HOST_PASSWORD") +EMAIL_PASSWORD_RESET = os.environ.get("WEBSITE_URL", "https://unitystation.org/reset-password/") EMAIL_MAIL_SUBJECT = "Confirm your Unitystation account" EMAIL_MAIL_HTML = "registration/confirmation_email.html" EMAIL_PAGE_TEMPLATE = "confirm_template.html"