[Python-modules-commits] [djoser] 01/06: Imported Upstream version 0.4.0
Michael Fladischer
fladi at moszumanska.debian.org
Fri Dec 11 10:50:48 UTC 2015
This is an automated email from the git hooks/post-receive script.
fladi pushed a commit to annotated tag debian/0.4.0-1
in repository djoser.
commit 75bce4e1548c92cdc683eba2e3da959a659244fd
Author: Michael Fladischer <FladischerMichael at fladi.at>
Date: Thu Oct 1 18:14:06 2015 +0200
Imported Upstream version 0.4.0
---
PKG-INFO | 119 ++++++++++++++++++++++++---------------
README.md | 95 +++++++++++++++++++------------
djoser.egg-info/PKG-INFO | 119 ++++++++++++++++++++++++---------------
djoser.egg-info/SOURCES.txt | 6 +-
djoser.egg-info/requires.txt | 2 +-
djoser.egg-info/top_level.txt | 1 +
djoser/serializers.py | 86 +++++-----------------------
djoser/settings.py | 3 +-
djoser/urls/__init__.py | 1 +
djoser/urls/authtoken.py | 9 +++
djoser/{urls.py => urls/base.py} | 9 ++-
djoser/utils.py | 7 ++-
djoser/views.py | 61 +++++++++-----------
requirements.txt | 2 +-
setup.cfg | 4 +-
setup.py | 18 ++++--
16 files changed, 290 insertions(+), 252 deletions(-)
diff --git a/PKG-INFO b/PKG-INFO
index fb5388c..ac29265 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: djoser
-Version: 0.3.2
+Version: 0.4.0
Summary: REST version of Django authentication system.
Home-page: https://github.com/sunscrapers/djoser
Author: SUNSCRAPERS
@@ -23,18 +23,20 @@ Description: djoser
App <http://en.wikipedia.org/wiki/Single-page_application>`__
architecture.
- We use **token based authentication**. The concept is simple - first of
- all, users obtain a token by providing their credentials (e.g. username,
- password) during logging in. Once the token is obtained users can offer
- it in order to retrieve a specific resource. Django REST framework
- supports `token based
- authentication <http://www.django-rest-framework.org/api-guide/authentication#tokenauthentication>`__
- but you might be interested in other authentication mechanisms like
- OAuth or session-based authentication.
-
Developed by `SUNSCRAPERS <http://sunscrapers.com/>`__ with passion &
patience.
+ Features
+ --------
+
+ Here is a list of supported authentication backends:
+
+ - `HTTP Basic
+ Auth <http://www.django-rest-framework.org/api-guide/authentication/#basicauthentication>`__
+ (Default)
+ - `Token based authentication from Django Rest
+ Framework <http://www.django-rest-framework.org/api-guide/authentication#tokenauthentication>`__
+
Available endpoints:
- ``/me/``
@@ -62,9 +64,11 @@ Description: djoser
Supported Django Rest Framework versions:
- - Django Rest Framework 2.4
- 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>`__.
+
Installation
------------
@@ -74,8 +78,8 @@ Description: djoser
$ pip install djoser
- Usage
- -----
+ Quick Start
+ -----------
Configure ``INSTALLED_APPS``:
@@ -85,7 +89,6 @@ Description: djoser
'django.contrib.auth',
(...),
'rest_framework',
- 'rest_framework.authtoken',
'djoser',
(...),
)
@@ -99,7 +102,54 @@ Description: djoser
url(r'^auth/', include('djoser.urls')),
)
- Use ``TokenAuthentication`` as default Django Rest Framework
+ HTTP Basic Auth strategy is assumed by default as Django Rest Framework
+ does it. However you may want to set it explicitly:
+
+ .. code:: python
+
+ REST_FRAMEWORK = {
+ 'DEFAULT_AUTHENTICATION_CLASSES': (
+ 'rest_framework.authentication.BasicAuthentication',
+ ),
+ }
+
+ Run migrations (if you are using Django 1.7+ or South) - this step will
+ create tables for ``auth`` app:
+
+ ::
+
+ $ ./manage.py migrate
+
+ Customizing authentication backend
+ ----------------------------------
+
+ Token Based Authentication
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ Add ``'rest_framework.authtoken'`` to ``INSTALLED_APPS``:
+
+ .. code:: python
+
+ INSTALLED_APPS = (
+ 'django.contrib.auth',
+ (...),
+ 'rest_framework',
+ 'rest_framework.authtoken',
+ 'djoser',
+ (...),
+ )
+
+ Configure ``urls.py``. Pay attention to ``djoser.url.authtoken`` module
+ path.
+
+ .. code:: python
+
+ urlpatterns = patterns('',
+ (...),
+ url(r'^auth/', include('djoser.urls.authtoken')),
+ )
+
+ Set ``TokenAuthentication`` as default Django Rest Framework
authentication strategy:
.. code:: python
@@ -117,6 +167,9 @@ Description: djoser
$ ./manage.py migrate
+ Settings
+ --------
+
Optionally add ``DJOSER`` settings:
.. code:: python
@@ -126,7 +179,6 @@ Description: djoser
'SITE_NAME': 'Frontend',
'PASSWORD_RESET_CONFIRM_URL': '#/password/reset/confirm/{uid}/{token}',
'ACTIVATION_URL': '#/activate/{uid}/{token}',
- 'LOGIN_AFTER_ACTIVATION': True,
'SEND_ACTIVATION_EMAIL': True,
}
@@ -196,9 +248,6 @@ Description: djoser
`REQUIRED\_FIELDS <https://docs.djangoproject.com/en/dev/topics/auth/customizing/#django.contrib.auth.models.CustomUser.REQUIRED_FIELDS>`__
fields.
- If ``LOGIN_AFTER_REGISTRATION`` is ``True``, you will receive
- authentication token within response.
-
``POST``
^^^^^^^^
@@ -226,8 +275,6 @@ Description: djoser
``{{ User.REQUIRED_FIELDS }}``
- ``auth_token`` (if ``LOGIN_AFTER_REGISTRATION`` is ``True``)
-
Login
~~~~~
@@ -272,9 +319,9 @@ Description: djoser
Activate
~~~~~~~~
- Use this endpoint to activate user account. This enpoint is not a URL
+ Use this endpoint to activate user account. This endpoint is not a URL
which will be directly exposed to your users - you should provide site
- in your frontend application (cofigured by ``ACTIVATION_URL``) which
+ in your frontend application (configured by ``ACTIVATION_URL``) which
will send ``POST`` request to activate endpoint.
``POST``
@@ -294,10 +341,6 @@ Description: djoser
- status: ``HTTP_200_OK`` (success)
- - data:
-
- ``auth_token`` (if ``LOGIN_AFTER_ACTIVATION`` is ``True``)
-
Set username
~~~~~~~~~~~~
@@ -371,10 +414,10 @@ Description: djoser
Reset password confirmation
~~~~~~~~~~~~~~~~~~~~~~~~~~~
- Use this endpoint to finish reset password process. This enpoint is not
+ Use this endpoint to finish reset password process. This endpoint is not
a URL which will be directly exposed to your users - you should provide
- site in your frontend application (cofigured by
- ``PASSWORD_RESET_CONFIRM_URL_URL``) which will send ``POST`` request to
+ site in your frontend application (configured by
+ ``PASSWORD_RESET_CONFIRM_URL``) which will send ``POST`` request to
reset password confirmation endpoint.
``POST``
@@ -402,14 +445,6 @@ Description: djoser
Settings
--------
- LOGIN\_AFTER\_REGISTRATION
- ~~~~~~~~~~~~~~~~~~~~~~~~~~
-
- If ``True``, register endpoint will return ``auth_token`` within
- response.
-
- **Default**: ``False``
-
DOMAIN
~~~~~~
@@ -452,14 +487,6 @@ Description: djoser
**Required**: ``True``
- LOGIN\_AFTER\_ACTIVATION
- ~~~~~~~~~~~~~~~~~~~~~~~~
-
- If ``True``, activate endpoint will return ``auth_token`` within
- response.
-
- **Default**: ``False``
-
SET\_USERNAME\_RETYPE
~~~~~~~~~~~~~~~~~~~~~
diff --git a/README.md b/README.md
index a65494f..3be4d9e 100644
--- a/README.md
+++ b/README.md
@@ -12,14 +12,15 @@ Instead of reusing Django code (e.g. `PasswordResetForm`), we reimplemented
few things to fit better into [Single Page App](http://en.wikipedia.org/wiki/Single-page_application)
architecture.
-We use **token based authentication**. The concept is simple - first of all, users obtain a token by
-providing their credentials (e.g. username, password) during logging in. Once the token is obtained
-users can offer it in order to retrieve a specific resource. Django REST framework
-supports [token based authentication](http://www.django-rest-framework.org/api-guide/authentication#tokenauthentication)
-but you might be interested in other authentication mechanisms like OAuth or session-based authentication.
-
Developed by [SUNSCRAPERS](http://sunscrapers.com/) with passion & patience.
+## Features
+
+Here is a list of supported authentication backends:
+
+ * [HTTP Basic Auth](http://www.django-rest-framework.org/api-guide/authentication/#basicauthentication) (Default)
+ * [Token based authentication from Django Rest Framework](http://www.django-rest-framework.org/api-guide/authentication#tokenauthentication)
+
Available endpoints:
* `/me/`
@@ -47,8 +48,9 @@ Supported Django versions:
Supported Django Rest Framework versions:
- * Django Rest Framework 2.4
* 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).
## Installation
@@ -56,7 +58,7 @@ Use `pip`:
$ pip install djoser
-## Usage
+## Quick Start
Configure `INSTALLED_APPS`:
@@ -65,7 +67,6 @@ INSTALLED_APPS = (
'django.contrib.auth',
(...),
'rest_framework',
- 'rest_framework.authtoken',
'djoser',
(...),
)
@@ -80,8 +81,48 @@ urlpatterns = patterns('',
)
```
-Use `TokenAuthentication` as default Django Rest Framework authentication
-strategy:
+HTTP Basic Auth strategy is assumed by default as Django Rest Framework does it. However you may want to set it
+explicitly:
+
+```python
+REST_FRAMEWORK = {
+ 'DEFAULT_AUTHENTICATION_CLASSES': (
+ 'rest_framework.authentication.BasicAuthentication',
+ ),
+}
+```
+
+Run migrations (if you are using Django 1.7+ or South) - this step will create tables for `auth` app:
+
+ $ ./manage.py migrate
+
+## Customizing authentication backend
+
+### Token Based Authentication
+
+Add `'rest_framework.authtoken'` to `INSTALLED_APPS`:
+
+```python
+INSTALLED_APPS = (
+ 'django.contrib.auth',
+ (...),
+ 'rest_framework',
+ 'rest_framework.authtoken',
+ 'djoser',
+ (...),
+)
+```
+
+Configure `urls.py`. Pay attention to `djoser.url.authtoken` module path.
+
+```python
+urlpatterns = patterns('',
+ (...),
+ url(r'^auth/', include('djoser.urls.authtoken')),
+)
+```
+
+Set `TokenAuthentication` as default Django Rest Framework authentication strategy:
```python
REST_FRAMEWORK = {
@@ -95,6 +136,8 @@ Run migrations (if you are using Django 1.7+ or South) - this step will create t
$ ./manage.py migrate
+## Settings
+
Optionally add `DJOSER` settings:
```python
@@ -103,7 +146,6 @@ DJOSER = {
'SITE_NAME': 'Frontend',
'PASSWORD_RESET_CONFIRM_URL': '#/password/reset/confirm/{uid}/{token}',
'ACTIVATION_URL': '#/activate/{uid}/{token}',
- 'LOGIN_AFTER_ACTIVATION': True,
'SEND_ACTIVATION_EMAIL': True,
}
```
@@ -166,9 +208,6 @@ method and have [USERNAME_FIELD](https://docs.djangoproject.com/en/dev/topics/au
and [REQUIRED_FIELDS](https://docs.djangoproject.com/en/dev/topics/auth/customizing/#django.contrib.auth.models.CustomUser.REQUIRED_FIELDS)
fields.
-If `LOGIN_AFTER_REGISTRATION` is `True`, you will receive authentication token
-within response.
-
#### `POST`
URL: `/register/`
@@ -195,8 +234,6 @@ URL: `/register/`
`{{ User.REQUIRED_FIELDS }}`
- `auth_token` (if `LOGIN_AFTER_REGISTRATION` is `True`)
-
### Login
Use this endpoint to obtain user [authentication token](http://www.django-rest-framework.org/api-guide/authentication#tokenauthentication).
@@ -235,9 +272,9 @@ URL: `/logout/`
### Activate
-Use this endpoint to activate user account. This enpoint is not a URL which
+Use this endpoint to activate user account. This endpoint is not a URL which
will be directly exposed to your users - you should provide site in your
-frontend application (cofigured by `ACTIVATION_URL`) which will send `POST`
+frontend application (configured by `ACTIVATION_URL`) which will send `POST`
request to activate endpoint.
#### `POST`
@@ -256,10 +293,6 @@ URL: `/activate/`
* status: `HTTP_200_OK` (success)
- * data:
-
- `auth_token` (if `LOGIN_AFTER_ACTIVATION` is `True`)
-
### Set username
Use this endpoint to change user username (`USERNAME_FIELD`).
@@ -325,9 +358,9 @@ URL: `/password/reset/`
### Reset password confirmation
-Use this endpoint to finish reset password process. This enpoint is not a URL
+Use this endpoint to finish reset password process. This endpoint is not a URL
which will be directly exposed to your users - you should provide site in your
-frontend application (cofigured by `PASSWORD_RESET_CONFIRM_URL_URL`) which
+frontend application (configured by `PASSWORD_RESET_CONFIRM_URL`) which
will send `POST` request to reset password confirmation endpoint.
#### `POST`
@@ -352,12 +385,6 @@ URL: `/password/reset/confirm/`
## Settings
-### LOGIN_AFTER_REGISTRATION
-
-If `True`, register endpoint will return `auth_token` within response.
-
-**Default**: `False`
-
### DOMAIN
Domain of your frontend app. If not provided, domain of current site will be
@@ -394,12 +421,6 @@ placeholders, e.g. `#/activate/{uid}/{token}`. You should pass `uid` and
**Required**: `True`
-### LOGIN_AFTER_ACTIVATION
-
-If `True`, activate endpoint will return `auth_token` within response.
-
-**Default**: `False`
-
### SET_USERNAME_RETYPE
If `True`, you need to pass `re_new_{{ User.USERNAME_FIELD }}` to
diff --git a/djoser.egg-info/PKG-INFO b/djoser.egg-info/PKG-INFO
index fb5388c..ac29265 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.3.2
+Version: 0.4.0
Summary: REST version of Django authentication system.
Home-page: https://github.com/sunscrapers/djoser
Author: SUNSCRAPERS
@@ -23,18 +23,20 @@ Description: djoser
App <http://en.wikipedia.org/wiki/Single-page_application>`__
architecture.
- We use **token based authentication**. The concept is simple - first of
- all, users obtain a token by providing their credentials (e.g. username,
- password) during logging in. Once the token is obtained users can offer
- it in order to retrieve a specific resource. Django REST framework
- supports `token based
- authentication <http://www.django-rest-framework.org/api-guide/authentication#tokenauthentication>`__
- but you might be interested in other authentication mechanisms like
- OAuth or session-based authentication.
-
Developed by `SUNSCRAPERS <http://sunscrapers.com/>`__ with passion &
patience.
+ Features
+ --------
+
+ Here is a list of supported authentication backends:
+
+ - `HTTP Basic
+ Auth <http://www.django-rest-framework.org/api-guide/authentication/#basicauthentication>`__
+ (Default)
+ - `Token based authentication from Django Rest
+ Framework <http://www.django-rest-framework.org/api-guide/authentication#tokenauthentication>`__
+
Available endpoints:
- ``/me/``
@@ -62,9 +64,11 @@ Description: djoser
Supported Django Rest Framework versions:
- - Django Rest Framework 2.4
- 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>`__.
+
Installation
------------
@@ -74,8 +78,8 @@ Description: djoser
$ pip install djoser
- Usage
- -----
+ Quick Start
+ -----------
Configure ``INSTALLED_APPS``:
@@ -85,7 +89,6 @@ Description: djoser
'django.contrib.auth',
(...),
'rest_framework',
- 'rest_framework.authtoken',
'djoser',
(...),
)
@@ -99,7 +102,54 @@ Description: djoser
url(r'^auth/', include('djoser.urls')),
)
- Use ``TokenAuthentication`` as default Django Rest Framework
+ HTTP Basic Auth strategy is assumed by default as Django Rest Framework
+ does it. However you may want to set it explicitly:
+
+ .. code:: python
+
+ REST_FRAMEWORK = {
+ 'DEFAULT_AUTHENTICATION_CLASSES': (
+ 'rest_framework.authentication.BasicAuthentication',
+ ),
+ }
+
+ Run migrations (if you are using Django 1.7+ or South) - this step will
+ create tables for ``auth`` app:
+
+ ::
+
+ $ ./manage.py migrate
+
+ Customizing authentication backend
+ ----------------------------------
+
+ Token Based Authentication
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ Add ``'rest_framework.authtoken'`` to ``INSTALLED_APPS``:
+
+ .. code:: python
+
+ INSTALLED_APPS = (
+ 'django.contrib.auth',
+ (...),
+ 'rest_framework',
+ 'rest_framework.authtoken',
+ 'djoser',
+ (...),
+ )
+
+ Configure ``urls.py``. Pay attention to ``djoser.url.authtoken`` module
+ path.
+
+ .. code:: python
+
+ urlpatterns = patterns('',
+ (...),
+ url(r'^auth/', include('djoser.urls.authtoken')),
+ )
+
+ Set ``TokenAuthentication`` as default Django Rest Framework
authentication strategy:
.. code:: python
@@ -117,6 +167,9 @@ Description: djoser
$ ./manage.py migrate
+ Settings
+ --------
+
Optionally add ``DJOSER`` settings:
.. code:: python
@@ -126,7 +179,6 @@ Description: djoser
'SITE_NAME': 'Frontend',
'PASSWORD_RESET_CONFIRM_URL': '#/password/reset/confirm/{uid}/{token}',
'ACTIVATION_URL': '#/activate/{uid}/{token}',
- 'LOGIN_AFTER_ACTIVATION': True,
'SEND_ACTIVATION_EMAIL': True,
}
@@ -196,9 +248,6 @@ Description: djoser
`REQUIRED\_FIELDS <https://docs.djangoproject.com/en/dev/topics/auth/customizing/#django.contrib.auth.models.CustomUser.REQUIRED_FIELDS>`__
fields.
- If ``LOGIN_AFTER_REGISTRATION`` is ``True``, you will receive
- authentication token within response.
-
``POST``
^^^^^^^^
@@ -226,8 +275,6 @@ Description: djoser
``{{ User.REQUIRED_FIELDS }}``
- ``auth_token`` (if ``LOGIN_AFTER_REGISTRATION`` is ``True``)
-
Login
~~~~~
@@ -272,9 +319,9 @@ Description: djoser
Activate
~~~~~~~~
- Use this endpoint to activate user account. This enpoint is not a URL
+ Use this endpoint to activate user account. This endpoint is not a URL
which will be directly exposed to your users - you should provide site
- in your frontend application (cofigured by ``ACTIVATION_URL``) which
+ in your frontend application (configured by ``ACTIVATION_URL``) which
will send ``POST`` request to activate endpoint.
``POST``
@@ -294,10 +341,6 @@ Description: djoser
- status: ``HTTP_200_OK`` (success)
- - data:
-
- ``auth_token`` (if ``LOGIN_AFTER_ACTIVATION`` is ``True``)
-
Set username
~~~~~~~~~~~~
@@ -371,10 +414,10 @@ Description: djoser
Reset password confirmation
~~~~~~~~~~~~~~~~~~~~~~~~~~~
- Use this endpoint to finish reset password process. This enpoint is not
+ Use this endpoint to finish reset password process. This endpoint is not
a URL which will be directly exposed to your users - you should provide
- site in your frontend application (cofigured by
- ``PASSWORD_RESET_CONFIRM_URL_URL``) which will send ``POST`` request to
+ site in your frontend application (configured by
+ ``PASSWORD_RESET_CONFIRM_URL``) which will send ``POST`` request to
reset password confirmation endpoint.
``POST``
@@ -402,14 +445,6 @@ Description: djoser
Settings
--------
- LOGIN\_AFTER\_REGISTRATION
- ~~~~~~~~~~~~~~~~~~~~~~~~~~
-
- If ``True``, register endpoint will return ``auth_token`` within
- response.
-
- **Default**: ``False``
-
DOMAIN
~~~~~~
@@ -452,14 +487,6 @@ Description: djoser
**Required**: ``True``
- LOGIN\_AFTER\_ACTIVATION
- ~~~~~~~~~~~~~~~~~~~~~~~~
-
- If ``True``, activate endpoint will return ``auth_token`` within
- response.
-
- **Default**: ``False``
-
SET\_USERNAME\_RETYPE
~~~~~~~~~~~~~~~~~~~~~
diff --git a/djoser.egg-info/SOURCES.txt b/djoser.egg-info/SOURCES.txt
index 5f9ad69..4cb50bc 100644
--- a/djoser.egg-info/SOURCES.txt
+++ b/djoser.egg-info/SOURCES.txt
@@ -7,7 +7,6 @@ djoser/constants.py
djoser/serializers.py
djoser/settings.py
djoser/signals.py
-djoser/urls.py
djoser/utils.py
djoser/views.py
djoser.egg-info/PKG-INFO
@@ -18,4 +17,7 @@ djoser.egg-info/top_level.txt
djoser/templates/activation_email_body.txt
djoser/templates/activation_email_subject.txt
djoser/templates/password_reset_email_body.txt
-djoser/templates/password_reset_email_subject.txt
\ No newline at end of file
+djoser/templates/password_reset_email_subject.txt
+djoser/urls/__init__.py
+djoser/urls/authtoken.py
+djoser/urls/base.py
\ No newline at end of file
diff --git a/djoser.egg-info/requires.txt b/djoser.egg-info/requires.txt
index b0e00ef..e7fcc50 100644
--- a/djoser.egg-info/requires.txt
+++ b/djoser.egg-info/requires.txt
@@ -1,2 +1,2 @@
Django>=1.5
-djangorestframework>=2.4.0
+djangorestframework>=3.0.0
diff --git a/djoser.egg-info/top_level.txt b/djoser.egg-info/top_level.txt
index 1ced82d..e629335 100644
--- a/djoser.egg-info/top_level.txt
+++ b/djoser.egg-info/top_level.txt
@@ -1 +1,2 @@
djoser
+djoser/urls
diff --git a/djoser/serializers.py b/djoser/serializers.py
index ac20770..5bd1bae 100644
--- a/djoser/serializers.py
+++ b/djoser/serializers.py
@@ -1,30 +1,11 @@
-from distutils import version
from django.contrib.auth import authenticate, get_user_model
from rest_framework import serializers
-import rest_framework
from rest_framework.authtoken.models import Token
from . import constants, utils
User = get_user_model()
-def create_username_field():
- username_field = User._meta.get_field(User.USERNAME_FIELD)
- if hasattr(serializers.ModelSerializer, 'field_mapping'): # DRF 2.x
- mapping_dict = serializers.ModelSerializer.field_mapping
- elif hasattr(serializers.ModelSerializer, '_field_mapping'): # DRF 3.0
- mapping_dict = serializers.ModelSerializer._field_mapping.mapping
- elif hasattr(serializers.ModelSerializer, 'serializer_field_mapping'): # DRF 3.1
- mapping_dict = serializers.ModelSerializer.serializer_field_mapping
- else:
- raise AttributeError(
- 'serializers.ModelSerializer doesn\'t have any of these attributes: '
- 'field_mapping, _field_mapping, serializer_field_mapping '
- )
- field_class = mapping_dict[username_field.__class__]
- return field_class()
-
-
class UserSerializer(serializers.ModelSerializer):
class Meta:
@@ -38,7 +19,8 @@ class UserSerializer(serializers.ModelSerializer):
)
-class AbstractUserRegistrationSerializer(serializers.ModelSerializer):
+class UserRegistrationSerializer(serializers.ModelSerializer):
+ password = serializers.CharField(style={'input_type': 'password'}, write_only=True)
class Meta:
model = User
@@ -47,46 +29,13 @@ class AbstractUserRegistrationSerializer(serializers.ModelSerializer):
User._meta.pk.name,
'password',
)
- write_only_fields = (
- 'password',
- )
-
-if version.StrictVersion(rest_framework.VERSION) >= version.StrictVersion('3.0.0'):
-
- class UserRegistrationSerializer(AbstractUserRegistrationSerializer):
-
- def create(self, validated_data):
- return User.objects.create_user(**validated_data)
-
-else:
-
- class UserRegistrationSerializer(AbstractUserRegistrationSerializer):
-
- def restore_object(self, attrs, instance=None):
- try:
- return User.objects.get(**{User.USERNAME_FIELD: attrs[User.USERNAME_FIELD]})
- except User.DoesNotExist:
- return User.objects.create_user(**attrs)
-
- def save_object(self, obj, **kwargs):
- return obj
-
-
-class UserRegistrationWithAuthTokenSerializer(UserRegistrationSerializer):
- auth_token = serializers.SerializerMethodField(method_name='get_user_auth_token')
-
- class Meta(UserRegistrationSerializer.Meta):
- model = User
- fields = UserRegistrationSerializer.Meta.fields + (
- 'auth_token',
- )
- def get_user_auth_token(self, obj):
- return obj.auth_token.key
+ def create(self, validated_data):
+ return User.objects.create_user(**validated_data)
class LoginSerializer(serializers.Serializer):
- password = serializers.CharField(required=False)
+ password = serializers.CharField(required=False, style={'input_type': 'password'})
default_error_messages = {
'inactive_account': constants.INACTIVE_ACCOUNT_ERROR,
@@ -99,7 +48,7 @@ class LoginSerializer(serializers.Serializer):
self.fields[User.USERNAME_FIELD] = serializers.CharField(required=False)
def validate(self, attrs):
- self.user = authenticate(username=attrs[User.USERNAME_FIELD], password=attrs['password'])
+ self.user = authenticate(username=attrs.get(User.USERNAME_FIELD), password=attrs.get('password'))
if self.user:
if not self.user.is_active:
raise serializers.ValidationError(self.error_messages['inactive_account'])
@@ -120,14 +69,13 @@ class UidAndTokenSerializer(serializers.Serializer):
'invalid_token': constants.INVALID_TOKEN_ERROR
}
- def validate_uid(self, attrs_or_value, source=None):
- value = attrs_or_value[source] if source else attrs_or_value
+ def validate_uid(self, value):
try:
uid = utils.decode_uid(value)
self.user = User.objects.get(pk=uid)
- except (User.DoesNotExist, ValueError, TypeError, ValueError, OverflowError) as error:
+ except (User.DoesNotExist, ValueError, TypeError, OverflowError) as error:
raise serializers.ValidationError(error)
- return attrs_or_value
+ return value
def validate(self, attrs):
attrs = super(UidAndTokenSerializer, self).validate(attrs)
@@ -137,11 +85,11 @@ class UidAndTokenSerializer(serializers.Serializer):
class PasswordSerializer(serializers.Serializer):
- new_password = serializers.CharField()
+ new_password = serializers.CharField(style={'input_type': 'password'})
class PasswordRetypeSerializer(PasswordSerializer):
- re_new_password = serializers.CharField()
+ re_new_password = serializers.CharField(style={'input_type': 'password'})
default_error_messages = {
'password_mismatch': constants.PASSWORD_MISMATCH_ERROR,
@@ -155,17 +103,16 @@ class PasswordRetypeSerializer(PasswordSerializer):
class CurrentPasswordSerializer(serializers.Serializer):
- current_password = serializers.CharField()
+ current_password = serializers.CharField(style={'input_type': 'password'})
default_error_messages = {
'invalid_password': constants.INVALID_PASSWORD_ERROR,
}
- def validate_current_password(self, attrs_or_value, source=None):
- value = attrs_or_value[source] if source else attrs_or_value
+ def validate_current_password(self, value):
if not self.context['request'].user.check_password(value):
raise serializers.ValidationError(self.error_messages['invalid_password'])
- return attrs_or_value
+ return value
class SetPasswordSerializer(PasswordSerializer, CurrentPasswordSerializer):
@@ -210,10 +157,7 @@ class SetUsernameRetypeSerializer(SetUsernameSerializer):
def validate(self, attrs):
attrs = super(SetUsernameRetypeSerializer, self).validate(attrs)
- if User.USERNAME_FIELD in attrs:
- new_username = attrs[User.USERNAME_FIELD]
- else: # DRF 2.4
- new_username = attrs['new_' + User.USERNAME_FIELD]
+ new_username = attrs[User.USERNAME_FIELD]
if new_username != attrs['re_new_' + User.USERNAME_FIELD]:
raise serializers.ValidationError(self.error_messages['username_mismatch'].format(User.USERNAME_FIELD))
return attrs
diff --git a/djoser/settings.py b/djoser/settings.py
index 3e89e5d..4ea75b9 100644
--- a/djoser/settings.py
+++ b/djoser/settings.py
@@ -4,12 +4,11 @@ from django.core.exceptions import ImproperlyConfigured
def get(key):
from django.conf import settings
defaults = {
- 'LOGIN_AFTER_REGISTRATION': False,
- 'LOGIN_AFTER_ACTIVATION': False,
'SEND_ACTIVATION_EMAIL': False,
'SET_PASSWORD_RETYPE': False,
'SET_USERNAME_RETYPE': False,
'PASSWORD_RESET_CONFIRM_RETYPE': False,
+ 'ROOT_VIEW_URLS_MAPPING': {},
}
defaults.update(getattr(settings, 'DJOSER', {}))
try:
diff --git a/djoser/urls/__init__.py b/djoser/urls/__init__.py
new file mode 100644
index 0000000..92d04e2
--- /dev/null
+++ b/djoser/urls/__init__.py
@@ -0,0 +1 @@
+from .base import urlpatterns
diff --git a/djoser/urls/authtoken.py b/djoser/urls/authtoken.py
new file mode 100644
index 0000000..47374ca
--- /dev/null
+++ b/djoser/urls/authtoken.py
@@ -0,0 +1,9 @@
+from django.conf.urls import patterns, url
+from djoser import views
+from . import base
+
+urlpatterns = base.base_urlpatterns + patterns('',
+ 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.py b/djoser/urls/base.py
similarity index 75%
rename from djoser/urls.py
rename to djoser/urls/base.py
index 4a76563..1f63d4a 100644
--- a/djoser/urls.py
+++ b/djoser/urls/base.py
@@ -1,18 +1,17 @@
from django.conf.urls import patterns, url
-from . import views
+from djoser import views
from django.contrib.auth import get_user_model
User = get_user_model()
-urlpatterns = patterns('',
- url(r'^$', views.RootView.as_view(), name='root'),
+base_urlpatterns = patterns('',
url(r'^me/$', views.UserView.as_view(), name='user'),
url(r'^register/$', views.RegistrationView.as_view(), name='register'),
- url(r'^login/$', views.LoginView.as_view(), name='login'),
- url(r'^logout/$', views.LogoutView.as_view(), name='logout'),
url(r'^activate/$', views.ActivationView.as_view(), name='activate'),
url(r'^{0}/$'.format(User.USERNAME_FIELD), views.SetUsernameView.as_view(), name='set_username'),
url(r'^password/$', views.SetPasswordView.as_view(), name='set_password'),
url(r'^password/reset/$', views.PasswordResetView.as_view(), name='password_reset'),
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'))
diff --git a/djoser/utils.py b/djoser/utils.py
index 95ee7bc..ba53cd0 100644
--- a/djoser/utils.py
+++ b/djoser/utils.py
@@ -1,9 +1,13 @@
from django.conf import settings as django_settings
-from django.contrib.sites.models import get_current_site
from django.core.mail import EmailMultiAlternatives, EmailMessage
from django.template import loader
from rest_framework import response, status
+try:
+ from django.contrib.sites.shortcuts import get_current_site
+except ImportError:
+ from django.contrib.sites.models import get_current_site
+
def encode_uid(pk):
try:
@@ -59,6 +63,7 @@ class ActionViewMixin(object):
class SendEmailViewMixin(object):
+ token_generator = None
subject_template_name = None
plain_body_template_name = None
html_body_template_name = None
diff --git a/djoser/views.py b/djoser/views.py
index 6fd0fac..3037dff 100644
... 164 lines suppressed ...
--
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