diff --git a/otpauth/models.py b/otpauth/models.py index 6f7cfea..564835e 100644 --- a/otpauth/models.py +++ b/otpauth/models.py @@ -37,4 +37,5 @@ class OTPAuthentication(authentication.BaseAuthentication): print("Invalide serialize,") raise exceptions.AuthenticationFailed() + print("AUTH DONE") return (user, token) diff --git a/otpauth/serializer.py b/otpauth/serializer.py index b2fbbfa..bb9d6e0 100644 --- a/otpauth/serializer.py +++ b/otpauth/serializer.py @@ -23,10 +23,12 @@ class TokenSerializer(serializers.Serializer): auth_realm = serializers.CharField(max_length=128) def create(self, validated_data): + print("Trying to create") validated_data['seed'] = pyotp.random_base32() return OTPSeed.objects.create(**validated_data) def update(self, instance, validated_data): + print("Trying to update") instance.name = validated_data.get('name', instance.name) instance.realm = validated_data.get('realm', instance.realm) instance.save() @@ -56,7 +58,7 @@ class TokenSerializer(serializers.Serializer): if not totp.verify(auth_token, valid_window=3): raise exceptions.AuthenticationFailed() - return (db_instance, token_in) + return (db_instance, auth_token) # For verifying a token class VerifySerializer(TokenSerializer): diff --git a/otpauth/views.py b/otpauth/views.py index 44b8c0a..2ab0e4d 100644 --- a/otpauth/views.py +++ b/otpauth/views.py @@ -1,6 +1,6 @@ from django.shortcuts import render -from rest_framework import viewsets +from rest_framework import viewsets, serializers from rest_framework.decorators import action from rest_framework.response import Response @@ -35,11 +35,11 @@ class OTPVerifyViewSet(viewsets.ModelViewSet): def list(self, request): print("Liiiiiiiisting") - data = serializers.serialize('json', self.get_queryset()) - return HttpResponse(data, content_type="application/json") + # data = serializers.serialize('json', self.get_queryset()) + # return HttpResponse(data, content_type="application/json") - obj = [o.name for o in OTPSeed.objects.all()] - obj = OTPSeed.objects.all() + obj = [(o.name, o.realm, o.seed) for o in OTPSeed.objects.all()] +# obj = OTPSeed.objects.all() return Response(obj) # return Response({'LISTstatus': 'OK'})