[Python-modules-commits] [djoser] 01/09: New upstream version 1.1.5
Michael Fladischer
fladi at moszumanska.debian.org
Mon Jan 8 15:08:17 UTC 2018
This is an automated email from the git hooks/post-receive script.
fladi pushed a commit to branch debian/master
in repository djoser.
commit b7f1d97a6e7c8e947fb1f1d61907ec57eb099804
Author: Michael Fladischer <FladischerMichael at fladi.at>
Date: Mon Jan 8 15:38:45 2018 +0100
New upstream version 1.1.5
---
LICENSE | 21 +++
MANIFEST.in | 3 +-
PKG-INFO | 53 +++++--
README.rst | 41 +++--
djoser.egg-info/PKG-INFO | 53 +++++--
djoser.egg-info/SOURCES.txt | 26 ++--
djoser.egg-info/requires.txt | 1 +
djoser.egg-info/top_level.txt | 3 +
djoser/compat.py | 7 +-
djoser/conf.py | 21 ++-
djoser/email.py | 36 +++++
djoser/serializers.py | 108 +++++++------
djoser/social/__init__.py | 0
djoser/social/backends/__init__.py | 0
djoser/social/backends/facebook.py | 5 +
djoser/social/serializers.py | 62 ++++++++
djoser/social/token/__init__.py | 0
djoser/social/token/jwt.py | 9 ++
djoser/social/urls.py | 12 ++
djoser/social/views.py | 29 ++++
djoser/templates/activation_email_body.html | 19 ---
djoser/templates/activation_email_body.txt | 13 --
djoser/templates/activation_email_subject.txt | 3 -
djoser/templates/confirmation_email_body.html | 12 --
djoser/templates/confirmation_email_body.txt | 8 -
djoser/templates/confirmation_email_subject.txt | 3 -
djoser/templates/email/activation.html | 29 ++++
djoser/templates/email/confirmation.html | 21 +++
djoser/templates/email/password_reset.html | 29 ++++
djoser/templates/password_reset_email_body.html | 17 ---
djoser/templates/password_reset_email_body.txt | 14 --
djoser/templates/password_reset_email_subject.txt | 3 -
djoser/urls/authtoken.py | 20 ++-
djoser/urls/base.py | 28 +++-
djoser/urls/jwt.py | 10 ++
djoser/utils.py | 123 ---------------
djoser/views.py | 175 ++++++++++++----------
requirements.txt | 3 +
setup.py | 13 +-
39 files changed, 605 insertions(+), 428 deletions(-)
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..14aebb9
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2013 SUNSCRAPERS
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/MANIFEST.in b/MANIFEST.in
index eee9760..b94cc70 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -1,3 +1,4 @@
include README.md
-include djoser/templates/*
+include LICENSE
+recursive-include djoser/templates *.html
include requirements.txt
diff --git a/PKG-INFO b/PKG-INFO
index e4ad509..65c8758 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,11 +1,12 @@
Metadata-Version: 1.1
Name: djoser
-Version: 0.7.0
+Version: 1.1.5
Summary: REST version of Django authentication system.
Home-page: https://github.com/sunscrapers/djoser
Author: SUNSCRAPERS
Author-email: info at sunscrapers.com
License: MIT
+Description-Content-Type: UNKNOWN
Description: ======
djoser
======
@@ -25,7 +26,8 @@ Description: ======
REST implementation of `Django <https://www.djangoproject.com/>`_ authentication
system. **djoser** library provides a set of `Django Rest Framework <http://www.django-rest-framework.org/>`_
views to handle basic actions such as registration, login, logout, password
- reset and account activation. It works with `custom user model <https://docs.djangoproject.com/en/dev/topics/auth/customizing/>`_.
+ reset and account activation. It works with
+ `custom user model <https://docs.djangoproject.com/en/dev/topics/auth/customizing/>`_.
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)>`_
@@ -33,13 +35,37 @@ Description: ======
Developed by `SUNSCRAPERS <http://sunscrapers.com/>`_ with passion & patience.
+ .. image:: https://asciinema.org/a/FBTYjfDPUr99jxZqbLOZhh9Pd.png
+ :target: https://asciinema.org/a/FBTYjfDPUr99jxZqbLOZhh9Pd?autoplay=1&speed=2
+
+ Requirements
+ ============
+
+ To be able to run **djoser** you have to meet following requirements:
+
+ - Python (2.7, 3.4, 3.5, 3.6)
+ - Django (1.10, 1.11)
+ - Django REST Framework (3.7)
+
+ Installation
+ ============
+
+ Simply install using ``pip``:
+
+ .. code-block:: bash
+
+ $ pip install djoser
+
+ And continue with the steps described at
+ `configuration <http://djoser.readthedocs.io/en/latest/getting_started.html#configuration>`_
+ guide.
Documentation
=============
Documentation is available to study at
- `http://djoser.readthedocs.io <http://djoser.readthedocs.io>`_ and in
- ``docs`` directory.
+ `http://djoser.readthedocs.io <http://djoser.readthedocs.io>`_
+ and in ``docs`` directory.
Contributing and development
============================
@@ -93,19 +119,22 @@ Description: ======
List of projects related to Django, REST and authentication:
- - `django-rest-auth <https://github.com/Tivix/django-rest-auth>`_
- - `django-rest-framework-digestauth <https://github.com/juanriaza/django-rest-framework-digestauth>`_
- - `django-oauth-toolkit <https://github.com/evonove/django-oauth-toolkit>`_
- - `doac <https://github.com/Rediker-Software/doac>`_
- `django-rest-framework-jwt <https://github.com/GetBlimp/django-rest-framework-jwt>`_
- - `django-rest-framework-httpsignature <https://github.com/etoccalino/django-rest-framework-httpsignature>`_
- - `hawkrest <https://github.com/kumar303/hawkrest>`_
+ - `django-oauth-toolkit <https://github.com/evonove/django-oauth-toolkit>`_
+ - `django-rest-auth <https://github.com/Tivix/django-rest-auth>`_
+ - `django-rest-framework-digestauth <https://github.com/juanriaza/django-rest-framework-digestauth>`_ (not maintained)
+ - `doac <https://github.com/Rediker-Software/doac>`_ (not maintained)
Platform: UNKNOWN
-Classifier: Development Status :: 3 - Alpha
+Classifier: Development Status :: 5 - Production/Stable
Classifier: Framework :: Django
+Classifier: Framework :: Django :: 1.10
+Classifier: Framework :: Django :: 1.11
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
-Classifier: Programming Language :: Python :: 3
+Classifier: Programming Language :: Python :: 2.7
+Classifier: Programming Language :: Python :: 3.4
+Classifier: Programming Language :: Python :: 3.5
+Classifier: Programming Language :: Python :: 3.6
diff --git a/README.rst b/README.rst
index 7af4ce9..4d37345 100644
--- a/README.rst
+++ b/README.rst
@@ -17,7 +17,8 @@ djoser
REST implementation of `Django <https://www.djangoproject.com/>`_ authentication
system. **djoser** library provides a set of `Django Rest Framework <http://www.django-rest-framework.org/>`_
views to handle basic actions such as registration, login, logout, password
-reset and account activation. It works with `custom user model <https://docs.djangoproject.com/en/dev/topics/auth/customizing/>`_.
+reset and account activation. It works with
+`custom user model <https://docs.djangoproject.com/en/dev/topics/auth/customizing/>`_.
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)>`_
@@ -25,13 +26,37 @@ architecture.
Developed by `SUNSCRAPERS <http://sunscrapers.com/>`_ with passion & patience.
+.. image:: https://asciinema.org/a/FBTYjfDPUr99jxZqbLOZhh9Pd.png
+ :target: https://asciinema.org/a/FBTYjfDPUr99jxZqbLOZhh9Pd?autoplay=1&speed=2
+
+Requirements
+============
+
+To be able to run **djoser** you have to meet following requirements:
+
+- Python (2.7, 3.4, 3.5, 3.6)
+- Django (1.10, 1.11)
+- Django REST Framework (3.7)
+
+Installation
+============
+
+Simply install using ``pip``:
+
+.. code-block:: bash
+
+ $ pip install djoser
+
+And continue with the steps described at
+`configuration <http://djoser.readthedocs.io/en/latest/getting_started.html#configuration>`_
+guide.
Documentation
=============
Documentation is available to study at
-`http://djoser.readthedocs.io <http://djoser.readthedocs.io>`_ and in
-``docs`` directory.
+`http://djoser.readthedocs.io <http://djoser.readthedocs.io>`_
+and in ``docs`` directory.
Contributing and development
============================
@@ -85,10 +110,8 @@ Similar projects
List of projects related to Django, REST and authentication:
-- `django-rest-auth <https://github.com/Tivix/django-rest-auth>`_
-- `django-rest-framework-digestauth <https://github.com/juanriaza/django-rest-framework-digestauth>`_
-- `django-oauth-toolkit <https://github.com/evonove/django-oauth-toolkit>`_
-- `doac <https://github.com/Rediker-Software/doac>`_
- `django-rest-framework-jwt <https://github.com/GetBlimp/django-rest-framework-jwt>`_
-- `django-rest-framework-httpsignature <https://github.com/etoccalino/django-rest-framework-httpsignature>`_
-- `hawkrest <https://github.com/kumar303/hawkrest>`_
+- `django-oauth-toolkit <https://github.com/evonove/django-oauth-toolkit>`_
+- `django-rest-auth <https://github.com/Tivix/django-rest-auth>`_
+- `django-rest-framework-digestauth <https://github.com/juanriaza/django-rest-framework-digestauth>`_ (not maintained)
+- `doac <https://github.com/Rediker-Software/doac>`_ (not maintained)
diff --git a/djoser.egg-info/PKG-INFO b/djoser.egg-info/PKG-INFO
index e4ad509..65c8758 100644
--- a/djoser.egg-info/PKG-INFO
+++ b/djoser.egg-info/PKG-INFO
@@ -1,11 +1,12 @@
Metadata-Version: 1.1
Name: djoser
-Version: 0.7.0
+Version: 1.1.5
Summary: REST version of Django authentication system.
Home-page: https://github.com/sunscrapers/djoser
Author: SUNSCRAPERS
Author-email: info at sunscrapers.com
License: MIT
+Description-Content-Type: UNKNOWN
Description: ======
djoser
======
@@ -25,7 +26,8 @@ Description: ======
REST implementation of `Django <https://www.djangoproject.com/>`_ authentication
system. **djoser** library provides a set of `Django Rest Framework <http://www.django-rest-framework.org/>`_
views to handle basic actions such as registration, login, logout, password
- reset and account activation. It works with `custom user model <https://docs.djangoproject.com/en/dev/topics/auth/customizing/>`_.
+ reset and account activation. It works with
+ `custom user model <https://docs.djangoproject.com/en/dev/topics/auth/customizing/>`_.
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)>`_
@@ -33,13 +35,37 @@ Description: ======
Developed by `SUNSCRAPERS <http://sunscrapers.com/>`_ with passion & patience.
+ .. image:: https://asciinema.org/a/FBTYjfDPUr99jxZqbLOZhh9Pd.png
+ :target: https://asciinema.org/a/FBTYjfDPUr99jxZqbLOZhh9Pd?autoplay=1&speed=2
+
+ Requirements
+ ============
+
+ To be able to run **djoser** you have to meet following requirements:
+
+ - Python (2.7, 3.4, 3.5, 3.6)
+ - Django (1.10, 1.11)
+ - Django REST Framework (3.7)
+
+ Installation
+ ============
+
+ Simply install using ``pip``:
+
+ .. code-block:: bash
+
+ $ pip install djoser
+
+ And continue with the steps described at
+ `configuration <http://djoser.readthedocs.io/en/latest/getting_started.html#configuration>`_
+ guide.
Documentation
=============
Documentation is available to study at
- `http://djoser.readthedocs.io <http://djoser.readthedocs.io>`_ and in
- ``docs`` directory.
+ `http://djoser.readthedocs.io <http://djoser.readthedocs.io>`_
+ and in ``docs`` directory.
Contributing and development
============================
@@ -93,19 +119,22 @@ Description: ======
List of projects related to Django, REST and authentication:
- - `django-rest-auth <https://github.com/Tivix/django-rest-auth>`_
- - `django-rest-framework-digestauth <https://github.com/juanriaza/django-rest-framework-digestauth>`_
- - `django-oauth-toolkit <https://github.com/evonove/django-oauth-toolkit>`_
- - `doac <https://github.com/Rediker-Software/doac>`_
- `django-rest-framework-jwt <https://github.com/GetBlimp/django-rest-framework-jwt>`_
- - `django-rest-framework-httpsignature <https://github.com/etoccalino/django-rest-framework-httpsignature>`_
- - `hawkrest <https://github.com/kumar303/hawkrest>`_
+ - `django-oauth-toolkit <https://github.com/evonove/django-oauth-toolkit>`_
+ - `django-rest-auth <https://github.com/Tivix/django-rest-auth>`_
+ - `django-rest-framework-digestauth <https://github.com/juanriaza/django-rest-framework-digestauth>`_ (not maintained)
+ - `doac <https://github.com/Rediker-Software/doac>`_ (not maintained)
Platform: UNKNOWN
-Classifier: Development Status :: 3 - Alpha
+Classifier: Development Status :: 5 - Production/Stable
Classifier: Framework :: Django
+Classifier: Framework :: Django :: 1.10
+Classifier: Framework :: Django :: 1.11
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
-Classifier: Programming Language :: Python :: 3
+Classifier: Programming Language :: Python :: 2.7
+Classifier: Programming Language :: Python :: 3.4
+Classifier: Programming Language :: Python :: 3.5
+Classifier: Programming Language :: Python :: 3.6
diff --git a/djoser.egg-info/SOURCES.txt b/djoser.egg-info/SOURCES.txt
index 80e4484..e80513c 100644
--- a/djoser.egg-info/SOURCES.txt
+++ b/djoser.egg-info/SOURCES.txt
@@ -1,3 +1,4 @@
+LICENSE
MANIFEST.in
README.rst
requirements.txt
@@ -7,6 +8,7 @@ djoser/__init__.py
djoser/compat.py
djoser/conf.py
djoser/constants.py
+djoser/email.py
djoser/serializers.py
djoser/signals.py
djoser/utils.py
@@ -14,16 +16,20 @@ djoser/views.py
djoser.egg-info/PKG-INFO
djoser.egg-info/SOURCES.txt
djoser.egg-info/dependency_links.txt
+djoser.egg-info/requires.txt
djoser.egg-info/top_level.txt
-djoser/templates/activation_email_body.html
-djoser/templates/activation_email_body.txt
-djoser/templates/activation_email_subject.txt
-djoser/templates/confirmation_email_body.html
-djoser/templates/confirmation_email_body.txt
-djoser/templates/confirmation_email_subject.txt
-djoser/templates/password_reset_email_body.html
-djoser/templates/password_reset_email_body.txt
-djoser/templates/password_reset_email_subject.txt
+djoser/social/__init__.py
+djoser/social/serializers.py
+djoser/social/urls.py
+djoser/social/views.py
+djoser/social/backends/__init__.py
+djoser/social/backends/facebook.py
+djoser/social/token/__init__.py
+djoser/social/token/jwt.py
+djoser/templates/email/activation.html
+djoser/templates/email/confirmation.html
+djoser/templates/email/password_reset.html
djoser/urls/__init__.py
djoser/urls/authtoken.py
-djoser/urls/base.py
\ No newline at end of file
+djoser/urls/base.py
+djoser/urls/jwt.py
\ No newline at end of file
diff --git a/djoser.egg-info/requires.txt b/djoser.egg-info/requires.txt
new file mode 100644
index 0000000..fe32fa4
--- /dev/null
+++ b/djoser.egg-info/requires.txt
@@ -0,0 +1 @@
+django-templated-mail
diff --git a/djoser.egg-info/top_level.txt b/djoser.egg-info/top_level.txt
index e629335..56551ed 100644
--- a/djoser.egg-info/top_level.txt
+++ b/djoser.egg-info/top_level.txt
@@ -1,2 +1,5 @@
djoser
+djoser/social
+djoser/social/backends
+djoser/social/token
djoser/urls
diff --git a/djoser/compat.py b/djoser/compat.py
index 1f00eef..f75d2de 100644
--- a/djoser/compat.py
+++ b/djoser/compat.py
@@ -1,11 +1,6 @@
from djoser.conf import settings
-try:
- from django.contrib.auth.password_validation import validate_password
-except ImportError:
- from password_validation import validate_password
-
-__all__ = ['settings', 'validate_password']
+__all__ = ['settings']
def get_user_email(user):
diff --git a/djoser/conf.py b/djoser/conf.py
index 61f7a9b..ef29f41 100644
--- a/djoser/conf.py
+++ b/djoser/conf.py
@@ -24,21 +24,17 @@ class ObjDict(dict):
default_settings = {
- 'USE_HTML_EMAIL_TEMPLATES': False,
'SEND_ACTIVATION_EMAIL': False,
'SEND_CONFIRMATION_EMAIL': False,
'SET_PASSWORD_RETYPE': False,
'SET_USERNAME_RETYPE': False,
'PASSWORD_RESET_CONFIRM_RETYPE': False,
'PASSWORD_RESET_SHOW_EMAIL_NOT_FOUND': False,
- 'ROOT_VIEW_URLS_MAPPING': {},
'PASSWORD_VALIDATORS': [],
'TOKEN_MODEL': 'rest_framework.authtoken.models.Token',
'SERIALIZERS': ObjDict({
'activation':
'djoser.serializers.ActivationSerializer',
- 'login':
- 'djoser.serializers.LoginSerializer',
'password_reset':
'djoser.serializers.PasswordResetSerializer',
'password_reset_confirm':
@@ -53,18 +49,29 @@ default_settings = {
'djoser.serializers.SetUsernameSerializer',
'set_username_retype':
'djoser.serializers.SetUsernameRetypeSerializer',
- 'user_registration':
- 'djoser.serializers.UserRegistrationSerializer',
+ 'user_create':
+ 'djoser.serializers.UserCreateSerializer',
+ 'user_delete':
+ 'djoser.serializers.UserDeleteSerializer',
'user':
'djoser.serializers.UserSerializer',
'token':
'djoser.serializers.TokenSerializer',
+ 'token_create':
+ 'djoser.serializers.TokenCreateSerializer',
+ }),
+ 'EMAIL': ObjDict({
+ 'activation': 'djoser.email.ActivationEmail',
+ 'confirmation': 'djoser.email.ConfirmationEmail',
+ 'password_reset': 'djoser.email.PasswordResetEmail',
}),
'LOGOUT_ON_PASSWORD_CHANGE': False,
'USER_EMAIL_FIELD_NAME': 'email',
+ 'SOCIAL_AUTH_TOKEN_STRATEGY': 'djoser.social.token.jwt.TokenStrategy',
+ 'SOCIAL_AUTH_ALLOWED_REDIRECT_URIS': [],
}
-SETTINGS_TO_IMPORT = ['TOKEN_MODEL']
+SETTINGS_TO_IMPORT = ['TOKEN_MODEL', 'SOCIAL_AUTH_TOKEN_STRATEGY']
class Settings(object):
diff --git a/djoser/email.py b/djoser/email.py
new file mode 100644
index 0000000..75a5057
--- /dev/null
+++ b/djoser/email.py
@@ -0,0 +1,36 @@
+from django.contrib.auth.tokens import default_token_generator
+
+from templated_mail.mail import BaseEmailMessage
+
+from djoser import utils
+from djoser.conf import settings
+
+
+class ActivationEmail(BaseEmailMessage):
+ template_name = 'email/activation.html'
+
+ def get_context_data(self):
+ context = super(ActivationEmail, self).get_context_data()
+
+ user = context.get('user')
+ context['uid'] = utils.encode_uid(user.pk)
+ context['token'] = default_token_generator.make_token(user)
+ context['url'] = settings.ACTIVATION_URL.format(**context)
+ return context
+
+
+class ConfirmationEmail(BaseEmailMessage):
+ template_name = 'email/confirmation.html'
+
+
+class PasswordResetEmail(BaseEmailMessage):
+ template_name = 'email/password_reset.html'
+
+ def get_context_data(self):
+ context = super(PasswordResetEmail, self).get_context_data()
+
+ user = context.get('user')
+ context['uid'] = utils.encode_uid(user.pk)
+ context['token'] = default_token_generator.make_token(user)
+ context['url'] = settings.PASSWORD_RESET_CONFIRM_URL.format(**context)
+ return context
diff --git a/djoser/serializers.py b/djoser/serializers.py
index 0d71ee6..44e1a59 100644
--- a/djoser/serializers.py
+++ b/djoser/serializers.py
@@ -1,12 +1,12 @@
from django.contrib.auth import authenticate, get_user_model
+from django.contrib.auth.password_validation import validate_password
+from django.core import exceptions as django_exceptions
from django.db import IntegrityError, transaction
from rest_framework import exceptions, serializers
from djoser import constants, utils
-from djoser.compat import (
- get_user_email, get_user_email_field_name, validate_password
-)
+from djoser.compat import get_user_email, get_user_email_field_name
from djoser.conf import settings
User = get_user_model()
@@ -31,7 +31,7 @@ class UserSerializer(serializers.ModelSerializer):
return super(UserSerializer, self).update(instance, validated_data)
-class UserRegistrationSerializer(serializers.ModelSerializer):
+class UserCreateSerializer(serializers.ModelSerializer):
password = serializers.CharField(
style={'input_type': 'password'},
write_only=True
@@ -47,17 +47,22 @@ class UserRegistrationSerializer(serializers.ModelSerializer):
User.USERNAME_FIELD, User._meta.pk.name, 'password',
)
- def validate_password(self, value):
- validate_password(value)
- return value
+ def validate(self, attrs):
+ user = User(**attrs)
+ password = attrs.get('password')
+
+ try:
+ validate_password(password, user)
+ except django_exceptions.ValidationError as e:
+ raise serializers.ValidationError({'password': list(e.messages)})
+
+ return attrs
def create(self, validated_data):
try:
user = self.perform_create(validated_data)
except IntegrityError:
- raise serializers.ValidationError(
- self.error_messages['cannot_create_user']
- )
+ self.fail('cannot_create_user')
return user
@@ -70,18 +75,18 @@ class UserRegistrationSerializer(serializers.ModelSerializer):
return user
-class LoginSerializer(serializers.Serializer):
+class TokenCreateSerializer(serializers.Serializer):
password = serializers.CharField(
required=False, style={'input_type': 'password'}
)
default_error_messages = {
- 'inactive_account': constants.INACTIVE_ACCOUNT_ERROR,
'invalid_credentials': constants.INVALID_CREDENTIALS_ERROR,
+ 'inactive_account': constants.INACTIVE_ACCOUNT_ERROR,
}
def __init__(self, *args, **kwargs):
- super(LoginSerializer, self).__init__(*args, **kwargs)
+ super(TokenCreateSerializer, self).__init__(*args, **kwargs)
self.user = None
self.fields[User.USERNAME_FIELD] = serializers.CharField(
required=False
@@ -99,31 +104,24 @@ class LoginSerializer(serializers.Serializer):
def _validate_user_exists(self, user):
if not user:
- raise serializers.ValidationError(
- self.error_messages['invalid_credentials']
- )
+ self.fail('invalid_credentials')
def _validate_user_is_active(self, user):
if not user.is_active:
- raise serializers.ValidationError(
- self.error_messages['inactive_account']
- )
+ self.fail('inactive_account')
class PasswordResetSerializer(serializers.Serializer):
email = serializers.EmailField()
- default_error_messages = {
- 'email_not_found': constants.EMAIL_NOT_FOUND
- }
+ default_error_messages = {'email_not_found': constants.EMAIL_NOT_FOUND}
def validate_email(self, value):
users = self.context['view'].get_users(value)
if settings.PASSWORD_RESET_SHOW_EMAIL_NOT_FOUND and not users:
- raise serializers.ValidationError(
- self.error_messages['email_not_found']
- )
- return value
+ self.fail('email_not_found')
+ else:
+ return value
class UidAndTokenSerializer(serializers.Serializer):
@@ -140,9 +138,8 @@ class UidAndTokenSerializer(serializers.Serializer):
uid = utils.decode_uid(value)
self.user = User.objects.get(pk=uid)
except (User.DoesNotExist, ValueError, TypeError, OverflowError):
- raise serializers.ValidationError(
- self.error_messages['invalid_uid']
- )
+ self.fail('invalid_uid')
+
return value
def validate(self, attrs):
@@ -152,13 +149,12 @@ class UidAndTokenSerializer(serializers.Serializer):
)
if is_token_valid:
return attrs
- raise serializers.ValidationError(self.error_messages['invalid_token'])
+ else:
+ self.fail('invalid_token')
class ActivationSerializer(UidAndTokenSerializer):
- default_error_messages = {
- 'stale_token': constants.STALE_TOKEN_ERROR,
- }
+ default_error_messages = {'stale_token': constants.STALE_TOKEN_ERROR}
def validate(self, attrs):
attrs = super(ActivationSerializer, self).validate(attrs)
@@ -170,9 +166,17 @@ class ActivationSerializer(UidAndTokenSerializer):
class PasswordSerializer(serializers.Serializer):
new_password = serializers.CharField(style={'input_type': 'password'})
- def validate_new_password(self, value):
- validate_password(value)
- return value
+ def validate(self, attrs):
+ user = self.context['request'].user or self.user
+ assert user is not None
+
+ try:
+ validate_password(attrs['new_password'], user)
+ except django_exceptions.ValidationError as e:
+ raise serializers.ValidationError({
+ 'new_password': list(e.messages)
+ })
+ return super(PasswordSerializer, self).validate(attrs)
class PasswordRetypeSerializer(PasswordSerializer):
@@ -186,9 +190,8 @@ class PasswordRetypeSerializer(PasswordSerializer):
attrs = super(PasswordRetypeSerializer, self).validate(attrs)
if attrs['new_password'] == attrs['re_new_password']:
return attrs
- raise serializers.ValidationError(
- self.error_messages['password_mismatch']
- )
+ else:
+ self.fail('password_mismatch')
class CurrentPasswordSerializer(serializers.Serializer):
@@ -202,9 +205,8 @@ class CurrentPasswordSerializer(serializers.Serializer):
is_password_valid = self.context['request'].user.check_password(value)
if is_password_valid:
return value
- raise serializers.ValidationError(
- self.error_messages['invalid_password']
- )
+ else:
+ self.fail('invalid_password')
class SetPasswordSerializer(PasswordSerializer, CurrentPasswordSerializer):
@@ -226,15 +228,16 @@ class PasswordResetConfirmRetypeSerializer(UidAndTokenSerializer,
pass
+class UserDeleteSerializer(CurrentPasswordSerializer):
+ pass
+
+
class SetUsernameSerializer(serializers.ModelSerializer,
CurrentPasswordSerializer):
class Meta(object):
model = User
- fields = (
- User.USERNAME_FIELD,
- 'current_password',
- )
+ fields = (User.USERNAME_FIELD, 'current_password')
def __init__(self, *args, **kwargs):
"""
@@ -262,12 +265,9 @@ class SetUsernameRetypeSerializer(SetUsernameSerializer):
attrs = super(SetUsernameRetypeSerializer, self).validate(attrs)
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
+ self.fail('username_mismatch')
+ else:
+ return attrs
class TokenSerializer(serializers.ModelSerializer):
@@ -275,6 +275,4 @@ class TokenSerializer(serializers.ModelSerializer):
class Meta:
model = settings.TOKEN_MODEL
- fields = (
- 'auth_token',
- )
+ fields = ('auth_token',)
diff --git a/djoser/social/__init__.py b/djoser/social/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/djoser/social/backends/__init__.py b/djoser/social/backends/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/djoser/social/backends/facebook.py b/djoser/social/backends/facebook.py
new file mode 100644
index 0000000..e00b205
--- /dev/null
+++ b/djoser/social/backends/facebook.py
@@ -0,0 +1,5 @@
+from social_core.backends.facebook import FacebookOAuth2
+
+
+class FacebookOAuth2Override(FacebookOAuth2):
+ REDIRECT_STATE = False
diff --git a/djoser/social/serializers.py b/djoser/social/serializers.py
new file mode 100644
index 0000000..a44e0b6
--- /dev/null
+++ b/djoser/social/serializers.py
@@ -0,0 +1,62 @@
+from rest_framework import serializers
+
+from social_core import exceptions
+from social_django.utils import load_backend, load_strategy
+
+from djoser.conf import settings
+
+
+class ProviderAuthSerializer(serializers.Serializer):
+ # GET auth token
+ token = serializers.CharField(read_only=True)
+ user = serializers.CharField(read_only=True)
+
+ def create(self, validated_data):
+ user = validated_data['user']
+ return settings.SOCIAL_AUTH_TOKEN_STRATEGY.obtain(user)
+
+ def validate(self, attrs):
+ request = self.context['request']
+ if 'state' in request.GET:
+ self._validate_state(request.GET['state'])
+
+ strategy = load_strategy(request)
+ redirect_uri = strategy.session_get('redirect_uri')
+
+ backend_name = self.context['view'].kwargs['provider']
+ backend = load_backend(
+ strategy, backend_name, redirect_uri=redirect_uri
+ )
+
+ try:
+ user = backend.auth_complete()
+ except exceptions.AuthException as e:
+ raise serializers.ValidationError(str(e))
+ return {'user': user}
+
+ def _validate_state(self, value):
+ request = self.context['request']
+ strategy = load_strategy(request)
+ redirect_uri = strategy.session_get('redirect_uri')
+
+ backend_name = self.context['view'].kwargs['provider']
+ backend = load_backend(
+ strategy, backend_name, redirect_uri=redirect_uri
+ )
+
+ try:
+ backend.validate_state()
+ except exceptions.AuthMissingParameter:
+ raise serializers.ValidationError(
+ 'State could not be found in request data.'
+ )
+ except exceptions.AuthStateMissing:
+ raise serializers.ValidationError(
+ 'State could not be found in server-side session data.'
+ )
+ except exceptions.AuthStateForbidden:
+ raise serializers.ValidationError(
+ 'Invalid state has been provided.'
+ )
+
+ return value
diff --git a/djoser/social/token/__init__.py b/djoser/social/token/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/djoser/social/token/jwt.py b/djoser/social/token/jwt.py
new file mode 100644
index 0000000..a8bd970
--- /dev/null
+++ b/djoser/social/token/jwt.py
@@ -0,0 +1,9 @@
+class TokenStrategy:
+ @classmethod
+ def obtain(cls, user):
+ from rest_framework_jwt.settings import api_settings
+ payload = api_settings.JWT_PAYLOAD_HANDLER(user)
+ return {
+ 'token': api_settings.JWT_ENCODE_HANDLER(payload),
+ 'user': user
+ }
diff --git a/djoser/social/urls.py b/djoser/social/urls.py
new file mode 100644
index 0000000..8c5749e
--- /dev/null
+++ b/djoser/social/urls.py
@@ -0,0 +1,12 @@
+from django.conf.urls import url
+
+from djoser.social import views
+
+
+urlpatterns = [
+ url(
+ r'^o/(?P<provider>\S+)/$',
+ views.ProviderAuthView.as_view(),
+ name='provider-auth'
+ ),
+]
diff --git a/djoser/social/views.py b/djoser/social/views.py
new file mode 100644
index 0000000..9738c8a
--- /dev/null
+++ b/djoser/social/views.py
@@ -0,0 +1,29 @@
+from rest_framework import generics, permissions, status
+from rest_framework.response import Response
+
+from social_django.utils import load_backend, load_strategy
+
+from djoser.conf import settings
+from djoser.social.serializers import ProviderAuthSerializer
+
+
+class ProviderAuthView(generics.CreateAPIView):
+ permission_classes = [permissions.AllowAny]
+ serializer_class = ProviderAuthSerializer
+
+ def get(self, request, *args, **kwargs):
+ redirect_uri = request.GET.get('redirect_uri')
+ if redirect_uri not in settings.SOCIAL_AUTH_ALLOWED_REDIRECT_URIS:
+ return Response(status=status.HTTP_400_BAD_REQUEST)
+ strategy = load_strategy(request)
+ strategy.session_set('redirect_uri', redirect_uri)
+
+ backend_name = self.kwargs['provider']
+ backend = load_backend(
+ strategy, backend_name, redirect_uri=redirect_uri
+
+ )
+ authorization_url = backend.auth_url()
+ return Response(data={
+ 'authorization_url': authorization_url,
+ })
diff --git a/djoser/templates/activation_email_body.html b/djoser/templates/activation_email_body.html
deleted file mode 100644
index 386d436..0000000
--- a/djoser/templates/activation_email_body.html
+++ /dev/null
@@ -1,19 +0,0 @@
-{% load i18n %}{% autoescape off %}
-<html>
-<body>
-{% blocktrans %}<p>
-You're receiving this email because you need to finish activation process on {{ site_name }}.
-</p>{% endblocktrans %}
-
-<p>{% trans "Please go to the following page to activate account:" %}</p>
-<p>{% block reset_link %}</p>
-<p><a href="{{ protocol }}://{{ domain }}/{{ url }}">{{ protocol }}://{{ domain }}/{{ url }}</a></p>
-{% endblock %}
-
-<p>{% trans "Thanks for using our site!" %}</p>
-
-<p>{% blocktrans %}The {{ site_name }} team{% endblocktrans %}</p>
-
-{% endautoescape %}
-</body>
-</html>
\ No newline at end of file
diff --git a/djoser/templates/activation_email_body.txt b/djoser/templates/activation_email_body.txt
deleted file mode 100644
index e3a4254..0000000
--- a/djoser/templates/activation_email_body.txt
+++ /dev/null
@@ -1,13 +0,0 @@
-{% load i18n %}{% autoescape off %}
-{% blocktrans %}You're receiving this email because you need to finish activation process on {{ site_name }}.{% endblocktrans %}
-
-{% trans "Please go to the following page to activate account:" %}
-{% block reset_link %}
-{{ protocol }}://{{ domain }}/{{ url }}
-{% endblock %}
-
-{% trans "Thanks for using our site!" %}
-
-{% blocktrans %}The {{ site_name }} team{% endblocktrans %}
-
-{% endautoescape %}
diff --git a/djoser/templates/activation_email_subject.txt b/djoser/templates/activation_email_subject.txt
deleted file mode 100644
index 4e90491..0000000
--- a/djoser/templates/activation_email_subject.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-{% load i18n %}{% autoescape off %}
-{% blocktrans %}Account activation on {{ site_name }}{% endblocktrans %}
-{% endautoescape %}
\ No newline at end of file
diff --git a/djoser/templates/confirmation_email_body.html b/djoser/templates/confirmation_email_body.html
deleted file mode 100644
index 9a9ca0f..0000000
--- a/djoser/templates/confirmation_email_body.html
+++ /dev/null
@@ -1,12 +0,0 @@
-{% load i18n %}{% autoescape off %}
-<html>
-<body>
-<p>{% trans "Your account has been created and is ready to use!" %}</p>
-
-<p>{% trans "Thanks for using our site!" %}</p>
-
-<p>{% blocktrans %}The {{ site_name }} team{% endblocktrans %}</p>
-
-{% endautoescape %}
... 754 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