diff --git a/authentication/urls.py b/authentication/urls.py index fecf9a5..f838e28 100644 --- a/authentication/urls.py +++ b/authentication/urls.py @@ -5,5 +5,6 @@ urlpatterns = [ path('register/', RegisterView.as_view(), name='register'), - path('login/', LoginView.as_view(), name='login') + path('login/', LoginView.as_view(), name='login'), + path('logout/', LogoutView.as_view(), name='logout') ] \ No newline at end of file diff --git a/authentication/views.py b/authentication/views.py index 47f3473..8ebaffb 100644 --- a/authentication/views.py +++ b/authentication/views.py @@ -1,7 +1,7 @@ import json from django.http import JsonResponse from authentication.models import * -from django.contrib.auth import authenticate, login +from django.contrib.auth import authenticate, login, logout from django.views import View from django.utils.decorators import method_decorator from django.views.decorators.csrf import csrf_exempt @@ -36,6 +36,12 @@ def post(self, request): else: return JsonResponse({'msg': 'Wrong username/password!'}, status=400) +@method_decorator(csrf_exempt, name='dispatch') +class LogoutView(View): + def post(self, request): + logout(request) + return JsonResponse({'msg': 'berhasil logout'}, status=200) + class Validators(): def validateInput(username, email, password): if username == '' or password == '' or email == '':