mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-07-15 18:07:02 +00:00
jira-25 setting API
This commit is contained in:
@ -0,0 +1,21 @@
|
||||
# Generated by Django 4.2.2 on 2023-07-11 11:26
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('account', '0005_usernotification'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name='useremailotp',
|
||||
options={'verbose_name': 'User Email OTP', 'verbose_name_plural': 'User Email OTP'},
|
||||
),
|
||||
migrations.AlterModelOptions(
|
||||
name='usernotification',
|
||||
options={'verbose_name': 'User Notification', 'verbose_name_plural': 'User Notification'},
|
||||
),
|
||||
]
|
@ -10,7 +10,7 @@ from junior.models import Junior
|
||||
from account.models import UserEmailOtp, DefaultTaskImages, UserDelete, UserNotification, UserPhoneOtp
|
||||
from base.constants import GUARDIAN, JUNIOR, SUPERUSER
|
||||
from base.messages import ERROR_CODE_REQUIRED, ERROR_CODE, SUCCESS_CODE, STATUS_CODE_ERROR
|
||||
from .utils import junior_account_update, guardian_account_update
|
||||
from .utils import delete_user_account_condition_social, delete_user_account_condition
|
||||
|
||||
class GoogleLoginSerializer(serializers.Serializer):
|
||||
"""google login serializer"""
|
||||
@ -231,26 +231,17 @@ class UserDeleteSerializer(serializers.ModelSerializer):
|
||||
user_type = str(self.context['user_type'])
|
||||
data = validated_data.get('reason')
|
||||
passwd = self.context['password']
|
||||
random_num = random.randint(0,10000)
|
||||
signup_method = self.context['signup_method']
|
||||
random_num = random.randint(0, 10000)
|
||||
user_tb = User.objects.filter(id=user.id).last()
|
||||
if user_tb and user_tb.check_password(passwd):
|
||||
user_type_data = UserEmailOtp.objects.filter(email=user.email).last()
|
||||
if user_type == '1' and user_type_data.user_type == '1':
|
||||
junior_account_update(user_tb)
|
||||
elif user_type == '2' and user_type_data.user_type == '2':
|
||||
guardian_account_update(user_tb)
|
||||
else:
|
||||
raise serializers.ValidationError({"details":ERROR_CODE['2030'],"code":"400", "status":"failed"})
|
||||
user_tb.email = str(random_num) + str('@D_') + '{}'.format(user_tb.username).lower()
|
||||
user_tb.username = str(random_num) + str('@D_') + '{}'.format(user_tb.username).lower()
|
||||
user_tb.password = 'None'
|
||||
d_email = user_tb.email
|
||||
o_mail = user.email
|
||||
instance = UserDelete.objects.create(user=user_tb, d_email=d_email, old_email=o_mail,
|
||||
is_active=True, reason=data)
|
||||
user_tb.save()
|
||||
|
||||
user_type_datas = UserEmailOtp.objects.filter(email=user.email).last()
|
||||
if user_tb and user_tb.check_password(passwd) and signup_method == '1':
|
||||
user_type_data = user_type_datas.user_type
|
||||
instance = delete_user_account_condition(user, user_type_data, user_type, user_tb, data, random_num)
|
||||
return instance
|
||||
elif user_tb and passwd is None and signup_method in ['2','3']:
|
||||
inst = delete_user_account_condition_social(user, user_type, user_tb, data, random_num)
|
||||
return inst
|
||||
else:
|
||||
raise serializers.ValidationError({"details": ERROR_CODE['2031'], "code": "400", "status": "failed"})
|
||||
|
||||
|
@ -10,8 +10,50 @@ from datetime import datetime
|
||||
from calendar import timegm
|
||||
from uuid import uuid4
|
||||
import secrets
|
||||
from rest_framework import serializers
|
||||
from junior.models import Junior
|
||||
from guardian.models import Guardian
|
||||
from account.models import UserDelete
|
||||
from base.messages import ERROR_CODE
|
||||
|
||||
|
||||
def delete_user_account_condition(user, user_type_data, user_type, user_tb, data, random_num):
|
||||
"""delete user account"""
|
||||
if user_type == '1' and user_type_data == '1':
|
||||
junior_account_update(user_tb)
|
||||
elif user_type == '2' and user_type_data == '2':
|
||||
guardian_account_update(user_tb)
|
||||
else:
|
||||
raise serializers.ValidationError({"details": ERROR_CODE['2030'], "code": "400", "status": "failed"})
|
||||
user_tb.email = str(random_num) + str('@D_') + '{}'.format(user_tb.username).lower()
|
||||
user_tb.username = str(random_num) + str('@D_') + '{}'.format(user_tb.username).lower()
|
||||
user_tb.password = 'None'
|
||||
d_email = user_tb.email
|
||||
o_mail = user.email
|
||||
user_tb.save()
|
||||
instance = UserDelete.objects.create(user=user_tb, d_email=d_email, old_email=o_mail,
|
||||
is_active=True, reason=data)
|
||||
|
||||
return instance
|
||||
|
||||
def delete_user_account_condition_social(user, user_type,user_tb, data, random_num):
|
||||
"""delete user account"""
|
||||
if user_type == '1':
|
||||
junior_account_update(user_tb)
|
||||
elif user_type == '2':
|
||||
guardian_account_update(user_tb)
|
||||
else:
|
||||
raise serializers.ValidationError({"details": ERROR_CODE['2030'], "code": "400", "status": "failed"})
|
||||
user_tb.email = str(random_num) + str('@D_') + '{}'.format(user_tb.username).lower()
|
||||
user_tb.username = str(random_num) + str('@D_') + '{}'.format(user_tb.username).lower()
|
||||
user_tb.password = 'None'
|
||||
d_email = user_tb.email
|
||||
o_mail = user.email
|
||||
user_tb.save()
|
||||
instance = UserDelete.objects.create(user=user_tb, d_email=d_email, old_email=o_mail,
|
||||
is_active=True, reason=data)
|
||||
|
||||
return instance
|
||||
def junior_account_update(user_tb):
|
||||
"""junior account delete"""
|
||||
junior_data = Junior.objects.filter(auth__email=user_tb.email).first()
|
||||
|
@ -85,11 +85,11 @@ class GoogleLoginMixin:
|
||||
user_obj = User.objects.create(username=email, email=email, first_name=first_name, last_name=last_name)
|
||||
if str(user_type) == '1':
|
||||
junior_query = Junior.objects.create(auth=user_obj, is_verified=True, is_active=True,
|
||||
image=profile_picture)
|
||||
image=profile_picture, signup_method='2')
|
||||
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)
|
||||
image=profile_picture,signup_method='2')
|
||||
serializer = GuardianSerializer(guardian_query)
|
||||
# Return a JSON response with the user's email and name
|
||||
return custom_response(SUCCESS_CODE['3003'], serializer.data,
|
||||
@ -127,10 +127,12 @@ class SigninWithApple(views.APIView):
|
||||
except User.DoesNotExist:
|
||||
user = User.objects.create(**user_data)
|
||||
if str(user_type) == '1':
|
||||
junior_query = Junior.objects.create(auth=user, is_verified=True, is_active=True)
|
||||
junior_query = Junior.objects.create(auth=user, is_verified=True, is_active=True,
|
||||
signup_method='3')
|
||||
serializer = JuniorSerializer(junior_query)
|
||||
if str(user_type) == '2':
|
||||
guardian_query = Guardian.objects.create(user=user, is_verified=True, is_active=True)
|
||||
guardian_query = Guardian.objects.create(user=user, is_verified=True, is_active=True,
|
||||
signup_method='3')
|
||||
serializer = GuardianSerializer(guardian_query)
|
||||
return custom_response(SUCCESS_CODE['3003'], serializer.data,
|
||||
response_status=status.HTTP_200_OK)
|
||||
@ -385,11 +387,13 @@ class ProfileAPIViewSet(viewsets.ModelViewSet):
|
||||
junior_data = Junior.objects.filter(auth=self.request.user).last()
|
||||
if junior_data:
|
||||
serializer = JuniorProfileSerializer(junior_data)
|
||||
if str(self.request.GET.get('user_type')) == '2':
|
||||
return custom_response(None, serializer.data, response_status=status.HTTP_200_OK)
|
||||
elif str(self.request.GET.get('user_type')) == '2':
|
||||
guardian_data = Guardian.objects.filter(user=self.request.user).last()
|
||||
if guardian_data:
|
||||
serializer = GuardianProfileSerializer(guardian_data)
|
||||
return custom_response(None, serializer.data, response_status=status.HTTP_200_OK)
|
||||
return custom_response(None, serializer.data, response_status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
|
||||
class UploadImageAPIViewSet(viewsets.ModelViewSet):
|
||||
@ -427,10 +431,13 @@ class DeleteUserProfileAPIViewSet(viewsets.GenericViewSet):
|
||||
permission_classes=[IsAuthenticated])
|
||||
def account(self, request):
|
||||
user_type = str(request.data['user_type'])
|
||||
password = request.data['password']
|
||||
password = request.data.get('password')
|
||||
signup_method = str(request.data.get('signup_method'))
|
||||
print("signup_method===>",signup_method,'==>',type(signup_method))
|
||||
serializer = self.get_serializer(data=request.data, context={'request': request, 'user': request.user,
|
||||
'user_type':user_type,
|
||||
'password':password})
|
||||
'user_type': user_type,
|
||||
'password': password,
|
||||
'signup_method':signup_method})
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return custom_response(SUCCESS_CODE['3005'], response_status=status.HTTP_200_OK)
|
||||
|
@ -42,7 +42,11 @@ TASK_STATUS = (
|
||||
('4', 'requested'),
|
||||
('5', 'completed')
|
||||
)
|
||||
|
||||
SIGNUP_METHODS = (
|
||||
('1', 'manual'),
|
||||
('2', 'google'),
|
||||
('3', 'apple')
|
||||
)
|
||||
PENDING = 1
|
||||
IN_PROGRESS = 2
|
||||
REJECTED = 3
|
||||
|
18
guardian/migrations/0014_guardian_signup_method.py
Normal file
18
guardian/migrations/0014_guardian_signup_method.py
Normal file
@ -0,0 +1,18 @@
|
||||
# Generated by Django 4.2.2 on 2023-07-11 11:26
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('guardian', '0013_alter_guardian_image'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='guardian',
|
||||
name='signup_method',
|
||||
field=models.CharField(choices=[('1', 'manual'), ('2', 'google'), ('3', 'apple')], default='1', max_length=31),
|
||||
),
|
||||
]
|
@ -3,7 +3,7 @@
|
||||
from django.db import models
|
||||
from django.contrib.auth import get_user_model
|
||||
"""Import Django app"""
|
||||
from base.constants import GENDERS, TASK_STATUS, PENDING, TASK_POINTS
|
||||
from base.constants import GENDERS, TASK_STATUS, PENDING, TASK_POINTS, SIGNUP_METHODS
|
||||
from junior.models import Junior
|
||||
"""Add user model"""
|
||||
User = get_user_model()
|
||||
@ -27,6 +27,8 @@ class Guardian(models.Model):
|
||||
is_verified = models.BooleanField(default=False)
|
||||
is_complete_profile = models.BooleanField(default=False)
|
||||
passcode = models.IntegerField(null=True, blank=True, default=None)
|
||||
"""Sign up method"""
|
||||
signup_method = models.CharField(max_length=31, choices=SIGNUP_METHODS, default='1')
|
||||
"""Codes"""
|
||||
guardian_code = models.CharField(max_length=10, null=True, blank=True, default=None)
|
||||
referral_code = models.CharField(max_length=10, null=True, blank=True, default=None)
|
||||
|
@ -241,5 +241,5 @@ class GuardianProfileSerializer(serializers.ModelSerializer):
|
||||
model = Guardian
|
||||
fields = ['id', 'email', 'first_name', 'last_name', 'country_name','country_code', 'phone', 'gender', 'dob',
|
||||
'guardian_code', 'notification_count', 'total_count', 'complete_field_count', 'referral_code',
|
||||
'is_active', 'is_complete_profile', 'created_at', 'image',
|
||||
'is_active', 'is_complete_profile', 'created_at', 'image', 'signup_method',
|
||||
'updated_at']
|
||||
|
18
junior/migrations/0010_junior_signup_method.py
Normal file
18
junior/migrations/0010_junior_signup_method.py
Normal file
@ -0,0 +1,18 @@
|
||||
# Generated by Django 4.2.2 on 2023-07-11 11:26
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('junior', '0009_juniorpoints_position'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='junior',
|
||||
name='signup_method',
|
||||
field=models.CharField(choices=[('1', 'manual'), ('2', 'google'), ('3', 'apple')], default='1', max_length=31),
|
||||
),
|
||||
]
|
@ -4,7 +4,7 @@ from django.db import models
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.postgres.fields import ArrayField
|
||||
"""Import django app"""
|
||||
from base.constants import GENDERS
|
||||
from base.constants import GENDERS, SIGNUP_METHODS
|
||||
User = get_user_model()
|
||||
# Create your models here.
|
||||
|
||||
@ -19,6 +19,8 @@ class Junior(models.Model):
|
||||
gender = models.CharField(max_length=10, choices=GENDERS, null=True, blank=True, default=None)
|
||||
dob = models.DateField(max_length=15, null=True, blank=True, default=None)
|
||||
image = models.URLField(null=True, blank=True, default=None)
|
||||
"""Sign up method"""
|
||||
signup_method = models.CharField(max_length=31, choices=SIGNUP_METHODS, default='1')
|
||||
"""Codes"""
|
||||
junior_code = models.CharField(max_length=10, null=True, blank=True, default=None)
|
||||
guardian_code = ArrayField(models.CharField(max_length=10, null=True, blank=True, default=None),null=True)
|
||||
|
@ -237,4 +237,4 @@ class JuniorProfileSerializer(serializers.ModelSerializer):
|
||||
model = Junior
|
||||
fields = ['id', 'email', 'first_name', 'last_name', 'country_name', 'country_code', 'phone', 'gender', 'dob',
|
||||
'guardian_code', 'referral_code','is_active', 'is_complete_profile', 'created_at', 'image',
|
||||
'updated_at', 'notification_count', 'total_count', 'complete_field_count']
|
||||
'updated_at', 'notification_count', 'total_count', 'complete_field_count', 'signup_method']
|
||||
|
Reference in New Issue
Block a user