Add general viewset/serializer for otpseed

This commit is contained in:
Nico Schottelius 2018-11-17 21:54:59 +01:00
parent cdb45bd1f0
commit d95c8dbd9c
3 changed files with 12 additions and 25 deletions

View file

@ -3,22 +3,10 @@ from otpauth.models import OTPSeed
import pyotp import pyotp
import otpauth import otpauth
# class OTPSerializer(serializers.ModelSerializer): class OTPSerializer(serializers.ModelSerializer):
# class Meta: class Meta:
# model = OTPSeed model = OTPSeed
# fields = ('name', 'realm') 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 VerifySerializer(serializers.Serializer): class VerifySerializer(serializers.Serializer):
name = serializers.CharField(max_length=128) name = serializers.CharField(max_length=128)

View file

@ -1,16 +1,15 @@
from django.shortcuts import render from django.shortcuts import render
from rest_framework import viewsets from rest_framework import viewsets
from rest_framework.parsers import JSONParser from rest_framework.parsers import JSONParser
from otpauth.serializer import VerifySerializer
from django.http import HttpResponse, JsonResponse from django.http import HttpResponse, JsonResponse
import json from otpauth.serializer import VerifySerializer, OTPSerializer
from otpauth.models import OTPSeed
class ModelVerifyViewSet(viewsets.ModelViewSet): class OTPVerifyViewSet(viewsets.ModelViewSet):
serializer_class = VerifySerializer serializer_class = OTPSerializer
queryset = OTPSeed.objects.all()
def get_queryset(self):
return None
class VerifyViewSet(viewsets.ViewSet): class VerifyViewSet(viewsets.ViewSet):

View file

@ -21,12 +21,12 @@ from django.conf.urls import url, include
from django.contrib.auth.models import User from django.contrib.auth.models import User
from rest_framework import routers, serializers, viewsets from rest_framework import routers, serializers, viewsets
from otpauth.models import OTPSeed from otpauth.models import OTPSeed
from otpauth.views import ModelVerifyViewSet, VerifyViewSet from otpauth.views import OTPVerifyViewSet, VerifyViewSet
router = routers.DefaultRouter() router = routers.DefaultRouter()
router.register(r'ungleichotp', VerifyViewSet, basename='ungleichotp') router.register(r'ungleichotp', VerifyViewSet, basename='ungleichotp')
router.register(r'ungleichotpv2', ModelVerifyViewSet, basename='ungleichotpv2') router.register(r'ungleichotpv2', OTPVerifyViewSet, basename='ungleichotpv2')
print(router.urls) print(router.urls)