Cleanup, expose seed read only

This commit is contained in:
Nico Schottelius 2018-11-17 22:15:17 +01:00
parent d95c8dbd9c
commit 6f7d02f7fc
3 changed files with 22 additions and 1 deletions

View File

@ -292,6 +292,7 @@ Dont forget to point AUTH_USER_MODEL to it. Do this before creating any migra
## TODOs
- [x] serialize / input request
- [x] Make seed read only
- [ ] Remove hard coded JSON
- [ ] Implement registering of new entries
- [ ] Use Custom authentication (?) - needs to have a user
@ -303,3 +304,4 @@ Dont forget to point AUTH_USER_MODEL to it. Do this before creating any migra
- [ ] Implement creating new "User"
- by POST / Model based
- [ ] Implement deleting "User"
- [ ] OTPSerializer: allow to read seed for admin

View File

@ -6,7 +6,9 @@ import otpauth
class OTPSerializer(serializers.ModelSerializer):
class Meta:
model = OTPSeed
fields = ('name', 'realm')
fields = ('name', 'realm', 'seed')
read_only_fields = ('seed',)
class VerifySerializer(serializers.Serializer):
name = serializers.CharField(max_length=128)
@ -18,6 +20,7 @@ class VerifySerializer(serializers.Serializer):
verifyrealm = serializers.CharField(max_length=128)
def create(self, validated_data):
print("all going to be verified - CREATE")
token_in = validated_data.get('token')
name_in = validated_data.get('name')
realm_in = validated_data.get('realm')
@ -55,3 +58,6 @@ class VerifySerializer(serializers.Serializer):
print("All verified!")
return verifyinstance
def verify(self, validated_data):
print("all going to be verified - AAAAAAAA")

View File

@ -1,6 +1,10 @@
from django.shortcuts import render
from rest_framework import viewsets
from rest_framework.parsers import JSONParser
from rest_framework.decorators import action
from rest_framework.response import Response
from django.http import HttpResponse, JsonResponse
@ -11,6 +15,15 @@ class OTPVerifyViewSet(viewsets.ModelViewSet):
serializer_class = OTPSerializer
queryset = OTPSeed.objects.all()
@action(detail=False, methods=['post'])
def verify(self, request):
serializer = VerifySerializer(data=request.data)
if serializer.is_valid():
print(serializer)
return Response({'status': 'OK'})
return JsonResponse(serializer.errors, status=400)
class VerifyViewSet(viewsets.ViewSet):
serializer_class = VerifySerializer