|
|
@@ -1,5 +1,6 @@
|
|
1
|
1
|
import warnings
|
|
2
|
2
|
|
|
|
3
|
+import django
|
|
3
|
4
|
from django.contrib.auth.backends import ModelBackend
|
|
4
|
5
|
from django.core.exceptions import ImproperlyConfigured
|
|
5
|
6
|
|
|
|
@@ -22,7 +23,7 @@ class EmailBackend(ModelBackend):
|
|
22
|
23
|
For this to work, the User model must have an 'email' field
|
|
23
|
24
|
"""
|
|
24
|
25
|
|
|
25
|
|
- def authenticate(self, email=None, password=None, *args, **kwargs):
|
|
|
26
|
+ def _authenticate(self, request, email=None, password=None, *args, **kwargs):
|
|
26
|
27
|
if email is None:
|
|
27
|
28
|
if 'username' not in kwargs or kwargs['username'] is None:
|
|
28
|
29
|
return None
|
|
|
@@ -55,14 +56,11 @@ class EmailBackend(ModelBackend):
|
|
55
|
56
|
"password")
|
|
56
|
57
|
return None
|
|
57
|
58
|
|
|
58
|
|
-
|
|
59
|
|
-# Deprecated since Oscar 1.0 because of the spelling.
|
|
60
|
|
-class Emailbackend(EmailBackend):
|
|
61
|
|
-
|
|
62
|
|
- def __init__(self):
|
|
63
|
|
- warnings.warn(
|
|
64
|
|
- "Oscar's auth backend EmailBackend has been renamed in Oscar 1.0 "
|
|
65
|
|
- " and you're using the old name of Emailbackend. Please rename "
|
|
66
|
|
- " all references; most likely in the AUTH_BACKENDS setting.",
|
|
67
|
|
- DeprecationWarning)
|
|
68
|
|
- super(Emailbackend, self).__init__()
|
|
|
59
|
+ # The signature of the authenticate method changed in Django 1.11 to include
|
|
|
60
|
+ # a mandatory `request` argument.
|
|
|
61
|
+ if django.VERSION < (1, 11):
|
|
|
62
|
+ def authenticate(self, email=None, password=None, *args, **kwargs):
|
|
|
63
|
+ return self._authenticate(None, email, password, *args, **kwargs)
|
|
|
64
|
+ else:
|
|
|
65
|
+ def authenticate(self, *args, **kwargs):
|
|
|
66
|
+ return self._authenticate(*args, **kwargs)
|