From 2d147d961c53fb36f2e5e32a5f7126170f9025ce Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sat, 17 Nov 2018 22:28:17 +0100 Subject: [PATCH] Implement seed generating --- README.md | 8 ++++---- ungleichotp/otpauth/serializer.py | 11 +++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 31d2292..d983882 100644 --- a/README.md +++ b/README.md @@ -293,8 +293,10 @@ Don’t forget to point AUTH_USER_MODEL to it. Do this before creating any migra - [x] serialize / input request - [x] Make seed read only -- [ ] Remove hard coded JSON -- [ ] Implement registering of new entries +- [x] Implement registering of new entries +- [x] OTPSerializer: allow to read seed for admin +- [x] Implement deleting entry +- [ ] Remove hard coded JSON (?) - [ ] Use Custom authentication (?) - needs to have a user - [ ] Maybe we map name+realm == User (?) - name == name@realm @@ -303,5 +305,3 @@ Don’t forget to point AUTH_USER_MODEL to it. Do this before creating any migra - custom auth method - [ ] Implement creating new "User" - by POST / Model based -- [ ] Implement deleting "User" -- [ ] OTPSerializer: allow to read seed for admin diff --git a/ungleichotp/otpauth/serializer.py b/ungleichotp/otpauth/serializer.py index bc7a084..a8a9980 100644 --- a/ungleichotp/otpauth/serializer.py +++ b/ungleichotp/otpauth/serializer.py @@ -9,6 +9,17 @@ class OTPSerializer(serializers.ModelSerializer): fields = ('name', 'realm', 'seed') read_only_fields = ('seed',) + def create(self, validated_data): + print(validated_data) + print("BEING CALLED??") + name = validated_data.get('name') + realm = validated_data.get('realm') + + # validated_data + seed = pyotp.random_base32() + validated_data['seed'] = seed + + return OTPSeed.objects.create(**validated_data) class VerifySerializer(serializers.Serializer): name = serializers.CharField(max_length=128)