<commit_before>from django.http import Http404

from rest_framework import generics, status, renderers, parsers
from rest_framework.renderers import TemplateHTMLRenderer
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework_jwt.serializers import JSONWebTokenSerializer

from ..users.models import User
from ..utils.shortcuts import redirect_with_params
from ..invitations.models import SignupRequest, InvitedUser
from . import serializers


class SigninAPIView(generics.CreateAPIView):
    throttle_classes = ()
    permission_classes = ()
    parser_classes = (parsers.FormParser, parsers.JSONParser,)
    renderer_classes = (renderers.JSONRenderer,)
    serializer_class = JSONWebTokenSerializer

    def get_serializer_class(self):
        if self.request.DATA.get('invited_user_token'):
            return serializers.SigninInvitedUserSerializer
        return super(SigninAPIView, self).get_serializer_class()

    def post(self, request):
        serializer = self.get_serializer(data=request.DATA)

        if serializer.is_valid():
            return Response(serializer.object)

        return Response({
            'error': serializer.errors
        }, status=status.HTTP_400_BAD_REQUEST)


class ValidateUsernameAPIView(generics.CreateAPIView):
    authentication_classes = ()
    permission_classes = ()
    serializer_class = serializers.ValidateUsernameSerializer

    def post(self, request):
        serializer = self.get_serializer(data=request.DATA)

        if serializer.is_valid():
            return Response(serializer.data)

        return Response({
            'error': serializer.errors
        }, status=status.HTTP_400_BAD_REQUEST)


class SignupAPIView(generics.CreateAPIView):
    authentication_classes = ()
    permission_classes = ()
    serializer_class = serializers.SignupSerializer

    def get_serializer_class(self):
        if self.request.DATA.get('invited_user_token'):
            return serializers.SignupInvitedUserSerializer
        return super(SignupAPIView, self).get_serializer_class()

    def post(self, request):
        serializer = self.get_serializer(data=request.DATA)

        if serializer.is_valid():
            return Response(serializer.object)

        return Response({
            'error': serializer.errors
        }, status=status.HTTP_400_BAD_REQUEST)


class ForgotPasswordAPIView(generics.CreateAPIView):
    authentication_classes = ()
    permission_classes = ()
    serializer_class = serializers.ForgotPasswordSerializer

    def post(self, request):
        serializer = self.get_serializer(data=request.DATA)

        if serializer.is_valid():
            return Response(serializer.data)

        return Response({
            'error': serializer.errors
        }, status=status.HTTP_400_BAD_REQUEST)


class ResetPasswordAPIView(generics.CreateAPIView):
    authentication_classes = ()
    permission_classes = ()
    serializer_class = serializers.ResetPasswordSerializer

    def post(self, request):
        serializer = self.get_serializer(data=request.DATA)

        if serializer.is_valid():
            return Response(serializer.object)

        return Response({
            'error': serializer.errors
        }, status=status.HTTP_400_BAD_REQUEST)


class SigninValidateTokenHTMLView(APIView):
    authentication_classes = ()
    permission_classes = ()
    renderer_classes = (TemplateHTMLRenderer,)

    def get(self, request, *args, **kwargs):
        invite = request.QUERY_PARAMS.get('invite')

        if invite:
            invited_user = InvitedUser.objects.get_from_token(invite)

            if not invited_user:
                raise Http404

            if not invited_user.user:
                return redirect_with_params(request, 'auth-signup')

        return Response(template_name='index.html')


class SignupValidateTokenHTMLView(APIView):
    authentication_classes = ()
    permission_classes = ()
    renderer_classes = (TemplateHTMLRenderer,)

    def get(self, request, *args, **kwargs):
        token = request.QUERY_PARAMS.get('token')
        invite = request.QUERY_PARAMS.get('invite')

        if token and not invite:
            signup_request = SignupRequest.objects.get_from_token(token)

            if not signup_request:
                raise Http404

        if invite:
            invited_user = InvitedUser.objects.get_from_token(invite)

            if not invited_user:
                raise Http404

            if invited_user.user:
                return redirect_with_params(request, 'auth-signin')

        return Response(template_name='index.html')


class ResetPasswordHTMLView(APIView):
    authentication_classes = ()
    permission_classes = ()
    renderer_classes = (TemplateHTMLRenderer,)

    def get(self, request, *args, **kwargs):
        token = request.QUERY_PARAMS.get('token')

        user = User.objects.get_from_password_reset_token(token)

        if not user:
            raise Http404

        return Response(template_name='index.html')
<commit_msg>Remove SigningAPIView parsers and renderers<commit_after>from django.http import Http404

from rest_framework import generics, status
from rest_framework.renderers import TemplateHTMLRenderer
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework_jwt.serializers import JSONWebTokenSerializer

from ..users.models import User
from ..utils.shortcuts import redirect_with_params
from ..invitations.models import SignupRequest, InvitedUser
from . import serializers


class SigninAPIView(generics.CreateAPIView):
    throttle_classes = ()
    permission_classes = ()
    serializer_class = JSONWebTokenSerializer

    def get_serializer_class(self):
        if self.request.DATA.get('invited_user_token'):
            return serializers.SigninInvitedUserSerializer
        return super(SigninAPIView, self).get_serializer_class()

    def post(self, request):
        serializer = self.get_serializer(data=request.DATA)

        if serializer.is_valid():
            return Response(serializer.object)

        return Response({
            'error': serializer.errors
        }, status=status.HTTP_400_BAD_REQUEST)


class ValidateUsernameAPIView(generics.CreateAPIView):
    authentication_classes = ()
    permission_classes = ()
    serializer_class = serializers.ValidateUsernameSerializer

    def post(self, request):
        serializer = self.get_serializer(data=request.DATA)

        if serializer.is_valid():
            return Response(serializer.data)

        return Response({
            'error': serializer.errors
        }, status=status.HTTP_400_BAD_REQUEST)


class SignupAPIView(generics.CreateAPIView):
    authentication_classes = ()
    permission_classes = ()
    serializer_class = serializers.SignupSerializer

    def get_serializer_class(self):
        if self.request.DATA.get('invited_user_token'):
            return serializers.SignupInvitedUserSerializer
        return super(SignupAPIView, self).get_serializer_class()

    def post(self, request):
        serializer = self.get_serializer(data=request.DATA)

        if serializer.is_valid():
            return Response(serializer.object)

        return Response({
            'error': serializer.errors
        }, status=status.HTTP_400_BAD_REQUEST)


class ForgotPasswordAPIView(generics.CreateAPIView):
    authentication_classes = ()
    permission_classes = ()
    serializer_class = serializers.ForgotPasswordSerializer

    def post(self, request):
        serializer = self.get_serializer(data=request.DATA)

        if serializer.is_valid():
            return Response(serializer.data)

        return Response({
            'error': serializer.errors
        }, status=status.HTTP_400_BAD_REQUEST)


class ResetPasswordAPIView(generics.CreateAPIView):
    authentication_classes = ()
    permission_classes = ()
    serializer_class = serializers.ResetPasswordSerializer

    def post(self, request):
        serializer = self.get_serializer(data=request.DATA)

        if serializer.is_valid():
            return Response(serializer.object)

        return Response({
            'error': serializer.errors
        }, status=status.HTTP_400_BAD_REQUEST)


class SigninValidateTokenHTMLView(APIView):
    authentication_classes = ()
    permission_classes = ()
    renderer_classes = (TemplateHTMLRenderer,)

    def get(self, request, *args, **kwargs):
        invite = request.QUERY_PARAMS.get('invite')

        if invite:
            invited_user = InvitedUser.objects.get_from_token(invite)

            if not invited_user:
                raise Http404

            if not invited_user.user:
                return redirect_with_params(request, 'auth-signup')

        return Response(template_name='index.html')


class SignupValidateTokenHTMLView(APIView):
    authentication_classes = ()
    permission_classes = ()
    renderer_classes = (TemplateHTMLRenderer,)

    def get(self, request, *args, **kwargs):
        token = request.QUERY_PARAMS.get('token')
        invite = request.QUERY_PARAMS.get('invite')

        if token and not invite:
            signup_request = SignupRequest.objects.get_from_token(token)

            if not signup_request:
                raise Http404

        if invite:
            invited_user = InvitedUser.objects.get_from_token(invite)

            if not invited_user:
                raise Http404

            if invited_user.user:
                return redirect_with_params(request, 'auth-signin')

        return Response(template_name='index.html')


class ResetPasswordHTMLView(APIView):
    authentication_classes = ()
    permission_classes = ()
    renderer_classes = (TemplateHTMLRenderer,)

    def get(self, request, *args, **kwargs):
        token = request.QUERY_PARAMS.get('token')

        user = User.objects.get_from_password_reset_token(token)

        if not user:
            raise Http404

        return Response(template_name='index.html')

{'fraction_non_alphanumeric': 0.08320031923383879, 'fraction_numerical': 0.005985634477254589, 'mean_word_length': 3.110291102911029, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1161218', 'n_tokens_mistral': 2798, 'n_tokens_neox': 2682, 'n_words': 519}