Skip to content
Snippets Groups Projects
Commit bbf55456 authored by Chris Li's avatar Chris Li
Browse files

Bugfix: fixed delete user not work.

parent 935b628b
No related branches found
No related tags found
No related merge requests found
......@@ -7,7 +7,7 @@ from django.contrib.auth.models import User
from django.shortcuts import render
from django.urls import reverse
from rest_framework import generics, status, serializers, HTTP_HEADER_ENCODING, permissions
from rest_framework.decorators import api_view, authentication_classes, permission_classes
from rest_framework.decorators import api_view, authentication_classes
from rest_framework.response import Response
from knox.auth import TokenAuthentication
from knox.models import AuthToken
......@@ -180,17 +180,14 @@ def validate_token(request):
return Response({'valid': 'false'})
@api_view(['DELETE'])
@authentication_classes([])
# @permission_classes([permissions.IsAuthenticated])
def delete_account(request):
try:
authenticator = TokenAuthentication()
user, auth_token = authenticator.authenticate(request)
if user and auth_token:
class DeleteAccountAPI(generics.GenericAPIView):
permission_classes = (permissions.IsAuthenticated,)
def delete(self, request):
user = self.request.user
if user:
user.delete()
return Response({'msg': 'Delete successfully.'})
except:
return Response({'msg': 'Failed to delete this account.'}, status=status.HTTP_401_UNAUTHORIZED)
......
......@@ -12,7 +12,7 @@ class BillListCreate(mixins.ListModelMixin, mixins.CreateModelMixin, generics.Ge
# authentication.SessionAuthentication,
# authentication.TokenAuthentication
# ]
# permission_classes = (permissions.IsAuthenticated,)
permission_classes = (permissions.IsAuthenticated,)
def get(self, request, *args, **kwargs):
return self.list(request, *args, **kwargs)
......
......@@ -2,7 +2,7 @@ from django.urls import path, include
from knox import views as knox_views
from rest_framework import routers
from core.api.auth import RegisterAPI, LoginAPI, AppleLogin, GoogleLogin, FacebookLogin, validate_token, delete_account, verify_user_and_activate
from core.api.auth import RegisterAPI, LoginAPI, AppleLogin, GoogleLogin, FacebookLogin, validate_token, DeleteAccountAPI, verify_user_and_activate
from core.api.password import ChangePasswordView
from core.api.profile import ProfileViewSet
from core.api.coupon import CouponViewSet
......@@ -24,7 +24,7 @@ urlpatterns += [
path('api/auth/google', GoogleLogin.as_view(), name='google_login'),
path('api/auth/facebook', FacebookLogin.as_view(), name='facebook_login'),
path('api/auth/validate-token', validate_token, name='validate-token'),
path('api/auth/delete-account', delete_account, name='delete-account'),
path('api/auth/delete-account', DeleteAccountAPI.as_view(), name='delete-account'),
# passwd
path('api/change-password', ChangePasswordView.as_view(), name='change-password'),
path('api/password_reset/', include('django_rest_passwordreset.urls', namespace='password_reset')),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment