mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-07-15 01:55:21 +00:00
Support email
This commit is contained in:
22
account/templates/templated_email/support_mail.email
Normal file
22
account/templates/templated_email/support_mail.email
Normal file
@ -0,0 +1,22 @@
|
||||
{% extends "templated_email/email_base.email" %}
|
||||
|
||||
{% block subject %}
|
||||
{{subject}}
|
||||
{% endblock %}
|
||||
|
||||
{% block plain %}
|
||||
<tr>
|
||||
<td style="padding: 0 27px 15px;">
|
||||
<p style="margin: 0; font-size: 16px; line-height: 20px; padding: 36px 0 0; font-weight: 500; color: #1f2532;">
|
||||
Hi {{name}},
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding: 0 27px 22px;">
|
||||
<p style="margin: 0;font-size: 14px; font-weight: 400; line-height: 21px; color: #1f2532;">
|
||||
<b>{{name}}</b> have some queries and need some support. Please support them by using their email address <b> {{sender}}</b>. <br> <br> <b>Queries are:- </b> <br> {{ message }}
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
{% endblock %}
|
@ -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')
|
||||
]
|
||||
|
@ -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:
|
||||
|
@ -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)
|
||||
|
@ -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 = {
|
||||
|
@ -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')
|
||||
|
@ -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')
|
||||
|
Reference in New Issue
Block a user