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%
This commit is contained in:
Nico Schottelius 2018-11-18 12:54:47 +01:00
parent cbd2446243
commit 26789ff11b
2 changed files with 19 additions and 18 deletions

View File

@ -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)

View File

@ -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'
)
}