mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-11-26 08:34:55 +00:00
Initial Commit
This commit is contained in:
31
zod_bank/account/utils.py
Normal file
31
zod_bank/account/utils.py
Normal file
@ -0,0 +1,31 @@
|
||||
from django.core.mail import send_mail
|
||||
from django.conf import settings
|
||||
import random
|
||||
from rest_framework import viewsets, status
|
||||
from rest_framework.response import Response
|
||||
def send_otp_email(recipient_email, otp):
|
||||
subject = 'One-Time Password'
|
||||
message = f'Your OTP is: {otp}'
|
||||
from_email = settings.DEFAULT_FROM_EMAIL
|
||||
recipient_list = [recipient_email]
|
||||
send_mail(subject, message, from_email, recipient_list)
|
||||
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