From 02dd509a5a42fb7ab77571584e5eb5519cc8481d Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sat, 17 Nov 2018 17:46:16 +0100 Subject: [PATCH] In between commit w/ serializer error --- requests/gendata.py | 1 - ungleichotp/otpauth/serializer.py | 44 +++++++++++++++++-------------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/requests/gendata.py b/requests/gendata.py index 9eb8185..78b4e27 100644 --- a/requests/gendata.py +++ b/requests/gendata.py @@ -13,7 +13,6 @@ request['verifytoken'] = request['token'] request['realm'] = "ungleich-admin" request['verifyrealm'] = request['realm'] -print(request) print(json.dumps(request)) data = json.dumps(request) diff --git a/ungleichotp/otpauth/serializer.py b/ungleichotp/otpauth/serializer.py index afd2d8d..cffa486 100644 --- a/ungleichotp/otpauth/serializer.py +++ b/ungleichotp/otpauth/serializer.py @@ -1,31 +1,35 @@ -from rest_framework import serializers +from rest_framework import serializers, exceptions from otpauth.models import OTPSeed import pyotp +import otpauth -class OTPSerializer(serializers.ModelSerializer): - class Meta: - model = OTPSeed - fields = ('name', 'realm') +# 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 VerifySerializer(serializers.Serializer): + name = serializers.CharField(max_length=128) token = serializers.CharField(max_length=128) + realm = 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 = serializers.CharField(max_length=128) - - verifyname = serializers.CharField(max_length=128) - verifytoken = serializers.CharField(max_length=128) - verifyrealm = serializers.CharField(max_length=128) - - def update(self, instance, validated_data): + def create(self, validated_data): token_in = validated_data.get('token') name_in = validated_data.get('name') realm_in = validated_data.get('realm') @@ -33,9 +37,9 @@ class VerifySerializer(serializers.ModelSerializer): try: db_instance = otpauth.models.OTPSeed.objects.get(name=name_in, realm=realm_in) except (OTPSeed.MultipleObjectsReturned, OTPSeed.DoesNotExist): - # FIXME: correct return? - return None + raise exceptions.PermissionDenied() + print("here?") # Generate token and compare totp = pyotp.TOTP(db_instance.seed)