mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-07-15 18:07:02 +00:00
39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
"""Account utils"""
|
|
"""Third party Django app"""
|
|
from django.conf import settings
|
|
from rest_framework import viewsets, status
|
|
from rest_framework.response import Response
|
|
|
|
from templated_email import send_templated_mail
|
|
def send_otp_email(recipient_email, otp):
|
|
from_email = settings.EMAIL_HOST_USER
|
|
recipient_list = [recipient_email]
|
|
send_templated_mail(
|
|
template_name='email_otp_verification.email',
|
|
from_email=from_email,
|
|
recipient_list=recipient_list,
|
|
context={
|
|
'otp': otp
|
|
}
|
|
)
|
|
return otp
|
|
|
|
def custom_response(detail, data=None, response_status=status.HTTP_200_OK):
|
|
"""Custom response code"""
|
|
if not data:
|
|
data = None
|
|
|
|
return Response({"data": data, "message": detail, "status": "success", "code": response_status})
|
|
|
|
|
|
def custom_error_response(detail, response_status):
|
|
"""
|
|
function is used for getting same global error response for all
|
|
:param detail: error message .
|
|
:param response_status: http status.
|
|
:return: Json response
|
|
"""
|
|
if not detail:
|
|
detail = {}
|
|
return Response({"error": detail, "status": "failed", "code": response_status})
|