auth_views.py 775 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
from django.contrib import auth

from rest_framework import response
from rest_framework import views

from . import auth_serializers


class LoginView(views.APIView):
    authentication_classes = []
    permission_classes = []

    def post(self, request, *args, **kwargs):

        serializer = auth_serializers.LoginSerializer(data=request.data)
        serializer.is_valid(raise_exception=True)

        auth.login(request=request, user=serializer.validated_data["user"])

        payload = {}

        return response.Response(payload)


class LogoutView(views.APIView):
    authentication_classes = []
    permission_classes = []

    def post(self, request, *args, **kwargs):
        auth.logout(request)
        payload = {}
        return response.Response(payload)