mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-08-26 06:09:41 +00:00
sonar issues
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
from django.contrib import admin
|
||||
|
||||
"""Import django app"""
|
||||
from .models import UserEmailOtp, UserPhoneOtp, DefaultTaskImages, UserNotification, UserDelete
|
||||
from .models import UserEmailOtp, DefaultTaskImages, UserNotification, UserDelete
|
||||
# Register your models here.
|
||||
|
||||
@admin.register(UserDelete)
|
||||
@ -37,11 +37,3 @@ class UserEmailOtpAdmin(admin.ModelAdmin):
|
||||
"""Return object in email and otp format"""
|
||||
return self.email + '-' + self.otp
|
||||
|
||||
@admin.register(UserPhoneOtp)
|
||||
class UserPhoneOtpAdmin(admin.ModelAdmin):
|
||||
"""User Phone otp admin"""
|
||||
list_display = ['phone']
|
||||
|
||||
def __str__(self):
|
||||
"""Return object in phone number and otp format"""
|
||||
return self.phone + '-' + self.otp
|
||||
|
@ -90,6 +90,8 @@ class DefaultTaskImages(models.Model):
|
||||
class Meta(object):
|
||||
""" Meta information """
|
||||
db_table = 'default_task_image'
|
||||
verbose_name = 'Default Task images'
|
||||
verbose_name_plural = 'Default Task images'
|
||||
|
||||
def __str__(self):
|
||||
"""return phone as an object"""
|
||||
@ -112,6 +114,8 @@ class UserDelete(models.Model):
|
||||
class Meta(object):
|
||||
""" Meta information """
|
||||
db_table = 'user_delete_information'
|
||||
verbose_name = 'Deleted User'
|
||||
verbose_name_plural = 'Deleted User'
|
||||
|
||||
def __str__(self):
|
||||
return self.user.email
|
||||
|
@ -183,13 +183,15 @@ def get_token(data: dict = dict):
|
||||
|
||||
|
||||
def generate_alphanumeric_code(length):
|
||||
"""Generate alphanumeric code"""
|
||||
alphabet = string.ascii_letters + string.digits
|
||||
code = ''.join(secrets.choice(alphabet) for _ in range(length))
|
||||
return code
|
||||
|
||||
|
||||
def generate_code(value, user_id):
|
||||
alphabet = value + user_id.zfill(3)
|
||||
return alphabet
|
||||
"""generate referral, junior and guardian code"""
|
||||
code = value + str(user_id).zfill(3)
|
||||
return code
|
||||
|
||||
|
||||
|
@ -25,10 +25,10 @@ from .serializers import (SuperUserSerializer, GuardianSerializer, JuniorSeriali
|
||||
UserNotificationSerializer, UpdateUserNotificationSerializer, UserPhoneOtpSerializer)
|
||||
from rest_framework_simplejwt.tokens import RefreshToken
|
||||
from base.messages import ERROR_CODE, SUCCESS_CODE
|
||||
from base.constants import NUMBER
|
||||
from base.constants import NUMBER, ZOD, JUN, GRD
|
||||
from guardian.tasks import generate_otp
|
||||
from account.utils import (send_otp_email, send_support_email, custom_response, custom_error_response,
|
||||
generate_alphanumeric_code)
|
||||
generate_code)
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from templated_email import send_templated_mail
|
||||
import google.oauth2.credentials
|
||||
@ -42,6 +42,7 @@ from guardian.serializers import GuardianProfileSerializer
|
||||
|
||||
class GoogleLoginMixin:
|
||||
"""google login mixin"""
|
||||
@staticmethod
|
||||
def google_login(self, request):
|
||||
"""google login function"""
|
||||
access_token = request.data.get('access_token')
|
||||
@ -90,15 +91,15 @@ class GoogleLoginMixin:
|
||||
if str(user_type) == '1':
|
||||
junior_query = Junior.objects.create(auth=user_obj, is_verified=True, is_active=True,
|
||||
image=profile_picture, signup_method='2',
|
||||
junior_code=generate_alphanumeric_code(6),
|
||||
referral_code=generate_alphanumeric_code(6)
|
||||
junior_code=generate_code(JUN, user_obj.id),
|
||||
referral_code=generate_code(ZOD, user_obj.id)
|
||||
)
|
||||
serializer = JuniorSerializer(junior_query)
|
||||
if str(user_type) == '2':
|
||||
guardian_query = Guardian.objects.create(user=user_obj, is_verified=True, is_active=True,
|
||||
image=profile_picture,signup_method='2',
|
||||
guardian_code=generate_alphanumeric_code(6),
|
||||
referral_code=generate_alphanumeric_code(6)
|
||||
guardian_code=generate_code(GRD, user_obj.id),
|
||||
referral_code=generate_code(ZOD, user_obj.id)
|
||||
)
|
||||
serializer = GuardianSerializer(guardian_query)
|
||||
# Return a JSON response with the user's email and name
|
||||
@ -141,14 +142,14 @@ class SigninWithApple(views.APIView):
|
||||
if str(user_type) == '1':
|
||||
junior_query = Junior.objects.create(auth=user, is_verified=True, is_active=True,
|
||||
signup_method='3',
|
||||
junior_code=generate_alphanumeric_code(6),
|
||||
referral_code=generate_alphanumeric_code(6))
|
||||
junior_code=generate_code(JUN, user.id),
|
||||
referral_code=generate_code(ZOD, user.id))
|
||||
serializer = JuniorSerializer(junior_query)
|
||||
if str(user_type) == '2':
|
||||
guardian_query = Guardian.objects.create(user=user, is_verified=True, is_active=True,
|
||||
signup_method='3',
|
||||
guardian_code=generate_alphanumeric_code(6),
|
||||
referral_code=generate_alphanumeric_code(6))
|
||||
guardian_code=generate_code(GRD, user.id),
|
||||
referral_code=generate_code(ZOD, user.id))
|
||||
serializer = GuardianSerializer(guardian_query)
|
||||
return custom_response(SUCCESS_CODE['3003'], serializer.data,
|
||||
response_status=status.HTTP_200_OK)
|
||||
@ -181,6 +182,7 @@ class UpdateProfileImage(views.APIView):
|
||||
return custom_response(SUCCESS_CODE['3017'], serializer.data, response_status=status.HTTP_200_OK)
|
||||
return custom_error_response(serializer.errors, response_status=status.HTTP_400_BAD_REQUEST)
|
||||
except Exception as e:
|
||||
logging.error(e)
|
||||
return custom_error_response(ERROR_CODE['2036'],response_status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
class ChangePasswordAPIView(views.APIView):
|
||||
@ -512,6 +514,7 @@ class SendSupportEmail(views.APIView):
|
||||
|
||||
|
||||
class LogoutAPIView(views.APIView):
|
||||
"""Log out API"""
|
||||
permission_classes = (IsAuthenticated,)
|
||||
|
||||
def post(self, request):
|
||||
|
Reference in New Issue
Block a user