In between commit w/ serializer error

This commit is contained in:
Nico Schottelius 2018-11-17 17:46:16 +01:00
parent aa7a4c4df3
commit 02dd509a5a
2 changed files with 24 additions and 21 deletions

View file

@ -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)

View file

@ -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)