mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-07-14 09:37:20 +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']
|
||||
|
||||
def __str__(self):
|
||||
"""Return delete user"""
|
||||
return self.user
|
||||
@admin.register(UserNotification)
|
||||
class UserNotificationAdmin(admin.ModelAdmin):
|
||||
|
@ -140,3 +140,7 @@ class UserNotification(models.Model):
|
||||
|
||||
def __str__(self):
|
||||
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,
|
||||
GoogleLoginViewSet, SigninWithApple, ProfileAPIViewSet, UploadImageAPIViewSet,
|
||||
DefaultImageAPIViewSet, DeleteUserProfileAPIViewSet, UserNotificationAPIViewSet,
|
||||
UpdateUserNotificationAPIViewSet, SendSupportEmail)
|
||||
UpdateUserNotificationAPIViewSet, SendSupportEmail, LogoutAPIView)
|
||||
"""Router"""
|
||||
router = routers.SimpleRouter()
|
||||
|
||||
@ -44,5 +44,6 @@ urlpatterns = [
|
||||
path('api/v1/change-password/', ChangePasswordAPIView.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/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.username = str(random_num) + str('@D_') + '{}'.format(user_tb.username).lower()
|
||||
user_tb.password = 'None'
|
||||
d_email = user_tb.email
|
||||
o_mail = user.email
|
||||
dummy_email = user_tb.email
|
||||
old_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)
|
||||
instance_data = UserDelete.objects.create(user=user_tb, d_email=dummy_email, old_email=old_mail,
|
||||
is_active=True, reason=data)
|
||||
|
||||
return instance
|
||||
return instance_data
|
||||
def junior_account_update(user_tb):
|
||||
"""junior account delete"""
|
||||
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.utils import timezone
|
||||
import jwt
|
||||
from django.contrib.auth import logout
|
||||
"""App Import"""
|
||||
from guardian.utils import upload_image_to_alibaba
|
||||
from django.contrib.auth import authenticate, login
|
||||
@ -30,8 +31,8 @@ from templated_email import send_templated_mail
|
||||
import google.oauth2.credentials
|
||||
import google.auth.transport.requests
|
||||
from rest_framework import status
|
||||
from rest_framework.response import Response
|
||||
import requests
|
||||
from rest_framework.response import Response
|
||||
from django.conf import settings
|
||||
from junior.serializers import JuniorProfileSerializer
|
||||
from guardian.serializers import GuardianProfileSerializer
|
||||
@ -97,9 +98,11 @@ class GoogleLoginMixin:
|
||||
|
||||
|
||||
class GoogleLoginViewSet(GoogleLoginMixin, viewsets.GenericViewSet):
|
||||
"""Google login viewset"""
|
||||
serializer_class = GoogleLoginSerializer
|
||||
|
||||
def create(self, request):
|
||||
"""create method"""
|
||||
serializer = self.get_serializer(data=request.data)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
return self.google_login(request)
|
||||
@ -142,6 +145,7 @@ class SigninWithApple(views.APIView):
|
||||
|
||||
|
||||
class UpdateProfileImage(views.APIView):
|
||||
"""Update profile image"""
|
||||
permission_classes = [IsAuthenticated]
|
||||
def put(self, request, format=None):
|
||||
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)
|
||||
|
||||
class ChangePasswordAPIView(views.APIView):
|
||||
"""change password"""
|
||||
serializer_class = ChangePasswordSerializer
|
||||
permission_classes = [IsAuthenticated]
|
||||
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)
|
||||
|
||||
class ResetPasswordAPIView(views.APIView):
|
||||
"""Reset password"""
|
||||
def post(self, request):
|
||||
serializer = ResetPasswordSerializer(data=request.data)
|
||||
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)
|
||||
|
||||
class ForgotPasswordAPIView(views.APIView):
|
||||
"""Forgot password"""
|
||||
def post(self, request):
|
||||
serializer = ForgotPasswordSerializer(data=request.data)
|
||||
if serializer.is_valid():
|
||||
@ -255,6 +262,7 @@ class UserPhoneVerification(viewsets.ModelViewSet):
|
||||
|
||||
|
||||
class UserLogin(viewsets.ViewSet):
|
||||
"""User login"""
|
||||
@action(methods=['post'], detail=False)
|
||||
def login(self, request):
|
||||
username = request.data.get('username')
|
||||
@ -471,6 +479,7 @@ class UpdateUserNotificationAPIViewSet(viewsets.ModelViewSet):
|
||||
|
||||
|
||||
class SendSupportEmail(views.APIView):
|
||||
"""support email api"""
|
||||
def post(self, request):
|
||||
name = request.data.get('name')
|
||||
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)
|
||||
else:
|
||||
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',
|
||||
'2': '-name'
|
||||
}
|
||||
"""user type"""
|
||||
USER_TYPE = (
|
||||
('1', 'junior'),
|
||||
('2', 'guardian'),
|
||||
('3', 'superuser')
|
||||
)
|
||||
"""gender"""
|
||||
GENDERS = (
|
||||
('1', 'Male'),
|
||||
('2', 'Female')
|
||||
)
|
||||
"""Task status"""
|
||||
TASK_STATUS = (
|
||||
('1', 'pending'),
|
||||
('2', 'in-progress'),
|
||||
@ -42,6 +45,7 @@ TASK_STATUS = (
|
||||
('4', 'requested'),
|
||||
('5', 'completed')
|
||||
)
|
||||
"""sign up method"""
|
||||
SIGNUP_METHODS = (
|
||||
('1', 'manual'),
|
||||
('2', 'google'),
|
||||
|
@ -87,7 +87,8 @@ SUCCESS_CODE = {
|
||||
"3016": "Send otp on your Email successfully",
|
||||
"3017": "Profile image update successfully",
|
||||
"3018": "Task created successfully",
|
||||
"3019": "Support Email sent successfully"
|
||||
"3019": "Support Email sent successfully",
|
||||
"3020": "Logged out successfully."
|
||||
}
|
||||
|
||||
STATUS_CODE_ERROR = {
|
||||
|
@ -119,7 +119,7 @@ class CreateGuardianSerializer(serializers.ModelSerializer):
|
||||
"""Complete profile of the junior if below all data are filled"""
|
||||
complete_profile_field = all([guardian.phone, guardian.gender, guardian.country_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
|
||||
if complete_profile_field:
|
||||
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',
|
||||
'updated_at']
|
||||
class TaskDetailsSerializer(serializers.ModelSerializer):
|
||||
"""Task detail serializer"""
|
||||
|
||||
junior = JuniorDetailSerializer()
|
||||
class Meta(object):
|
||||
@ -187,7 +188,7 @@ class TopJuniorSerializer(serializers.ModelSerializer):
|
||||
junior = JuniorDetailSerializer()
|
||||
position = serializers.IntegerField()
|
||||
|
||||
class Meta:
|
||||
class Meta(object):
|
||||
"""Meta info"""
|
||||
model = JuniorPoints
|
||||
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):
|
||||
"""total filled fields count"""
|
||||
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]
|
||||
return len(total_complete_field)
|
||||
|
||||
|
@ -1,7 +1,9 @@
|
||||
"""Utiles file of guardian"""
|
||||
"""Django import"""
|
||||
import oss2
|
||||
"""Import setting"""
|
||||
from django.conf import settings
|
||||
"""Import tempfile"""
|
||||
import tempfile
|
||||
|
||||
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_field = all([junior.phone, junior.gender, junior.country_name, junior.image,
|
||||
junior.dob, junior.country_code, user.first_name, user.last_name,
|
||||
user.email])
|
||||
user.email, junior.passcode])
|
||||
junior.is_complete_profile = False
|
||||
if complete_profile_field:
|
||||
junior.is_complete_profile = True
|
||||
@ -224,12 +224,12 @@ class JuniorProfileSerializer(serializers.ModelSerializer):
|
||||
|
||||
def get_total_count(self, obj):
|
||||
"""total fields count"""
|
||||
return 9
|
||||
return 10
|
||||
|
||||
def get_complete_field_count(self, obj):
|
||||
"""total filled fields count"""
|
||||
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 != '']
|
||||
return len(complete_field)
|
||||
class Meta(object):
|
||||
|
@ -154,6 +154,10 @@ AUTH_PASSWORD_VALIDATORS = [
|
||||
},
|
||||
]
|
||||
|
||||
JWT_AUTH = {
|
||||
# Other JWT authentication settings
|
||||
'JWT_AUTHENTICATION': 'your_app.authentication.CustomJWTAuthentication',
|
||||
}
|
||||
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/3.0/topics/i18n/
|
||||
@ -167,7 +171,6 @@ USE_I18N = True
|
||||
USE_L10N = True
|
||||
|
||||
USE_TZ = True
|
||||
|
||||
# cors header settings
|
||||
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
|
||||
|
||||
|
Reference in New Issue
Block a user