diff --git a/ungleichotp/otpauth/serializer.py b/ungleichotp/otpauth/serializer.py index 345c2be..4625adc 100644 --- a/ungleichotp/otpauth/serializer.py +++ b/ungleichotp/otpauth/serializer.py @@ -3,22 +3,10 @@ from otpauth.models import OTPSeed import pyotp import otpauth -# class OTPSerializer(serializers.ModelSerializer): -# class Meta: -# model = OTPSeed -# fields = ('name', 'realm') - -# token = serializers.CharField(max_length=128) - -# verifyname = serializers.CharField(max_length=128) -# verifytoken = serializers.CharField(max_length=128) -# verifyrealm = serializers.CharField(max_length=128) - - -# class VerifySerializer(serializers.ModelSerializer): -# class Meta: -# model = OTPSeed -# fields = ('name', 'realm', 'token', 'verifyname', 'verifytoken', 'verifyrealm') +class OTPSerializer(serializers.ModelSerializer): + class Meta: + model = OTPSeed + fields = ('name', 'realm') class VerifySerializer(serializers.Serializer): name = serializers.CharField(max_length=128) diff --git a/ungleichotp/otpauth/views.py b/ungleichotp/otpauth/views.py index b15fbce..9fb6b42 100644 --- a/ungleichotp/otpauth/views.py +++ b/ungleichotp/otpauth/views.py @@ -1,16 +1,15 @@ from django.shortcuts import render from rest_framework import viewsets from rest_framework.parsers import JSONParser -from otpauth.serializer import VerifySerializer + from django.http import HttpResponse, JsonResponse -import json +from otpauth.serializer import VerifySerializer, OTPSerializer +from otpauth.models import OTPSeed -class ModelVerifyViewSet(viewsets.ModelViewSet): - serializer_class = VerifySerializer - - def get_queryset(self): - return None +class OTPVerifyViewSet(viewsets.ModelViewSet): + serializer_class = OTPSerializer + queryset = OTPSeed.objects.all() class VerifyViewSet(viewsets.ViewSet): diff --git a/ungleichotp/ungleichotp/urls.py b/ungleichotp/ungleichotp/urls.py index 740f82c..05b26cd 100644 --- a/ungleichotp/ungleichotp/urls.py +++ b/ungleichotp/ungleichotp/urls.py @@ -21,12 +21,12 @@ from django.conf.urls import url, include from django.contrib.auth.models import User from rest_framework import routers, serializers, viewsets from otpauth.models import OTPSeed -from otpauth.views import ModelVerifyViewSet, VerifyViewSet +from otpauth.views import OTPVerifyViewSet, VerifyViewSet router = routers.DefaultRouter() router.register(r'ungleichotp', VerifyViewSet, basename='ungleichotp') -router.register(r'ungleichotpv2', ModelVerifyViewSet, basename='ungleichotpv2') +router.register(r'ungleichotpv2', OTPVerifyViewSet, basename='ungleichotpv2') print(router.urls)