mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-07-14 17:45:46 +00:00
logout api and sonar
This commit is contained in:
@ -11,6 +11,7 @@ class UserDeleteAdmin(admin.ModelAdmin):
|
|||||||
list_display = ['user', 'old_email', 'd_email']
|
list_display = ['user', 'old_email', 'd_email']
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
"""Return delete user"""
|
||||||
return self.user
|
return self.user
|
||||||
@admin.register(UserNotification)
|
@admin.register(UserNotification)
|
||||||
class UserNotificationAdmin(admin.ModelAdmin):
|
class UserNotificationAdmin(admin.ModelAdmin):
|
||||||
|
@ -140,3 +140,7 @@ class UserNotification(models.Model):
|
|||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.user.email
|
return self.user.email
|
||||||
|
|
||||||
|
# class RevokedToken(models.Model):
|
||||||
|
# token = models.CharField(max_length=255, unique=True)
|
||||||
|
# date_revoked = models.DateTimeField(auto_now_add=True)
|
@ -8,7 +8,7 @@ from .views import (UserLogin, SendPhoneOtp, UserPhoneVerification, UserEmailVer
|
|||||||
ForgotPasswordAPIView, ResetPasswordAPIView, ChangePasswordAPIView, UpdateProfileImage,
|
ForgotPasswordAPIView, ResetPasswordAPIView, ChangePasswordAPIView, UpdateProfileImage,
|
||||||
GoogleLoginViewSet, SigninWithApple, ProfileAPIViewSet, UploadImageAPIViewSet,
|
GoogleLoginViewSet, SigninWithApple, ProfileAPIViewSet, UploadImageAPIViewSet,
|
||||||
DefaultImageAPIViewSet, DeleteUserProfileAPIViewSet, UserNotificationAPIViewSet,
|
DefaultImageAPIViewSet, DeleteUserProfileAPIViewSet, UserNotificationAPIViewSet,
|
||||||
UpdateUserNotificationAPIViewSet, SendSupportEmail)
|
UpdateUserNotificationAPIViewSet, SendSupportEmail, LogoutAPIView)
|
||||||
"""Router"""
|
"""Router"""
|
||||||
router = routers.SimpleRouter()
|
router = routers.SimpleRouter()
|
||||||
|
|
||||||
@ -44,5 +44,6 @@ urlpatterns = [
|
|||||||
path('api/v1/change-password/', ChangePasswordAPIView.as_view()),
|
path('api/v1/change-password/', ChangePasswordAPIView.as_view()),
|
||||||
path('api/v1/update-profile-image/', UpdateProfileImage.as_view()),
|
path('api/v1/update-profile-image/', UpdateProfileImage.as_view()),
|
||||||
path('api/v1/apple-login/', SigninWithApple.as_view(), name='signup_with_apple'),
|
path('api/v1/apple-login/', SigninWithApple.as_view(), name='signup_with_apple'),
|
||||||
path('api/v1/send-support-email/', SendSupportEmail.as_view(), name='send-support-email')
|
path('api/v1/send-support-email/', SendSupportEmail.as_view(), name='send-support-email'),
|
||||||
|
path('api/v1/logout/', LogoutAPIView.as_view(), name='logout')
|
||||||
]
|
]
|
||||||
|
@ -47,13 +47,13 @@ def delete_user_account_condition_social(user, user_type,user_tb, data, random_n
|
|||||||
user_tb.email = str(random_num) + str('@D_') + '{}'.format(user_tb.username).lower()
|
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.username = str(random_num) + str('@D_') + '{}'.format(user_tb.username).lower()
|
||||||
user_tb.password = 'None'
|
user_tb.password = 'None'
|
||||||
d_email = user_tb.email
|
dummy_email = user_tb.email
|
||||||
o_mail = user.email
|
old_mail = user.email
|
||||||
user_tb.save()
|
user_tb.save()
|
||||||
instance = UserDelete.objects.create(user=user_tb, d_email=d_email, old_email=o_mail,
|
instance_data = UserDelete.objects.create(user=user_tb, d_email=dummy_email, old_email=old_mail,
|
||||||
is_active=True, reason=data)
|
is_active=True, reason=data)
|
||||||
|
|
||||||
return instance
|
return instance_data
|
||||||
def junior_account_update(user_tb):
|
def junior_account_update(user_tb):
|
||||||
"""junior account delete"""
|
"""junior account delete"""
|
||||||
junior_data = Junior.objects.filter(auth__email=user_tb.email).first()
|
junior_data = Junior.objects.filter(auth__email=user_tb.email).first()
|
||||||
|
@ -8,6 +8,7 @@ import logging
|
|||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
import jwt
|
import jwt
|
||||||
|
from django.contrib.auth import logout
|
||||||
"""App Import"""
|
"""App Import"""
|
||||||
from guardian.utils import upload_image_to_alibaba
|
from guardian.utils import upload_image_to_alibaba
|
||||||
from django.contrib.auth import authenticate, login
|
from django.contrib.auth import authenticate, login
|
||||||
@ -30,8 +31,8 @@ from templated_email import send_templated_mail
|
|||||||
import google.oauth2.credentials
|
import google.oauth2.credentials
|
||||||
import google.auth.transport.requests
|
import google.auth.transport.requests
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
from rest_framework.response import Response
|
|
||||||
import requests
|
import requests
|
||||||
|
from rest_framework.response import Response
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from junior.serializers import JuniorProfileSerializer
|
from junior.serializers import JuniorProfileSerializer
|
||||||
from guardian.serializers import GuardianProfileSerializer
|
from guardian.serializers import GuardianProfileSerializer
|
||||||
@ -97,9 +98,11 @@ class GoogleLoginMixin:
|
|||||||
|
|
||||||
|
|
||||||
class GoogleLoginViewSet(GoogleLoginMixin, viewsets.GenericViewSet):
|
class GoogleLoginViewSet(GoogleLoginMixin, viewsets.GenericViewSet):
|
||||||
|
"""Google login viewset"""
|
||||||
serializer_class = GoogleLoginSerializer
|
serializer_class = GoogleLoginSerializer
|
||||||
|
|
||||||
def create(self, request):
|
def create(self, request):
|
||||||
|
"""create method"""
|
||||||
serializer = self.get_serializer(data=request.data)
|
serializer = self.get_serializer(data=request.data)
|
||||||
serializer.is_valid(raise_exception=True)
|
serializer.is_valid(raise_exception=True)
|
||||||
return self.google_login(request)
|
return self.google_login(request)
|
||||||
@ -142,6 +145,7 @@ class SigninWithApple(views.APIView):
|
|||||||
|
|
||||||
|
|
||||||
class UpdateProfileImage(views.APIView):
|
class UpdateProfileImage(views.APIView):
|
||||||
|
"""Update profile image"""
|
||||||
permission_classes = [IsAuthenticated]
|
permission_classes = [IsAuthenticated]
|
||||||
def put(self, request, format=None):
|
def put(self, request, format=None):
|
||||||
if str(request.data['user_type']) == '1':
|
if str(request.data['user_type']) == '1':
|
||||||
@ -166,6 +170,7 @@ class UpdateProfileImage(views.APIView):
|
|||||||
return custom_error_response(serializer.errors, response_status=status.HTTP_400_BAD_REQUEST)
|
return custom_error_response(serializer.errors, response_status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
class ChangePasswordAPIView(views.APIView):
|
class ChangePasswordAPIView(views.APIView):
|
||||||
|
"""change password"""
|
||||||
serializer_class = ChangePasswordSerializer
|
serializer_class = ChangePasswordSerializer
|
||||||
permission_classes = [IsAuthenticated]
|
permission_classes = [IsAuthenticated]
|
||||||
def post(self, request):
|
def post(self, request):
|
||||||
@ -176,6 +181,7 @@ class ChangePasswordAPIView(views.APIView):
|
|||||||
return custom_error_response(serializer.errors, response_status=status.HTTP_400_BAD_REQUEST)
|
return custom_error_response(serializer.errors, response_status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
class ResetPasswordAPIView(views.APIView):
|
class ResetPasswordAPIView(views.APIView):
|
||||||
|
"""Reset password"""
|
||||||
def post(self, request):
|
def post(self, request):
|
||||||
serializer = ResetPasswordSerializer(data=request.data)
|
serializer = ResetPasswordSerializer(data=request.data)
|
||||||
if serializer.is_valid():
|
if serializer.is_valid():
|
||||||
@ -184,6 +190,7 @@ class ResetPasswordAPIView(views.APIView):
|
|||||||
return custom_error_response(serializer.errors, response_status=status.HTTP_400_BAD_REQUEST)
|
return custom_error_response(serializer.errors, response_status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
class ForgotPasswordAPIView(views.APIView):
|
class ForgotPasswordAPIView(views.APIView):
|
||||||
|
"""Forgot password"""
|
||||||
def post(self, request):
|
def post(self, request):
|
||||||
serializer = ForgotPasswordSerializer(data=request.data)
|
serializer = ForgotPasswordSerializer(data=request.data)
|
||||||
if serializer.is_valid():
|
if serializer.is_valid():
|
||||||
@ -255,6 +262,7 @@ class UserPhoneVerification(viewsets.ModelViewSet):
|
|||||||
|
|
||||||
|
|
||||||
class UserLogin(viewsets.ViewSet):
|
class UserLogin(viewsets.ViewSet):
|
||||||
|
"""User login"""
|
||||||
@action(methods=['post'], detail=False)
|
@action(methods=['post'], detail=False)
|
||||||
def login(self, request):
|
def login(self, request):
|
||||||
username = request.data.get('username')
|
username = request.data.get('username')
|
||||||
@ -471,6 +479,7 @@ class UpdateUserNotificationAPIViewSet(viewsets.ModelViewSet):
|
|||||||
|
|
||||||
|
|
||||||
class SendSupportEmail(views.APIView):
|
class SendSupportEmail(views.APIView):
|
||||||
|
"""support email api"""
|
||||||
def post(self, request):
|
def post(self, request):
|
||||||
name = request.data.get('name')
|
name = request.data.get('name')
|
||||||
sender = request.data.get('email')
|
sender = request.data.get('email')
|
||||||
@ -484,3 +493,12 @@ class SendSupportEmail(views.APIView):
|
|||||||
return custom_error_response(str(e), response_status=status.HTTP_400_BAD_REQUEST)
|
return custom_error_response(str(e), response_status=status.HTTP_400_BAD_REQUEST)
|
||||||
else:
|
else:
|
||||||
return custom_error_response(ERROR_CODE['2033'], response_status=status.HTTP_400_BAD_REQUEST)
|
return custom_error_response(ERROR_CODE['2033'], response_status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
|
|
||||||
|
class LogoutAPIView(views.APIView):
|
||||||
|
permission_classes = (IsAuthenticated,)
|
||||||
|
|
||||||
|
def post(self, request):
|
||||||
|
logout(request)
|
||||||
|
request.session.flush()
|
||||||
|
return custom_response(SUCCESS_CODE['3020'], response_status=status.HTTP_200_OK)
|
||||||
|
@ -26,15 +26,18 @@ sort_dict = {
|
|||||||
'1': 'name',
|
'1': 'name',
|
||||||
'2': '-name'
|
'2': '-name'
|
||||||
}
|
}
|
||||||
|
"""user type"""
|
||||||
USER_TYPE = (
|
USER_TYPE = (
|
||||||
('1', 'junior'),
|
('1', 'junior'),
|
||||||
('2', 'guardian'),
|
('2', 'guardian'),
|
||||||
('3', 'superuser')
|
('3', 'superuser')
|
||||||
)
|
)
|
||||||
|
"""gender"""
|
||||||
GENDERS = (
|
GENDERS = (
|
||||||
('1', 'Male'),
|
('1', 'Male'),
|
||||||
('2', 'Female')
|
('2', 'Female')
|
||||||
)
|
)
|
||||||
|
"""Task status"""
|
||||||
TASK_STATUS = (
|
TASK_STATUS = (
|
||||||
('1', 'pending'),
|
('1', 'pending'),
|
||||||
('2', 'in-progress'),
|
('2', 'in-progress'),
|
||||||
@ -42,6 +45,7 @@ TASK_STATUS = (
|
|||||||
('4', 'requested'),
|
('4', 'requested'),
|
||||||
('5', 'completed')
|
('5', 'completed')
|
||||||
)
|
)
|
||||||
|
"""sign up method"""
|
||||||
SIGNUP_METHODS = (
|
SIGNUP_METHODS = (
|
||||||
('1', 'manual'),
|
('1', 'manual'),
|
||||||
('2', 'google'),
|
('2', 'google'),
|
||||||
|
@ -87,7 +87,8 @@ SUCCESS_CODE = {
|
|||||||
"3016": "Send otp on your Email successfully",
|
"3016": "Send otp on your Email successfully",
|
||||||
"3017": "Profile image update successfully",
|
"3017": "Profile image update successfully",
|
||||||
"3018": "Task created successfully",
|
"3018": "Task created successfully",
|
||||||
"3019": "Support Email sent successfully"
|
"3019": "Support Email sent successfully",
|
||||||
|
"3020": "Logged out successfully."
|
||||||
}
|
}
|
||||||
|
|
||||||
STATUS_CODE_ERROR = {
|
STATUS_CODE_ERROR = {
|
||||||
|
@ -119,7 +119,7 @@ class CreateGuardianSerializer(serializers.ModelSerializer):
|
|||||||
"""Complete profile of the junior if below all data are filled"""
|
"""Complete profile of the junior if below all data are filled"""
|
||||||
complete_profile_field = all([guardian.phone, guardian.gender, guardian.country_name,
|
complete_profile_field = all([guardian.phone, guardian.gender, guardian.country_name,
|
||||||
guardian.dob, guardian.country_code, user.first_name, user.last_name,
|
guardian.dob, guardian.country_code, user.first_name, user.last_name,
|
||||||
user.email, guardian.image])
|
user.email, guardian.image, guardian.passcode])
|
||||||
guardian.is_complete_profile = False
|
guardian.is_complete_profile = False
|
||||||
if complete_profile_field:
|
if complete_profile_field:
|
||||||
guardian.is_complete_profile = True
|
guardian.is_complete_profile = True
|
||||||
@ -173,6 +173,7 @@ class GuardianDetailSerializer(serializers.ModelSerializer):
|
|||||||
'guardian_code', 'referral_code','is_active', 'is_complete_profile', 'created_at', 'image',
|
'guardian_code', 'referral_code','is_active', 'is_complete_profile', 'created_at', 'image',
|
||||||
'updated_at']
|
'updated_at']
|
||||||
class TaskDetailsSerializer(serializers.ModelSerializer):
|
class TaskDetailsSerializer(serializers.ModelSerializer):
|
||||||
|
"""Task detail serializer"""
|
||||||
|
|
||||||
junior = JuniorDetailSerializer()
|
junior = JuniorDetailSerializer()
|
||||||
class Meta(object):
|
class Meta(object):
|
||||||
@ -187,7 +188,7 @@ class TopJuniorSerializer(serializers.ModelSerializer):
|
|||||||
junior = JuniorDetailSerializer()
|
junior = JuniorDetailSerializer()
|
||||||
position = serializers.IntegerField()
|
position = serializers.IntegerField()
|
||||||
|
|
||||||
class Meta:
|
class Meta(object):
|
||||||
"""Meta info"""
|
"""Meta info"""
|
||||||
model = JuniorPoints
|
model = JuniorPoints
|
||||||
fields = ['id', 'junior', 'total_task_points', 'position', 'created_at', 'updated_at']
|
fields = ['id', 'junior', 'total_task_points', 'position', 'created_at', 'updated_at']
|
||||||
@ -228,7 +229,7 @@ class GuardianProfileSerializer(serializers.ModelSerializer):
|
|||||||
def get_complete_field_count(self, obj):
|
def get_complete_field_count(self, obj):
|
||||||
"""total filled fields count"""
|
"""total filled fields count"""
|
||||||
total_field_list = [obj.user.first_name, obj.user.last_name, obj.user.email, obj.country_name, obj.country_code,
|
total_field_list = [obj.user.first_name, obj.user.last_name, obj.user.email, obj.country_name, obj.country_code,
|
||||||
obj.phone, obj.gender, obj.dob, obj.image]
|
obj.phone, obj.gender, obj.dob, obj.image, obj.passcode]
|
||||||
total_complete_field = [data for data in total_field_list if data != '' and data is not None]
|
total_complete_field = [data for data in total_field_list if data != '' and data is not None]
|
||||||
return len(total_complete_field)
|
return len(total_complete_field)
|
||||||
|
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
"""Utiles file of guardian"""
|
"""Utiles file of guardian"""
|
||||||
"""Django import"""
|
"""Django import"""
|
||||||
import oss2
|
import oss2
|
||||||
|
"""Import setting"""
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
"""Import tempfile"""
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
def upload_image_to_alibaba(image, filename):
|
def upload_image_to_alibaba(image, filename):
|
||||||
|
@ -93,7 +93,7 @@ class CreateJuniorSerializer(serializers.ModelSerializer):
|
|||||||
"""Complete profile of the junior if below all data are filled"""
|
"""Complete profile of the junior if below all data are filled"""
|
||||||
complete_profile_field = all([junior.phone, junior.gender, junior.country_name, junior.image,
|
complete_profile_field = all([junior.phone, junior.gender, junior.country_name, junior.image,
|
||||||
junior.dob, junior.country_code, user.first_name, user.last_name,
|
junior.dob, junior.country_code, user.first_name, user.last_name,
|
||||||
user.email])
|
user.email, junior.passcode])
|
||||||
junior.is_complete_profile = False
|
junior.is_complete_profile = False
|
||||||
if complete_profile_field:
|
if complete_profile_field:
|
||||||
junior.is_complete_profile = True
|
junior.is_complete_profile = True
|
||||||
@ -224,12 +224,12 @@ class JuniorProfileSerializer(serializers.ModelSerializer):
|
|||||||
|
|
||||||
def get_total_count(self, obj):
|
def get_total_count(self, obj):
|
||||||
"""total fields count"""
|
"""total fields count"""
|
||||||
return 9
|
return 10
|
||||||
|
|
||||||
def get_complete_field_count(self, obj):
|
def get_complete_field_count(self, obj):
|
||||||
"""total filled fields count"""
|
"""total filled fields count"""
|
||||||
field_list = [obj.auth.first_name, obj.auth.last_name, obj.auth.email, obj.country_name, obj.country_code,
|
field_list = [obj.auth.first_name, obj.auth.last_name, obj.auth.email, obj.country_name, obj.country_code,
|
||||||
obj.phone, obj.gender, obj.dob, obj.image]
|
obj.phone, obj.gender, obj.dob, obj.image, obj.passcode]
|
||||||
complete_field = [data for data in field_list if data is not None and data != '']
|
complete_field = [data for data in field_list if data is not None and data != '']
|
||||||
return len(complete_field)
|
return len(complete_field)
|
||||||
class Meta(object):
|
class Meta(object):
|
||||||
|
@ -154,6 +154,10 @@ AUTH_PASSWORD_VALIDATORS = [
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
JWT_AUTH = {
|
||||||
|
# Other JWT authentication settings
|
||||||
|
'JWT_AUTHENTICATION': 'your_app.authentication.CustomJWTAuthentication',
|
||||||
|
}
|
||||||
|
|
||||||
# Internationalization
|
# Internationalization
|
||||||
# https://docs.djangoproject.com/en/3.0/topics/i18n/
|
# https://docs.djangoproject.com/en/3.0/topics/i18n/
|
||||||
@ -167,7 +171,6 @@ USE_I18N = True
|
|||||||
USE_L10N = True
|
USE_L10N = True
|
||||||
|
|
||||||
USE_TZ = True
|
USE_TZ = True
|
||||||
|
|
||||||
# cors header settings
|
# cors header settings
|
||||||
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
|
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user