mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-11-27 09:04:54 +00:00
changes
This commit is contained in:
38
account/utils.py
Normal file
38
account/utils.py
Normal file
@ -0,0 +1,38 @@
|
||||
"""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})
|
||||
Reference in New Issue
Block a user