diff --git a/account/templates/templated_email/support_mail.email b/account/templates/templated_email/support_mail.email new file mode 100644 index 0000000..50467a9 --- /dev/null +++ b/account/templates/templated_email/support_mail.email @@ -0,0 +1,22 @@ +{% extends "templated_email/email_base.email" %} + +{% block subject %} + {{subject}} +{% endblock %} + +{% block plain %} + + +

+ Hi {{name}}, +

+ + + + +

+ {{name}} have some queries and need some support. Please support them by using their email address {{sender}}.

Queries are:-
{{ message }} +

+ + +{% endblock %} diff --git a/account/urls.py b/account/urls.py index 6bfc8dd..3d4642f 100644 --- a/account/urls.py +++ b/account/urls.py @@ -8,7 +8,7 @@ from .views import (UserLogin, SendPhoneOtp, UserPhoneVerification, UserEmailVer ForgotPasswordAPIView, ResetPasswordAPIView, ChangePasswordAPIView, UpdateProfileImage, GoogleLoginViewSet, SigninWithApple, ProfileAPIViewSet, UploadImageAPIViewSet, DefaultImageAPIViewSet, DeleteUserProfileAPIViewSet, UserNotificationAPIViewSet, - UpdateUserNotificationAPIViewSet) + UpdateUserNotificationAPIViewSet, SendSupportEmail) """Router""" router = routers.SimpleRouter() @@ -36,6 +36,8 @@ router.register('delete', DeleteUserProfileAPIViewSet, basename='delete') router.register('user-notification', UserNotificationAPIViewSet, basename='user-notification') """update user account notification""" router.register('update-user-notification', UpdateUserNotificationAPIViewSet, basename='update-user-notification') +"""Support Email API""" +# router.register('support', SupportAPIViewSet, basename='update-user-notification') """Define url pattern""" urlpatterns = [ path('api/v1/', include(router.urls)), @@ -44,4 +46,5 @@ urlpatterns = [ path('api/v1/change-password/', ChangePasswordAPIView.as_view()), path('api/v1/update-profile-image/', UpdateProfileImage.as_view()), path('api/v1/apple-login/', SigninWithApple.as_view(), name='signup_with_apple'), + path('api/v1/send-support-email/', SendSupportEmail.as_view(), name='send-support-email') ] diff --git a/account/utils.py b/account/utils.py index af9f86b..ad91468 100644 --- a/account/utils.py +++ b/account/utils.py @@ -46,6 +46,22 @@ def send_otp_email(recipient_email, otp): ) return otp +def send_support_email(name, sender, subject, message): + """Send otp on email with template""" + to_email = [settings.EMAIL_FROM_ADDRESS] + from_email = settings.DEFAULT_ADDRESS + send_templated_mail( + template_name='support_mail.email', + from_email=from_email, + recipient_list=to_email, + context={ + 'name': name.title(), + 'sender': sender, + 'subject': subject, + 'message': message + } + ) + return name def custom_response(detail, data=None, response_status=status.HTTP_200_OK): """Custom response code""" if not data: diff --git a/account/views.py b/account/views.py index b5c0d26..12b0043 100644 --- a/account/views.py +++ b/account/views.py @@ -5,6 +5,7 @@ from rest_framework import viewsets, status, views from rest_framework.decorators import action import random import logging +from django.views.decorators.csrf import csrf_exempt from django.utils import timezone import jwt """App Import""" @@ -23,8 +24,7 @@ from .serializers import (SuperUserSerializer, GuardianSerializer, JuniorSeriali from rest_framework_simplejwt.tokens import RefreshToken from base.messages import ERROR_CODE, SUCCESS_CODE from guardian.tasks import generate_otp -from account.utils import send_otp_email -from account.utils import custom_response, custom_error_response +from account.utils import send_otp_email, send_support_email, custom_response, custom_error_response from rest_framework.permissions import IsAuthenticated from templated_email import send_templated_mail import google.oauth2.credentials @@ -461,3 +461,19 @@ class UpdateUserNotificationAPIViewSet(viewsets.ModelViewSet): serializer.save() return custom_response(None, serializer.data, response_status=status.HTTP_200_OK) return custom_error_response(serializer.error, response_status=status.HTTP_400_BAD_REQUEST) + + +class SendSupportEmail(views.APIView): + def post(self, request): + name = request.data.get('name') + sender = request.data.get('email') + subject = request.data.get('subject') + message = request.data.get('message') + if name and sender and subject and message: + try: + send_support_email(name, sender, subject, message) + return custom_response(SUCCESS_CODE['3019'], response_status=status.HTTP_200_OK) + except Exception as e: + return custom_error_response(str(e), response_status=status.HTTP_400_BAD_REQUEST) + else: + return custom_error_response(ERROR_CODE['2033'], response_status=status.HTTP_400_BAD_REQUEST) diff --git a/base/messages.py b/base/messages.py index 788c7bc..50ca7f0 100644 --- a/base/messages.py +++ b/base/messages.py @@ -54,7 +54,9 @@ ERROR_CODE = { "2028": "You are not authorized person to sign up on this platform", "2029": "Validity of otp verification is expired", "2030": "Use correct user type and token", - "2031":"Invalid password" + "2031": "Invalid password", + "2032": "Failed to send email", + "2033": "Missing required fields" } SUCCESS_CODE = { # Success code for password @@ -84,7 +86,8 @@ SUCCESS_CODE = { "3015": "Verification code sent on your email.", "3016": "Send otp on your Email successfully", "3017": "Profile image update successfully", - "3018": "Task created successfully" + "3018": "Task created successfully", + "3019": "Support Email sent successfully" } STATUS_CODE_ERROR = { diff --git a/guardian/views.py b/guardian/views.py index f55dd47..f8295a3 100644 --- a/guardian/views.py +++ b/guardian/views.py @@ -93,7 +93,7 @@ class TaskListAPIView(viewsets.ModelViewSet): """Create guardian profile""" status_value = self.request.GET.get('status') if str(status_value) == '0': - queryset = JuniorTask.objects.filter(guardian__user=request.user).order_by('created_at') + queryset = JuniorTask.objects.filter(guardian__user=request.user).order_by('due_date', 'created_at') else: queryset = JuniorTask.objects.filter(guardian__user=request.user, task_status=status_value).order_by('due_date','created_at') diff --git a/zod_bank/settings.py b/zod_bank/settings.py index 6f43fdc..595305a 100644 --- a/zod_bank/settings.py +++ b/zod_bank/settings.py @@ -209,6 +209,7 @@ EMAIL_USE_TLS="True" EMAIL_HOST_USER="apikey" EMAIL_HOST_PASSWORD="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" EMAIL_FROM_ADDRESS="support@zodbank.com" +DEFAULT_ADDRESS="zodbank@yopmail.com" ALIYUN_OSS_ACCESS_KEY_ID = os.getenv('ALIYUN_OSS_ACCESS_KEY_ID')