mirror of
https://github.com/Tivix/django-rest-auth.git
synced 2025-02-16 18:00:35 +03:00
Compatibility updates
+ removed some legacy code + added force_text for py3 support
This commit is contained in:
parent
315f6f2844
commit
6ace9de268
|
@ -35,5 +35,5 @@ urlpatterns = patterns('',
|
|||
url(r'^rest-auth/registration/', include('rest_auth.registration.urls')),
|
||||
url(r'^account/', include('allauth.urls')),
|
||||
url(r'^admin/', include(admin.site.urls)),
|
||||
url(r'^accounts/profile/$', RedirectView.as_view(url='/'), name='profile-redirect'),
|
||||
url(r'^accounts/profile/$', RedirectView.as_view(url='/', permanent=True), name='profile-redirect'),
|
||||
)
|
||||
|
|
|
@ -1,19 +1,18 @@
|
|||
from django.contrib.auth import get_user_model, authenticate
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.forms import PasswordResetForm, SetPasswordForm
|
||||
try:
|
||||
from django.utils.http import urlsafe_base64_decode as uid_decoder
|
||||
except:
|
||||
# make compatible with django 1.5
|
||||
from django.utils.http import base36_to_int as uid_decoder
|
||||
from django.contrib.auth.tokens import default_token_generator
|
||||
from django.utils.http import urlsafe_base64_decode as uid_decoder
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django import VERSION
|
||||
from django.utils.encoding import force_text
|
||||
|
||||
from rest_framework import serializers, exceptions
|
||||
from rest_framework.authtoken.models import Token
|
||||
from rest_framework.exceptions import ValidationError
|
||||
|
||||
# Get the UserModel
|
||||
UserModel = get_user_model()
|
||||
|
||||
|
||||
class LoginSerializer(serializers.Serializer):
|
||||
username = serializers.CharField(required=False, allow_blank=True)
|
||||
|
@ -146,11 +145,10 @@ class PasswordResetConfirmSerializer(serializers.Serializer):
|
|||
|
||||
def validate(self, attrs):
|
||||
self._errors = {}
|
||||
# Get the UserModel
|
||||
UserModel = get_user_model()
|
||||
|
||||
# Decode the uidb64 to uid to get User object
|
||||
try:
|
||||
uid = uid_decoder(attrs['uid'])
|
||||
uid = force_text(uid_decoder(attrs['uid']))
|
||||
self.user = UserModel._default_manager.get(pk=uid)
|
||||
except (TypeError, ValueError, OverflowError, UserModel.DoesNotExist):
|
||||
raise ValidationError({'uid': ['Invalid value']})
|
||||
|
@ -216,6 +214,6 @@ class PasswordChangeSerializer(serializers.Serializer):
|
|||
|
||||
def save(self):
|
||||
self.set_password_form.save()
|
||||
if VERSION[1] > 6 and not self.logout_on_password_change:
|
||||
if not self.logout_on_password_change:
|
||||
from django.contrib.auth import update_session_auth_hash
|
||||
update_session_auth_hash(self.request, self.user)
|
||||
|
|
|
@ -8,6 +8,7 @@ from django.contrib.auth import get_user_model
|
|||
from django.core import mail
|
||||
from django.test.utils import override_settings
|
||||
from django.contrib.sites.models import Site
|
||||
from django.utils.encoding import force_text
|
||||
|
||||
from allauth.socialaccount.models import SocialApp
|
||||
from allauth.socialaccount.providers.facebook.provider import GRAPH_API_URL
|
||||
|
@ -51,7 +52,7 @@ class BaseAPITestCase(object):
|
|||
is_json = bool(
|
||||
[x for x in self.response._headers['content-type'] if 'json' in x])
|
||||
if is_json and self.response.content:
|
||||
self.response.json = json.loads(self.response.content)
|
||||
self.response.json = json.loads(force_text(self.response.content))
|
||||
else:
|
||||
self.response.json = {}
|
||||
if status_code:
|
||||
|
@ -298,7 +299,7 @@ class APITestCase1(TestCase, BaseAPITestCase):
|
|||
data = {
|
||||
'new_password1': self.NEW_PASS,
|
||||
'new_password2': self.NEW_PASS,
|
||||
'uid': url_kwargs['uid'],
|
||||
'uid': force_text(url_kwargs['uid']),
|
||||
'token': '-wrong-token-'
|
||||
}
|
||||
self.post(url, data=data, status_code=400)
|
||||
|
@ -325,7 +326,7 @@ class APITestCase1(TestCase, BaseAPITestCase):
|
|||
data = {
|
||||
'new_password1': self.NEW_PASS,
|
||||
'new_password2': self.NEW_PASS,
|
||||
'uid': url_kwargs['uid'],
|
||||
'uid': force_text(url_kwargs['uid']),
|
||||
'token': url_kwargs['token']
|
||||
}
|
||||
url = reverse('rest_password_reset_confirm')
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
from six import string_types
|
||||
import sys
|
||||
if sys.version_info < (2, 7):
|
||||
from django.utils.importlib import import_module
|
||||
else:
|
||||
from importlib import import_module
|
||||
from importlib import import_module
|
||||
|
||||
|
||||
def import_callable(path_or_callable):
|
||||
|
|
4
setup.py
4
setup.py
|
@ -28,8 +28,8 @@ setup(
|
|||
keywords='django rest auth registration rest-framework django-registration api',
|
||||
zip_safe=False,
|
||||
install_requires=[
|
||||
'Django>=1.5.0',
|
||||
'djangorestframework>=3.0',
|
||||
'Django>=1.7.0',
|
||||
'djangorestframework>=3.1.0',
|
||||
'six>=1.9.0',
|
||||
],
|
||||
test_suite='runtests.runtests',
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import django
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
@ -18,15 +17,12 @@ IS_STAGING = False
|
|||
IS_PROD = False
|
||||
IS_TEST = 'test' in sys.argv or 'test_coverage' in sys.argv
|
||||
|
||||
if django.VERSION[:2] >= (1, 3):
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': ':memory:',
|
||||
}
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': ':memory:',
|
||||
}
|
||||
else:
|
||||
DATABASE_ENGINE = 'sqlite3'
|
||||
}
|
||||
|
||||
MIDDLEWARE_CLASSES = [
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
|
|
Loading…
Reference in New Issue
Block a user