<commit_before>from django.core.exceptions import ObjectDoesNotExist
from rest_framework import viewsets
from rest_framework_jwt.serializers import User
from FiNote_API.models import AuthUser
from FiNote_API.v1.user_serializer import *
from rest_framework.response import Response


class SignUpUserViewSet(viewsets.ViewSet):
    queryset = AuthUser.objects.all()
    serializer_class = SignUpUserSerializer

    @staticmethod
    def create(request):
        """
        ユーザを作成する
        :param request: username, password, email, birthyear
        :return         user's pk
        """

        data = request.data
        serializer = SignUpUserSerializer(data=data)

        if serializer.is_valid() and request.method == 'POST':
            if User.objects.filter(username=data['username']).exists():
                raise serializers.ValidationError('このユーザ名は既に使われています')

            if User.objects.filter(email=data['email']).exists():
                raise serializers.ValidationError('このメールアドレスは既に使われています')

            user = User.objects.create_user(
                username=data['username'],
                email=data['email'],
                password=data['password'],
                birthyear=data['birthyear'],
            )

            return Response({'id': user.pk})
        else:
            return Response(serializer.errors, 400)


class SignInUserViewSet(viewsets.ViewSet):
    queryset = AuthUser.objects.all()
    serializer_class = SignInUserSerializer

    @staticmethod
    def create(request):
        """
        ユーザログインを実施
        :param request: username, password
        :return         user's pk
        """

        data = request.data
        serializer = SignInUserSerializer(data=data)

        if not (serializer.is_valid() and request.method == 'POST'):
            raise serializers.ValidationError(serializer.errors)

        try:
            user = AuthUser.objects.get(username=data['username'])
        except:
            raise serializers.ValidationError('ユーザが見つかりませんでした')

        if not user.check_password(data['password'].encode('utf-8')):
            raise serializers.ValidationError('パスワードが間違っています')

        return Response({'id': user.pk})


class UpdatePasswordViewSet(viewsets.ViewSet):
    queryset = AuthUser.objects.all()
    serializer_class = UpdatePasswordSerializer

    @staticmethod
    def create(request):
        """
        パスワードを変更する

        :param request: username, now_password, new_password
        :return:        username
        """

        data = request.data
        serializer = UpdatePasswordSerializer(data=data)

        if serializer.is_valid() and request.method == 'POST':
            try:
                user = AuthUser.objects.get(username=data['username'])

            except ObjectDoesNotExist:
                raise serializers.ValidationError('ユーザが見つかりませんでした')

            if not user.check_password(data['now_password'].encode('utf-8')):
                raise serializers.ValidationError('現在のパスワードが異なるため変更に失敗しました')

            user.set_password(data['<PASSWORD>'])
            user.save()

            return Response({'username': str(user)})

        else:
            return Response(serializer.errors)


class UpdateEmailViewSet(viewsets.ViewSet):
    queryset = AuthUser.objects.all()
    serializer_class = UpdateEmailSerializer

    @staticmethod
    def create(request):
        """
        メールアドレスを変更する

        :param request: username, password, new_email
        :return:        username
        """

        data = request.data
        serializer = UpdateEmailSerializer(data=data)

        if serializer.is_valid() and request.method == 'POST':
            try:
                user = AuthUser.objects.get(username=data["username"])
            except ObjectDoesNotExist:
                raise serializers.ValidationError('ユーザが見つかりませんでした')

            if not user.check_password(data['password'].encode('utf-8')):
                raise serializers.ValidationError('パスワードが違います')

            user.email = data['new_email']
            user.save()

            return Response({'username': str(user)})

        else:
            raise serializers.ValidationError(serializer.errors)
<commit_msg>Sign Upのインデントを修正<commit_after>from django.core.exceptions import ObjectDoesNotExist
from rest_framework import viewsets
from rest_framework_jwt.serializers import User
from FiNote_API.models import AuthUser
from FiNote_API.v1.user_serializer import *
from rest_framework.response import Response


class SignUpUserViewSet(viewsets.ViewSet):
    queryset = AuthUser.objects.all()
    serializer_class = SignUpUserSerializer

    @staticmethod
    def create(request):
        """
        ユーザを作成する
        :param request: username, password, email, birthyear
        :return         user's pk
        """

        data = request.data
        serializer = SignUpUserSerializer(data=data)

        if not (serializer.is_valid() and request.method == 'POST'):
            raise serializers.ValidationError(serializer.errors)

        if User.objects.filter(username=data['username']).exists():
            raise serializers.ValidationError('このユーザ名は既に使われています')

        if User.objects.filter(email=data['email']).exists():
            raise serializers.ValidationError('このメールアドレスは既に使われています')

        user = User.objects.create_user(
            username=data['username'],
            email=data['email'],
            password=data['password'],
            birthyear=data['birthyear'],
        )

        return Response({'id': user.pk})


class SignInUserViewSet(viewsets.ViewSet):
    queryset = AuthUser.objects.all()
    serializer_class = SignInUserSerializer

    @staticmethod
    def create(request):
        """
        ユーザログインを実施
        :param request: username, password
        :return         user's pk
        """

        data = request.data
        serializer = SignInUserSerializer(data=data)

        if not (serializer.is_valid() and request.method == 'POST'):
            raise serializers.ValidationError(serializer.errors)

        try:
            user = AuthUser.objects.get(username=data['username'])
        except:
            raise serializers.ValidationError('ユーザが見つかりませんでした')

        if not user.check_password(data['password'].encode('utf-8')):
            raise serializers.ValidationError('パスワードが間違っています')

        return Response({'id': user.pk})


class UpdatePasswordViewSet(viewsets.ViewSet):
    queryset = AuthUser.objects.all()
    serializer_class = UpdatePasswordSerializer

    @staticmethod
    def create(request):
        """
        パスワードを変更する

        :param request: username, now_password, new_password
        :return:        username
        """

        data = request.data
        serializer = UpdatePasswordSerializer(data=data)

        if serializer.is_valid() and request.method == 'POST':
            try:
                user = AuthUser.objects.get(username=data['username'])

            except ObjectDoesNotExist:
                raise serializers.ValidationError('ユーザが見つかりませんでした')

            if not user.check_password(data['now_password'].encode('utf-8')):
                raise serializers.ValidationError('現在のパスワードが異なるため変更に失敗しました')

            user.set_password(data['<PASSWORD>'])
            user.save()

            return Response({'username': str(user)})

        else:
            return Response(serializer.errors)


class UpdateEmailViewSet(viewsets.ViewSet):
    queryset = AuthUser.objects.all()
    serializer_class = UpdateEmailSerializer

    @staticmethod
    def create(request):
        """
        メールアドレスを変更する

        :param request: username, password, new_email
        :return:        username
        """

        data = request.data
        serializer = UpdateEmailSerializer(data=data)

        if serializer.is_valid() and request.method == 'POST':
            try:
                user = AuthUser.objects.get(username=data["username"])
            except ObjectDoesNotExist:
                raise serializers.ValidationError('ユーザが見つかりませんでした')

            if not user.check_password(data['password'].encode('utf-8')):
                raise serializers.ValidationError('パスワードが違います')

            user.email = data['new_email']
            user.save()

            return Response({'username': str(user)})

        else:
            raise serializers.ValidationError(serializer.errors)

{'fraction_non_alphanumeric': 0.10096555012516391, 'fraction_numerical': 0.0013112409107164144, 'mean_word_length': 2.451254627725216, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6519355', 'n_tokens_mistral': 2467, 'n_tokens_neox': 2336, 'n_words': 416}