clean code and add unsubscribe
This commit is contained in:
@@ -2,6 +2,8 @@ from django.urls import path
|
||||
from . import views
|
||||
from djoser.urls.jwt import views as djoser_jwt_views
|
||||
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
path('profile', views.ProfileView.as_view()),
|
||||
path('verify', djoser_jwt_views.TokenVerifyView.as_view(), name='jwt-verify'),
|
||||
@@ -13,6 +15,7 @@ urlpatterns = [
|
||||
path('address/list', views.GetUserAddressesView.as_view(), name='list-addresses'),
|
||||
path('address/<int:pk>', views.GetIDUserAddressView.as_view(), name='get-ID-address'),
|
||||
path('subscribe', views.SubscribeView.as_view(), name='subscibe'),
|
||||
path('unsubscribe', views.UnsubscribeView.as_view(), name='unsubscibe'),
|
||||
path('attack/view/<int:pk>', views.ChangeViewAttack.as_view(), name='attack-view'),
|
||||
path('logout', views.LogoutView.as_view(), name='logout'),
|
||||
]
|
||||
@@ -11,12 +11,11 @@ from django.shortcuts import get_object_or_404, redirect
|
||||
from rest_framework_simplejwt.tokens import RefreshToken
|
||||
import ghasedak_sms
|
||||
from django.views import View
|
||||
# this works only need to be used
|
||||
# class APIView(APIView):
|
||||
# def __init__(self, *args, **kwargs):
|
||||
# super().__init__(*args, **kwargs)
|
||||
# if AllowAny in self.permission_classes or not self.permission_classes:
|
||||
# self.authentication_classes = []
|
||||
from rest_framework import serializers
|
||||
from rest_framework_simplejwt.tokens import RefreshToken
|
||||
|
||||
|
||||
|
||||
class SendOTPView(APIView):
|
||||
permission_classes = [AllowAny]
|
||||
@extend_schema(
|
||||
@@ -190,6 +189,25 @@ class SubscribeView(APIView):
|
||||
return Response(status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
|
||||
class UnsubscribeSerializer(serializers.Serializer):
|
||||
end_point = serializers.CharField()
|
||||
|
||||
class UnsubscribeView(APIView):
|
||||
permission_classes = [IsAuthenticated]
|
||||
serializer_class = UnsubscribeSerializer
|
||||
def post(self, request):
|
||||
endpoint = request.data.get("end_point")
|
||||
if not endpoint:
|
||||
return Response({"detail": "اند پوینت لازم است"}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
deleted, _ = PushSubscription.objects.filter(user=request.user, endpoint=endpoint).delete()
|
||||
|
||||
if deleted:
|
||||
return Response({"detail": "با موفقیت اشتراک پاک شد"}, status=status.HTTP_200_OK)
|
||||
|
||||
return Response({"detail": "اند پوینت پیدا نشد"}, status=status.HTTP_404_NOT_FOUND)
|
||||
|
||||
|
||||
class ChangeViewAttack(View):
|
||||
def get(self, request, pk):
|
||||
attack = get_object_or_404(SecurityBreachAttemptModel, pk=pk)
|
||||
@@ -198,8 +216,6 @@ class ChangeViewAttack(View):
|
||||
return redirect('admin:account_securitybreachattemptmodel_changelist')
|
||||
|
||||
|
||||
from rest_framework import serializers
|
||||
from rest_framework_simplejwt.tokens import RefreshToken
|
||||
|
||||
class LogoutSerializer(serializers.Serializer):
|
||||
refresh_token = serializers.CharField(help_text="Refresh token to be blacklisted")
|
||||
|
||||
Reference in New Issue
Block a user