Пример #1
0
    def post(self, request):
        user = User.objects.create_guest_user()
        user.name = 'dummy user'
        user.save()

        serializer = TokenSerializer(data={'token': gen_jwt(user)})
        serializer.is_valid(raise_exception=True)
        return Response(serializer.data)
Пример #2
0
    def post(self, request):
        user = User.objects.create_guest_user()
        user.name = 'dummy user'
        user.save()

        payload = jwt_payload_handler(user)
        token = jwt_encode_handler(payload)
        serializer = TokenSerializer(data={'token': token})
        serializer.is_valid(raise_exception=True)
        return Response(serializer.data)
Пример #3
0
    def post(self, request):
        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)

        user = User.objects.create_user(
            email=serializer.validated_data["email"],
            password=serializer.validated_data["password"])
        user.save()

        serializer = TokenSerializer(data={'token': gen_jwt(user)})
        serializer.is_valid(raise_exception=True)
        return Response(serializer.data)
Пример #4
0
    def post(self, request):
        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)

        if User.objects.filter(device_uuid=serializer.data['uuid']):
            message = {'detail': 'すでにそのユーザーは登録済みです。'}
            return Response(message, status=status.HTTP_400_BAD_REQUEST)

        user = User.objects.create_guest_user(
            device_uuid=serializer.data['uuid'])
        user.save()

        serializer = TokenSerializer(data={'token': gen_jwt(user)})
        serializer.is_valid(raise_exception=True)
        return Response(serializer.data)
Пример #5
0
    def post(self, request):
        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)

        user = User.objects.filter(device_uuid=serializer.data['uuid']).first()

        if user is None:
            message = {'detail': 'そのユーザーは存在しません'}
            return Response(message, status=status.HTTP_400_BAD_REQUEST)

        payload = jwt_payload_handler(user)
        token = jwt_encode_handler(payload)
        serializer = TokenSerializer(data={'token': token})
        serializer.is_valid(raise_exception=True)
        return Response(serializer.data)
Пример #6
0
    def post(self, request):
        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        code = serializer.data["digit"]

        auth = AuthDigit.objects.filter(code=code).last()
        if auth and auth.is_expired():
            serializer = MessageSerializer(
                data={'message': "確認コードの有効期限が切れています。再度発行してください。"})
            serializer.is_valid(raise_exception=True)
            return Response(serializer.data, status=400)
        elif auth is None or auth.code != code:
            serializer = MessageSerializer(
                data={'message': "確認コードが一致しませんでした。"})
            serializer.is_valid(raise_exception=True)
            return Response(serializer.data, status=400)

        prt = PasswordResetToken.update_or_create(auth.user)
        serializer = TokenSerializer(data={'token': prt.token})
        serializer.is_valid(raise_exception=True)
        auth.delete()
        return Response(serializer.data)