[Python-modules-commits] [djoser] 01/06: Import djoser_0.4.2.orig.tar.gz

Michael Fladischer fladi at moszumanska.debian.org
Thu Feb 25 08:09:14 UTC 2016


This is an automated email from the git hooks/post-receive script.

fladi pushed a commit to branch master
in repository djoser.

commit bd8569ee295c32e284661b7e2c9b45991bef882a
Author: Michael Fladischer <FladischerMichael at fladi.at>
Date:   Thu Feb 25 08:52:20 2016 +0100

    Import djoser_0.4.2.orig.tar.gz
---
 PKG-INFO                 | 32 +++++++++++++++++++++++++++++---
 README.md                | 30 +++++++++++++++++++++++++-----
 djoser.egg-info/PKG-INFO | 32 +++++++++++++++++++++++++++++---
 djoser/constants.py      |  1 +
 djoser/serializers.py    | 27 +++++++++++++++++++++------
 djoser/settings.py       |  3 ++-
 djoser/urls/authtoken.py |  4 ++--
 djoser/urls/base.py      |  6 +++---
 djoser/utils.py          |  8 ++------
 djoser/views.py          |  2 +-
 setup.cfg                |  2 +-
 setup.py                 |  2 +-
 12 files changed, 117 insertions(+), 32 deletions(-)

diff --git a/PKG-INFO b/PKG-INFO
index ac29265..751e243 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: djoser
-Version: 0.4.0
+Version: 0.4.2
 Summary: REST version of Django authentication system.
 Home-page: https://github.com/sunscrapers/djoser
 Author: SUNSCRAPERS
@@ -41,8 +41,8 @@ Description: djoser
         
         -  ``/me/``
         -  ``/register/``
-        -  ``/login/``
-        -  ``/logout/``
+        -  ``/login/`` (token based authentication)
+        -  ``/logout/`` (token based authentication)
         -  ``/activate/``
         -  ``/{{ User.USERNAME_FIELD }}/``
         -  ``/password/``
@@ -54,6 +54,7 @@ Description: djoser
         -  Python 2.6
         -  Python 2.7
         -  Python 3.4
+        -  Python 3.5
         
         Supported Django versions:
         
@@ -61,6 +62,7 @@ Description: djoser
         -  Django 1.6
         -  Django 1.7
         -  Django 1.8
+        -  Django 1.9
         
         Supported Django Rest Framework versions:
         
@@ -180,6 +182,7 @@ Description: djoser
                 'PASSWORD_RESET_CONFIRM_URL': '#/password/reset/confirm/{uid}/{token}',
                 'ACTIVATION_URL': '#/activate/{uid}/{token}',
                 'SEND_ACTIVATION_EMAIL': True,
+                'PASSWORD_VALIDATORS': []
             }
         
         Check "Settings" section for more info.
@@ -280,6 +283,8 @@ Description: djoser
         
         Use this endpoint to obtain user `authentication
         token <http://www.django-rest-framework.org/api-guide/authentication#tokenauthentication>`__.
+        This endpoint is available only if you are using token based
+        authentication.
         
         ``POST``
         ^^^^^^^^
@@ -306,6 +311,8 @@ Description: djoser
         ~~~~~~
         
         Use this endpoint to logout user (remove user authentication token).
+        This endpoint is available only if you are using token based
+        authentication.
         
         ``POST``
         ^^^^^^^^
@@ -512,6 +519,18 @@ Description: djoser
         
         **Default**: ``False``
         
+        PASSWORD\_VALIDATORS
+        ~~~~~~~~~~~~~~~~~~~~
+        
+        List containing `REST Framework
+        Validator <http://www.django-rest-framework.org/api-guide/validators/>`__
+        functions. These validators are run on ``/register/`` and
+        ``/password/reset/confirm/``.
+        
+        **Default**: ``[]``
+        
+        **Example**: ``[my_validator1, my_validator2]``
+        
         Emails
         ------
         
@@ -661,6 +680,13 @@ Description: djoser
         
         ``$ ./manage.py test``
         
+        If you need to run tests against all supported Python and Django
+        versions then invoke:
+        
+        ``$ pip install tox``
+        
+        ``$ tox``
+        
         Similar projects
         ----------------
         
diff --git a/README.md b/README.md
index 3be4d9e..ecdfada 100644
--- a/README.md
+++ b/README.md
@@ -25,8 +25,8 @@ Available endpoints:
 
  * `/me/`
  * `/register/`
- * `/login/`
- * `/logout/`
+ * `/login/` (token based authentication)
+ * `/logout/` (token based authentication)
  * `/activate/`
  * `/{{ User.USERNAME_FIELD }}/`
  * `/password/`
@@ -38,6 +38,7 @@ Supported Python versions:
  * Python 2.6
  * Python 2.7
  * Python 3.4
+ * Python 3.5
 
 Supported Django versions:
 
@@ -45,12 +46,13 @@ Supported Django versions:
  * Django 1.6
  * Django 1.7
  * Django 1.8
+ * Django 1.9
 
 Supported Django Rest Framework versions:
 
  * Django Rest Framework 3.x
- 
-For Django Rest Framework 2.4 support check [djoser 0.3.2](https://github.com/sunscrapers/djoser/tree/0.3.2). 
+
+For Django Rest Framework 2.4 support check [djoser 0.3.2](https://github.com/sunscrapers/djoser/tree/0.3.2).
 
 ## Installation
 
@@ -147,6 +149,7 @@ DJOSER = {
     'PASSWORD_RESET_CONFIRM_URL': '#/password/reset/confirm/{uid}/{token}',
     'ACTIVATION_URL': '#/activate/{uid}/{token}',
     'SEND_ACTIVATION_EMAIL': True,
+    'PASSWORD_VALIDATORS': []
 }
 ```
 
@@ -237,6 +240,7 @@ URL: `/register/`
 ### Login
 
 Use this endpoint to obtain user [authentication token](http://www.django-rest-framework.org/api-guide/authentication#tokenauthentication).
+This endpoint is available only if you are using token based authentication.
 
 #### `POST`
 
@@ -260,7 +264,8 @@ URL: `/login/`
 
 ### Logout
 
-Use this endpoint to logout user (remove user authentication token).
+Use this endpoint to logout user (remove user authentication token). This endpoint is available only if you are using
+token based authentication.
 
 #### `POST`
 
@@ -442,6 +447,15 @@ endpoint in order to validate password equality.
 
 **Default**: `False`
 
+### PASSWORD_VALIDATORS
+
+List containing [REST Framework Validator](http://www.django-rest-framework.org/api-guide/validators/) functions.
+These validators are run on `/register/` and `/password/reset/confirm/`.
+
+**Default**: `[]`
+
+**Example**: `[my_validator1, my_validator2]`
+
 ## Emails
 
 There are few email templates which you may want to override:
@@ -577,6 +591,12 @@ In order to run the tests create virtualenv, go to repo directory and then:
 
 `$ ./manage.py test`
 
+If you need to run tests against all supported Python and Django versions then invoke:
+
+`$ pip install tox`
+
+`$ tox`
+
 ## Similar projects
 
 List of projects related to Django, REST and authentication:
diff --git a/djoser.egg-info/PKG-INFO b/djoser.egg-info/PKG-INFO
index ac29265..751e243 100644
--- a/djoser.egg-info/PKG-INFO
+++ b/djoser.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: djoser
-Version: 0.4.0
+Version: 0.4.2
 Summary: REST version of Django authentication system.
 Home-page: https://github.com/sunscrapers/djoser
 Author: SUNSCRAPERS
@@ -41,8 +41,8 @@ Description: djoser
         
         -  ``/me/``
         -  ``/register/``
-        -  ``/login/``
-        -  ``/logout/``
+        -  ``/login/`` (token based authentication)
+        -  ``/logout/`` (token based authentication)
         -  ``/activate/``
         -  ``/{{ User.USERNAME_FIELD }}/``
         -  ``/password/``
@@ -54,6 +54,7 @@ Description: djoser
         -  Python 2.6
         -  Python 2.7
         -  Python 3.4
+        -  Python 3.5
         
         Supported Django versions:
         
@@ -61,6 +62,7 @@ Description: djoser
         -  Django 1.6
         -  Django 1.7
         -  Django 1.8
+        -  Django 1.9
         
         Supported Django Rest Framework versions:
         
@@ -180,6 +182,7 @@ Description: djoser
                 'PASSWORD_RESET_CONFIRM_URL': '#/password/reset/confirm/{uid}/{token}',
                 'ACTIVATION_URL': '#/activate/{uid}/{token}',
                 'SEND_ACTIVATION_EMAIL': True,
+                'PASSWORD_VALIDATORS': []
             }
         
         Check "Settings" section for more info.
@@ -280,6 +283,8 @@ Description: djoser
         
         Use this endpoint to obtain user `authentication
         token <http://www.django-rest-framework.org/api-guide/authentication#tokenauthentication>`__.
+        This endpoint is available only if you are using token based
+        authentication.
         
         ``POST``
         ^^^^^^^^
@@ -306,6 +311,8 @@ Description: djoser
         ~~~~~~
         
         Use this endpoint to logout user (remove user authentication token).
+        This endpoint is available only if you are using token based
+        authentication.
         
         ``POST``
         ^^^^^^^^
@@ -512,6 +519,18 @@ Description: djoser
         
         **Default**: ``False``
         
+        PASSWORD\_VALIDATORS
+        ~~~~~~~~~~~~~~~~~~~~
+        
+        List containing `REST Framework
+        Validator <http://www.django-rest-framework.org/api-guide/validators/>`__
+        functions. These validators are run on ``/register/`` and
+        ``/password/reset/confirm/``.
+        
+        **Default**: ``[]``
+        
+        **Example**: ``[my_validator1, my_validator2]``
+        
         Emails
         ------
         
@@ -661,6 +680,13 @@ Description: djoser
         
         ``$ ./manage.py test``
         
+        If you need to run tests against all supported Python and Django
+        versions then invoke:
+        
+        ``$ pip install tox``
+        
+        ``$ tox``
+        
         Similar projects
         ----------------
         
diff --git a/djoser/constants.py b/djoser/constants.py
index 9281d12..481c305 100644
--- a/djoser/constants.py
+++ b/djoser/constants.py
@@ -3,6 +3,7 @@ from django.utils.translation import ugettext_lazy as _
 INVALID_CREDENTIALS_ERROR = _('Unable to login with provided credentials.')
 INACTIVE_ACCOUNT_ERROR = _('User account is disabled.')
 INVALID_TOKEN_ERROR = _('Invalid token for given user.')
+STALE_TOKEN_ERROR = _('Stale token for given user.')
 PASSWORD_MISMATCH_ERROR = _('The two password fields didn\'t match.')
 USERNAME_MISMATCH_ERROR = _('The two {0} fields didn\'t match.')
 INVALID_PASSWORD_ERROR = _('Invalid password.')
diff --git a/djoser/serializers.py b/djoser/serializers.py
index 5bd1bae..4b6742a 100644
--- a/djoser/serializers.py
+++ b/djoser/serializers.py
@@ -1,7 +1,7 @@
 from django.contrib.auth import authenticate, get_user_model
-from rest_framework import serializers
+from rest_framework import exceptions, serializers
 from rest_framework.authtoken.models import Token
-from . import constants, utils
+from . import constants, utils, settings
 
 User = get_user_model()
 
@@ -20,7 +20,9 @@ class UserSerializer(serializers.ModelSerializer):
 
 
 class UserRegistrationSerializer(serializers.ModelSerializer):
-    password = serializers.CharField(style={'input_type': 'password'}, write_only=True)
+    password = serializers.CharField(style={'input_type': 'password'},
+                                     write_only=True,
+                                     validators=settings.get('PASSWORD_VALIDATORS'))
 
     class Meta:
         model = User
@@ -66,7 +68,7 @@ class UidAndTokenSerializer(serializers.Serializer):
     token = serializers.CharField()
 
     default_error_messages = {
-        'invalid_token': constants.INVALID_TOKEN_ERROR
+        'invalid_token': constants.INVALID_TOKEN_ERROR,
     }
 
     def validate_uid(self, value):
@@ -74,7 +76,7 @@ class UidAndTokenSerializer(serializers.Serializer):
             uid = utils.decode_uid(value)
             self.user = User.objects.get(pk=uid)
         except (User.DoesNotExist, ValueError, TypeError, OverflowError) as error:
-            raise serializers.ValidationError(error)
+            raise serializers.ValidationError(str(error))
         return value
 
     def validate(self, attrs):
@@ -84,8 +86,21 @@ class UidAndTokenSerializer(serializers.Serializer):
         return attrs
 
 
+class ActivationSerializer(UidAndTokenSerializer):
+    default_error_messages = {
+        'stale_token': constants.STALE_TOKEN_ERROR,
+    }
+
+    def validate(self, attrs):
+        attrs = super(ActivationSerializer, self).validate(attrs)
+        if self.user.is_active:
+            raise exceptions.PermissionDenied(self.error_messages['stale_token'])
+        return attrs
+
+
 class PasswordSerializer(serializers.Serializer):
-    new_password = serializers.CharField(style={'input_type': 'password'})
+    new_password = serializers.CharField(style={'input_type': 'password'},
+                                         validators=settings.get('PASSWORD_VALIDATORS'))
 
 
 class PasswordRetypeSerializer(PasswordSerializer):
diff --git a/djoser/settings.py b/djoser/settings.py
index 4ea75b9..f15c4bd 100644
--- a/djoser/settings.py
+++ b/djoser/settings.py
@@ -9,9 +9,10 @@ def get(key):
         'SET_USERNAME_RETYPE': False,
         'PASSWORD_RESET_CONFIRM_RETYPE': False,
         'ROOT_VIEW_URLS_MAPPING': {},
+        'PASSWORD_VALIDATORS': []
     }
     defaults.update(getattr(settings, 'DJOSER', {}))
     try:
         return defaults[key]
     except KeyError:
-        raise ImproperlyConfigured('Missing settings: DJOSER[\'{}\']'.format(key))
\ No newline at end of file
+        raise ImproperlyConfigured('Missing settings: DJOSER[\'{}\']'.format(key))
diff --git a/djoser/urls/authtoken.py b/djoser/urls/authtoken.py
index 47374ca..73211cd 100644
--- a/djoser/urls/authtoken.py
+++ b/djoser/urls/authtoken.py
@@ -1,8 +1,8 @@
-from django.conf.urls import patterns, url
+from django.conf.urls import url
 from djoser import views
 from . import base
 
-urlpatterns = base.base_urlpatterns + patterns('',
+urlpatterns = base.base_urlpatterns + (
     url(r'^login/$', views.LoginView.as_view(), name='login'),
     url(r'^logout/$', views.LogoutView.as_view(), name='logout'),
     url(r'^$', views.RootView.as_view(urls_extra_mapping={'login': 'login', 'logout': 'logout'}), name='root'),
diff --git a/djoser/urls/base.py b/djoser/urls/base.py
index 1f63d4a..d3eebc4 100644
--- a/djoser/urls/base.py
+++ b/djoser/urls/base.py
@@ -1,10 +1,10 @@
-from django.conf.urls import patterns, url
+from django.conf.urls import url
 from djoser import views
 from django.contrib.auth import get_user_model
 
 User = get_user_model()
 
-base_urlpatterns = patterns('',
+base_urlpatterns = (
     url(r'^me/$', views.UserView.as_view(), name='user'),
     url(r'^register/$', views.RegistrationView.as_view(), name='register'),
     url(r'^activate/$', views.ActivationView.as_view(), name='activate'),
@@ -14,4 +14,4 @@ base_urlpatterns = patterns('',
     url(r'^password/reset/confirm/$', views.PasswordResetConfirmView.as_view(), name='password_reset_confirm'),
 )
 
-urlpatterns = base_urlpatterns + patterns('', url(r'^$', views.RootView.as_view(), name='root'))
+urlpatterns = base_urlpatterns + (url(r'^$', views.RootView.as_view(), name='root'),)
diff --git a/djoser/utils.py b/djoser/utils.py
index ba53cd0..f7408aa 100644
--- a/djoser/utils.py
+++ b/djoser/utils.py
@@ -97,12 +97,8 @@ class SendEmailViewMixin(object):
     def get_email_context(self, user):
         token = self.token_generator.make_token(user)
         uid = encode_uid(user.pk)
-        try:
-            domain = django_settings.DJOSER['DOMAIN']
-            site_name = django_settings.DJOSER['SITE_NAME']
-        except KeyError:
-            site = get_current_site(self.request)
-            domain, site_name = site.domain, site.name
+        domain = django_settings.DJOSER.get('DOMAIN') or get_current_site(self.request).domain
+        site_name = django_settings.DJOSER.get('SITE_NAME') or get_current_site(self.request).name
         return {
             'user': user,
             'domain': domain,
diff --git a/djoser/views.py b/djoser/views.py
index 3037dff..ad73883 100644
--- a/djoser/views.py
+++ b/djoser/views.py
@@ -172,7 +172,7 @@ class ActivationView(utils.ActionViewMixin, generics.GenericAPIView):
     """
     Use this endpoint to activate user account.
     """
-    serializer_class = serializers.UidAndTokenSerializer
+    serializer_class = serializers.ActivationSerializer
     permission_classes = (
         permissions.AllowAny,
     )
diff --git a/setup.cfg b/setup.cfg
index 72f9d44..ebbec92 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,5 +1,5 @@
 [egg_info]
+tag_build = 
 tag_svn_revision = 0
 tag_date = 0
-tag_build = 
 
diff --git a/setup.py b/setup.py
index b98e8a9..19fe20a 100644
--- a/setup.py
+++ b/setup.py
@@ -22,7 +22,7 @@ def get_requirements(file_name):
 
 setup(
     name='djoser',
-    version='0.4.0',
+    version='0.4.2',
     packages=get_packages('djoser'),
     license='MIT',
     author='SUNSCRAPERS',

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/djoser.git



More information about the Python-modules-commits mailing list