Add logging

This commit is contained in:
PCoder 2019-02-10 23:52:52 +01:00
parent d598b9584e
commit 1b4107306b

View file

@ -2,6 +2,10 @@ from django.db import models
from django.contrib.auth.models import AbstractUser
from rest_framework import exceptions
from rest_framework import authentication
import json
import logging
logger = logging.getLogger(__name__)
class OTPSeed(AbstractUser):
@ -27,17 +31,20 @@ from otpauth.serializer import TokenSerializer
class OTPAuthentication(authentication.BaseAuthentication):
def authenticate(self, request):
logger.debug("in authenticate {}".format(json.dumps(request.data)))
serializer = TokenSerializer(data=request.data)
if serializer.is_valid():
instance, token = serializer.save()
else:
logger.error("serializer is invalid")
raise exceptions.AuthenticationFailed()
# not dealing with admin realm -> can only be auth [see serializer]
if not instance.realm == "ungleich-admin":
if not request.path == "/ungleichotp/verify/":
logger.debug("request.path is not /ungleichotp/verify/")
raise exceptions.AuthenticationFailed()
# print("AUTH DONE: {} - {}".format(request.path, instance))
logger.debug("AUTH DONE: {} - {}".format(request.path, instance))
return (instance, token)