From 5bd3e277df3fe925255302e4aa50a17118ea61b0 Mon Sep 17 00:00:00 2001 From: Samir Shah Date: Tue, 25 Apr 2017 08:30:17 +0300 Subject: [PATCH 6/8] Fix EmailBackend.authenticate() signature for Django 1.11. --- src/oscar/apps/customer/auth_backends.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/oscar/apps/customer/auth_backends.py b/src/oscar/apps/customer/auth_backends.py index 65b8778..6558454 100644 --- a/src/oscar/apps/customer/auth_backends.py +++ b/src/oscar/apps/customer/auth_backends.py @@ -1,5 +1,6 @@ import warnings +import django from django.contrib.auth.backends import ModelBackend from django.core.exceptions import ImproperlyConfigured @@ -22,7 +23,7 @@ class EmailBackend(ModelBackend): For this to work, the User model must have an 'email' field """ - def authenticate(self, email=None, password=None, *args, **kwargs): + def _authenticate(self, request, email=None, password=None, *args, **kwargs): if email is None: if 'username' not in kwargs or kwargs['username'] is None: return None @@ -55,14 +56,11 @@ class EmailBackend(ModelBackend): "password") return None - -# Deprecated since Oscar 1.0 because of the spelling. -class Emailbackend(EmailBackend): - - def __init__(self): - warnings.warn( - "Oscar's auth backend EmailBackend has been renamed in Oscar 1.0 " - " and you're using the old name of Emailbackend. Please rename " - " all references; most likely in the AUTH_BACKENDS setting.", - DeprecationWarning) - super(Emailbackend, self).__init__() + # The signature of the authenticate method changed in Django 1.11 to include + # a mandatory `request` argument. + if django.VERSION < (1, 11): + def authenticate(self, email=None, password=None, *args, **kwargs): + return self._authenticate(None, email, password, *args, **kwargs) + else: + def authenticate(self, *args, **kwargs): + return self._authenticate(*args, **kwargs) -- 2.9.4