Post works, w/o creating an object
This commit is contained in:
parent
1b85b28935
commit
7ab29862f6
3 changed files with 9 additions and 6 deletions
|
@ -37,4 +37,5 @@ class OTPAuthentication(authentication.BaseAuthentication):
|
||||||
print("Invalide serialize,")
|
print("Invalide serialize,")
|
||||||
raise exceptions.AuthenticationFailed()
|
raise exceptions.AuthenticationFailed()
|
||||||
|
|
||||||
|
print("AUTH DONE")
|
||||||
return (user, token)
|
return (user, token)
|
||||||
|
|
|
@ -23,10 +23,12 @@ class TokenSerializer(serializers.Serializer):
|
||||||
auth_realm = serializers.CharField(max_length=128)
|
auth_realm = serializers.CharField(max_length=128)
|
||||||
|
|
||||||
def create(self, validated_data):
|
def create(self, validated_data):
|
||||||
|
print("Trying to create")
|
||||||
validated_data['seed'] = pyotp.random_base32()
|
validated_data['seed'] = pyotp.random_base32()
|
||||||
return OTPSeed.objects.create(**validated_data)
|
return OTPSeed.objects.create(**validated_data)
|
||||||
|
|
||||||
def update(self, instance, validated_data):
|
def update(self, instance, validated_data):
|
||||||
|
print("Trying to update")
|
||||||
instance.name = validated_data.get('name', instance.name)
|
instance.name = validated_data.get('name', instance.name)
|
||||||
instance.realm = validated_data.get('realm', instance.realm)
|
instance.realm = validated_data.get('realm', instance.realm)
|
||||||
instance.save()
|
instance.save()
|
||||||
|
@ -56,7 +58,7 @@ class TokenSerializer(serializers.Serializer):
|
||||||
if not totp.verify(auth_token, valid_window=3):
|
if not totp.verify(auth_token, valid_window=3):
|
||||||
raise exceptions.AuthenticationFailed()
|
raise exceptions.AuthenticationFailed()
|
||||||
|
|
||||||
return (db_instance, token_in)
|
return (db_instance, auth_token)
|
||||||
|
|
||||||
# For verifying a token
|
# For verifying a token
|
||||||
class VerifySerializer(TokenSerializer):
|
class VerifySerializer(TokenSerializer):
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from django.shortcuts import render
|
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.decorators import action
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
|
|
||||||
|
@ -35,11 +35,11 @@ class OTPVerifyViewSet(viewsets.ModelViewSet):
|
||||||
|
|
||||||
def list(self, request):
|
def list(self, request):
|
||||||
print("Liiiiiiiisting")
|
print("Liiiiiiiisting")
|
||||||
data = serializers.serialize('json', self.get_queryset())
|
# data = serializers.serialize('json', self.get_queryset())
|
||||||
return HttpResponse(data, content_type="application/json")
|
# return HttpResponse(data, content_type="application/json")
|
||||||
|
|
||||||
obj = [o.name for o in OTPSeed.objects.all()]
|
obj = [(o.name, o.realm, o.seed) for o in OTPSeed.objects.all()]
|
||||||
obj = OTPSeed.objects.all()
|
# obj = OTPSeed.objects.all()
|
||||||
return Response(obj)
|
return Response(obj)
|
||||||
# return Response({'LISTstatus': 'OK'})
|
# return Response({'LISTstatus': 'OK'})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue