mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-08-25 13:49:40 +00:00
Merge pull request #4 from KiwiTechLLC/26june_sprint1
jira-9 changes in phone verification
This commit is contained in:
@ -13,6 +13,7 @@ from rest_framework.decorators import action
|
||||
from django.contrib.auth import authenticate, login
|
||||
from rest_framework_simplejwt.tokens import RefreshToken
|
||||
|
||||
|
||||
class ResetPasswordSerializer(serializers.Serializer):
|
||||
"""Reset Password after verification"""
|
||||
verification_code = serializers.CharField(max_length=10)
|
||||
@ -62,7 +63,6 @@ class ChangePasswordSerializer(serializers.Serializer):
|
||||
user_details.set_password(new_password)
|
||||
user_details.save()
|
||||
return {'password':new_password}
|
||||
return user_details
|
||||
return ''
|
||||
|
||||
|
||||
|
@ -11,7 +11,7 @@ router = routers.SimpleRouter()
|
||||
|
||||
"""API End points with router"""
|
||||
router.register('user', UserLogin, basename='user')
|
||||
router.register('superuser', UserLogin, basename='superuser')
|
||||
router.register('admin', UserLogin, basename='admin')
|
||||
router.register('send-phone-otp', SendPhoneOtp, basename='send-phone-otp')
|
||||
router.register('user-phone-verification', UserPhoneVerification, basename='user-phone-verification')
|
||||
router.register('user-email-verification', UserEmailVerification, basename='user-email-verification')
|
||||
|
@ -9,8 +9,6 @@ from django.contrib.auth.models import User
|
||||
from .serializers import (SuperUserSerializer, GuardianSerializer, JuniorSerializer, EmailVerificationSerializer,
|
||||
ForgotPasswordSerializer, ResetPasswordSerializer, ChangePasswordSerializer)
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from rest_framework_simplejwt.serializers import TokenObtainPairSerializer
|
||||
from rest_framework_simplejwt.views import TokenObtainPairView
|
||||
from rest_framework_simplejwt.tokens import RefreshToken
|
||||
from base.messages import ERROR_CODE, SUCCESS_CODE
|
||||
from guardian.tasks import generate_otp
|
||||
@ -21,14 +19,11 @@ from django.core.mail import send_mail
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from templated_email import send_templated_mail
|
||||
import secrets
|
||||
|
||||
|
||||
class ChangePasswordAPIView(views.APIView):
|
||||
permission_classes = [IsAuthenticated]
|
||||
def post(self, request):
|
||||
print("request.data====>",request.data)
|
||||
print("request.user====>", request.user)
|
||||
serializer = ChangePasswordSerializer(context=request.user, data=request.data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
@ -37,7 +32,6 @@ class ChangePasswordAPIView(views.APIView):
|
||||
|
||||
class ResetPasswordAPIView(views.APIView):
|
||||
def post(self, request):
|
||||
print("request.data====>",request.data)
|
||||
serializer = ResetPasswordSerializer(data=request.data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
@ -65,7 +59,10 @@ class ForgotPasswordAPIView(views.APIView):
|
||||
'verification_code': verification_code
|
||||
}
|
||||
)
|
||||
UserEmailOtp.objects.create(email=email, otp=verification_code)
|
||||
user_data = UserEmailOtp.objects.get_or_create(email=email)
|
||||
if user_data:
|
||||
user_data.otp = verification_code
|
||||
user_data.save()
|
||||
return custom_response(SUCCESS_CODE['3015'], {'verification_code': verification_code},
|
||||
response_status=status.HTTP_200_OK)
|
||||
return custom_error_response(serializer.errors, response_status=status.HTTP_400_BAD_REQUEST)
|
||||
@ -74,9 +71,15 @@ class SendPhoneOtp(viewsets.ModelViewSet):
|
||||
"""Send otp on phone"""
|
||||
def create(self, request, *args, **kwargs):
|
||||
otp = generate_otp()
|
||||
UserPhoneOtp.objects.create(country_code=self.request.data['country_code'],
|
||||
phone=self.request.data['phone'], otp=otp)
|
||||
return custom_response(None, {'phone_otp':otp}, response_status=status.HTTP_200_OK)
|
||||
phone_number = self.request.data['phone']
|
||||
if phone_number.isdigit() and len(phone_number) == 10:
|
||||
phone_otp, created = UserPhoneOtp.objects.get_or_create(country_code=self.request.data['country_code'],
|
||||
phone=self.request.data['phone'])
|
||||
if phone_otp:
|
||||
phone_otp.otp = otp
|
||||
phone_otp.save()
|
||||
return custom_response(None, {'phone_otp':otp}, response_status=status.HTTP_200_OK)
|
||||
return custom_error_response(ERROR_CODE['2020'], response_status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
|
||||
class UserPhoneVerification(viewsets.ModelViewSet):
|
||||
@ -88,7 +91,7 @@ class UserPhoneVerification(viewsets.ModelViewSet):
|
||||
if phone_data:
|
||||
phone_data.is_verified = True
|
||||
phone_data.save()
|
||||
return custom_response(SUCCESS_CODE['3027'], response_status=status.HTTP_200_OK)
|
||||
return custom_response(SUCCESS_CODE['3012'], response_status=status.HTTP_200_OK)
|
||||
else:
|
||||
return custom_error_response(ERROR_CODE["2008"], response_status=status.HTTP_400_BAD_REQUEST)
|
||||
except Exception as e:
|
||||
@ -132,8 +135,8 @@ class UserLogin(viewsets.ViewSet):
|
||||
email_verified.otp = otp
|
||||
email_verified.save()
|
||||
data.update({"email_otp":otp})
|
||||
return custom_response(ERROR_CODE['2024'], {"email_otp":otp, "is_email_verified": is_verified},
|
||||
response_status=status.HTTP_400_BAD_REQUEST)
|
||||
return custom_response(ERROR_CODE['2024'], {"email_otp": otp, "is_email_verified": is_verified},
|
||||
response_status=status.HTTP_200_OK)
|
||||
data.update({"is_email_verified": is_verified})
|
||||
return custom_response(None, data, response_status=status.HTTP_200_OK)
|
||||
|
||||
@ -159,7 +162,10 @@ class ReSendEmailOtp(viewsets.ModelViewSet):
|
||||
def create(self, request, *args, **kwargs):
|
||||
otp = generate_otp()
|
||||
if User.objects.filter(email=request.data['email']):
|
||||
UserEmailOtp.objects.create(email=request.data['email'], otp=otp)
|
||||
email_data = UserEmailOtp.objects.get_or_create(email=request.data['email'])
|
||||
if email_data:
|
||||
email_data.otp = otp
|
||||
email_data.save()
|
||||
return custom_response(None, {'email_otp': otp}, response_status=status.HTTP_200_OK)
|
||||
else:
|
||||
return custom_error_response(ERROR_CODE["2023"], response_status=status.HTTP_400_BAD_REQUEST)
|
||||
|
@ -14,8 +14,7 @@ SUPER_ADMIN = "Super Admin"
|
||||
JWT_TOKEN_EXPIRATION = 3 * 24 * 60
|
||||
|
||||
# Define common file extention
|
||||
FILE_EXTENSION = ("gif", "jpeg", "jpg", "png", "svg", "csv", "doc", "docx", "odt", "pdf", "rtf", "txt", "wks", "wp",
|
||||
"wpd")
|
||||
FILE_EXTENSION = ("gif", "jpeg", "jpg", "png", "svg")
|
||||
|
||||
# Define file size in bytes(5MB = 5 * 1024 * 1024)
|
||||
FILE_SIZE = 5 * 1024 * 1024
|
||||
@ -42,53 +41,6 @@ GUARDIAN = 'guardian'
|
||||
JUNIOR = 'junior'
|
||||
SUPERUSER = 'superuser'
|
||||
# numbers used as a constant
|
||||
NUMBER = {
|
||||
'point_zero': 0.0,
|
||||
'zero': 0,
|
||||
'one': 1,
|
||||
'two': 2,
|
||||
'three': 3,
|
||||
'four': 4,
|
||||
'five': 5,
|
||||
'six': 6,
|
||||
'seven': 7,
|
||||
'eight': 8,
|
||||
'nine': 9,
|
||||
'ten': 10,
|
||||
'eleven': 11,
|
||||
'twelve': 12,
|
||||
'thirteen': 13,
|
||||
'fourteen': 14,
|
||||
'fifteen': 15,
|
||||
'sixteen': 16,
|
||||
'seventeen': 17,
|
||||
'eighteen': 18,
|
||||
'nineteen': 19,
|
||||
'twenty_four': 24,
|
||||
'twenty_one': 21,
|
||||
'twenty_two': 22,
|
||||
'twenty_five': 25,
|
||||
'thirty': 30,
|
||||
'thirty_five': 35,
|
||||
'thirty_six': 36,
|
||||
'forty': 40,
|
||||
'fifty': 50,
|
||||
'fifty_nine': 59,
|
||||
'sixty': 60,
|
||||
'seventy_five': 75,
|
||||
'eighty': 80,
|
||||
'ninty_five': 95,
|
||||
'ninty_six': 96,
|
||||
'ninety_nine': 99,
|
||||
'hundred': 100,
|
||||
'one_one_nine': 119,
|
||||
'one_twenty': 120,
|
||||
'four_zero_four': 404,
|
||||
'five_hundred': 500,
|
||||
'minus_one': -1,
|
||||
'point_three': 0.3,
|
||||
'point_seven': 0.7
|
||||
}
|
||||
|
||||
# Define the byte into kb
|
||||
BYTE_IMAGE_SIZE = 1024
|
||||
|
@ -1,16 +0,0 @@
|
||||
"""
|
||||
module containing override conflict error class
|
||||
"""
|
||||
# third party imports
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from rest_framework import status
|
||||
from rest_framework.exceptions import APIException
|
||||
|
||||
|
||||
class ConflictError(APIException):
|
||||
"""
|
||||
Override conflict error
|
||||
"""
|
||||
status_code = status.HTTP_409_CONFLICT
|
||||
default_detail = _('Not allowed request.')
|
||||
default_code = 'conflict_error'
|
@ -1,49 +0,0 @@
|
||||
"""
|
||||
This module contains search methods that can be used to search over a particular field in a specific model.
|
||||
Update SEARCH_MAP dict for searching with model name and fields name
|
||||
"""
|
||||
# python imports
|
||||
import operator
|
||||
from functools import reduce
|
||||
|
||||
# third party imports
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.db.models import Q
|
||||
|
||||
SEARCH_MAP = {
|
||||
get_user_model(): {'search_fields': ['first_name__icontains', 'last_name__icontains', 'username__icontains']}
|
||||
}
|
||||
|
||||
|
||||
def search_query(search_by, search_term):
|
||||
"""
|
||||
:param search_by: search fields
|
||||
:param search_term: search value
|
||||
:return: return query
|
||||
"""
|
||||
query = []
|
||||
if search_by:
|
||||
for key in search_by:
|
||||
query.append({key: search_term})
|
||||
return query
|
||||
|
||||
|
||||
def get_search_fields(model):
|
||||
"""
|
||||
:param model: model name
|
||||
:return: dict of searching field name
|
||||
"""
|
||||
return SEARCH_MAP[model]['search_fields']
|
||||
|
||||
|
||||
def global_search(search_data, model_name):
|
||||
"""
|
||||
:param search_data: search value
|
||||
:param model_name: model name
|
||||
:return: query
|
||||
"""
|
||||
# get search fields for the above model
|
||||
search_fields = get_search_fields(model_name)
|
||||
# build query
|
||||
query = search_query(search_fields, search_data)
|
||||
return model_name.objects.filter(reduce(operator.or_, [Q(**x) for x in query]))
|
@ -16,8 +16,8 @@ from rest_framework.status import HTTP_400_BAD_REQUEST, HTTP_200_OK
|
||||
from base import constants
|
||||
from base.constants import NUMBER
|
||||
# local import
|
||||
from resourcekit.settings import base_settings as settings
|
||||
from resourcekit.settings.base_settings import BASE_DIR
|
||||
from zod_bank.settings import base_settings as settings
|
||||
from zod_bank.settings.base_settings import BASE_DIR
|
||||
|
||||
|
||||
def image_upload(folder, file_name, data):
|
||||
|
@ -13,7 +13,6 @@ class Guardian(models.Model):
|
||||
gender = models.CharField(choices=GENDERS, max_length=15, null=True, blank=True, default=None)
|
||||
dob = models.DateField(max_length=15, null=True, blank=True, default=None)
|
||||
guardian_code = models.CharField(max_length=10, null=True, blank=True, default=None)
|
||||
junior_code = ArrayField(models.CharField(max_length=10, null=True, blank=True, default=None),null=True)
|
||||
referral_code = models.CharField(max_length=10, null=True, blank=True, default=None)
|
||||
referral_code_used = models.CharField(max_length=10, null=True, blank=True, default=None)
|
||||
is_active = models.BooleanField(default=True)
|
||||
|
@ -11,7 +11,7 @@ router = routers.SimpleRouter()
|
||||
|
||||
"""API End points with router"""
|
||||
router.register('sign-up', SignupViewset, basename='sign-up')
|
||||
router.register('complete-guardian-profile', UpdateGuardianProfile, basename='update-guardian-profile')
|
||||
router.register('create-guardian-profile', UpdateGuardianProfile, basename='update-guardian-profile')
|
||||
urlpatterns = [
|
||||
path('api/v1/', include(router.urls)),
|
||||
]
|
||||
|
@ -10,7 +10,7 @@ from rest_framework import routers
|
||||
router = routers.SimpleRouter()
|
||||
|
||||
"""API End points with router"""
|
||||
router.register('complete-junior-profile', UpdateJuniorProfile, basename='profile-update')
|
||||
router.register('create-junior-profile', UpdateJuniorProfile, basename='profile-update')
|
||||
router.register('validate-guardian-code', ValidateGuardianCode, basename='validate-guardian-code')
|
||||
urlpatterns = [
|
||||
path('api/v1/', include(router.urls)),
|
||||
|
@ -25,7 +25,7 @@ class UpdateJuniorProfile(viewsets.ViewSet):
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return custom_response(None, serializer.data, response_status=status.HTTP_200_OK)
|
||||
return custom_error_response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
||||
return custom_error_response(serializer.errors, response_status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
class ValidateGuardianCode(viewsets.ViewSet):
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
@ -23,8 +23,12 @@ django-celery-results==2.5.1
|
||||
django-cors-headers==4.1.0
|
||||
django-dotenv==1.4.2
|
||||
django-extensions==3.2.3
|
||||
django-phonenumber-field==7.1.0
|
||||
django-render-block==0.9.2
|
||||
django-ses==3.5.0
|
||||
django-smtp-ssl==1.0
|
||||
django-storages==1.13.2
|
||||
django-templated-email==3.0.1
|
||||
django-timezone-field==5.1
|
||||
djangorestframework==3.14.0
|
||||
djangorestframework-simplejwt==5.2.2
|
||||
@ -34,6 +38,7 @@ jmespath==0.10.0
|
||||
kombu==5.3.1
|
||||
msgpack==1.0.5
|
||||
packaging==23.1
|
||||
phonenumbers==8.13.15
|
||||
prompt-toolkit==3.0.38
|
||||
psycopg==3.1.9
|
||||
pycparser==2.21
|
||||
|
Reference in New Issue
Block a user