From 26789ff11b4023310a5ed3fe8afe030d988ca8c5 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 18 Nov 2018 12:54:47 +0100 Subject: [PATCH] Move AUTH code into model of otpauth To prevent the following exception: File "/home/nico/vcs/ungleich-otp/venv/lib/python3.5/site-packages/django/db/models/base.py", line 87, in __new__ app_config = apps.get_containing_app_config(module) File "/home/nico/vcs/ungleich-otp/venv/lib/python3.5/site-packages/django/apps/registry.py", line 249, in get_containing_app_config self.check_apps_ready() File "/home/nico/vcs/ungleich-otp/venv/lib/python3.5/site-packages/django/apps/registry.py", line 132, in check_apps_ready raise AppRegistryNotReady("Apps aren't loaded yet.") django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet. (venv) [12:41] line:ungleichotp% --- ungleichotp/otpauth/models.py | 18 ++++++++++++++++++ ungleichotp/ungleichotp/settings.py | 19 +------------------ 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/ungleichotp/otpauth/models.py b/ungleichotp/otpauth/models.py index 50080e0..78e7e57 100644 --- a/ungleichotp/otpauth/models.py +++ b/ungleichotp/otpauth/models.py @@ -26,3 +26,21 @@ class OTPSeed(AbstractUser): # @classmethod # def has_usable_password(cls): # pass + + +from rest_framework import exceptions +from rest_framework import authentication +from otpauth.models import OTPSeed +from otpauth.serializer import TokenSerializer + +class OTPAuthentication(authentication.BaseAuthentication): + def authenticate(self, request): + serializer = TokenSerializer(data=request.data) + + if serializer.is_valid(): + print("trying to save... {}".format(serializer)) + user = serializer.save() + else: + raise exceptions.AuthenticationFailed() + + return (user, None) diff --git a/ungleichotp/ungleichotp/settings.py b/ungleichotp/ungleichotp/settings.py index 3044056..af24e79 100644 --- a/ungleichotp/ungleichotp/settings.py +++ b/ungleichotp/ungleichotp/settings.py @@ -102,26 +102,9 @@ AUTH_PASSWORD_VALIDATORS = [ ] -from rest_framework import exceptions -from rest_framework import authentication -from otpauth.models import OTPSeed -from otpauth.serializer import TokenSerializer - -class OTPAuthentication(authentication.BaseAuthentication): - def authenticate(self, request): - serializer = TokenSerializer(data=request.data) - - if serializer.is_valid(): - print("trying to save... {}".format(serializer)) - user = serializer.save() - else: - raise exceptions.AuthenticationFailed() - - return (user, None) - REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': ( - 'OTPAuthentication' + 'otpauth.models.OTPAuthentication' ) }