Commit 3afb0c71 authored by Ana Rodríguez López's avatar Ana Rodríguez López

Import upstream version 3.1.0

parent 61f42d7d
......@@ -5,7 +5,25 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased](https://github.com/python-social-auth/social-app-django/commits/master)
## [3.1.0](https://github.com/python-social-auth/social-app-django/releases/tag/3.1.0) - 2018-10-31
### Changed
- Updated `JSONField.from_db_value` signature to support multiple Django
versions by accepting just the needed parameters.
## [3.0.0](https://github.com/python-social-auth/social-app-django/releases/tag/3.0.0) - 2018-10-28
### Changed
- Reduce log level of exceptions to `INFO` if messages app is installed
- Encode association secret with `encodebytes` if available
- Decode association secret for proper storage
- Remove obsolete code from JSONField
- Pass `user` as keyword argument to `do_complete`
- Cleanup `username` when using email as username
- Drop Python 3.3 support
- Correct spelling errors
- Correct version that renamed `field.rel`
- Reduce error logs in `SocialAuthExceptionMiddleware`
## [2.1.0](https://github.com/python-social-auth/social-app-django/releases/tag/2.1.0) - 2017-12-22
......@@ -13,6 +31,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Use Django `urlquote` since it handles unicode
- Remove version check in favor of import error catch
- Remove call to deprecated method `_get_val_from_obj()`
- Drop Python 3.3 support
## [2.0.0](https://github.com/python-social-auth/social-app-django/releases/tag/2.0.0) - 2017-10-28
......
Metadata-Version: 1.1
Name: social-auth-app-django
Version: 2.1.0
Summary: Python Social Authentication, Django integration.
Home-page: https://github.com/python-social-auth/social-app-django
Author: Matias Aguirre
Author-email: matiasaguirre@gmail.com
License: BSD
Description-Content-Type: UNKNOWN
Description: # Python Social Auth - Django
[![Build Status](https://travis-ci.org/python-social-auth/social-app-django.svg?branch=master)](https://travis-ci.org/python-social-auth/social-app-django)
[![Donate](https://img.shields.io/badge/Donate-PayPal-orange.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=matiasaguirre%40gmail%2ecom&lc=US&item_name=Python%20Social%20Auth&no_note=0&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHostedGuest)
Python Social Auth is an easy to setup social authentication/registration
mechanism with support for several frameworks and auth providers.
## Description
This is the [Django](https://www.djangoproject.com/) component of the
[python-social-auth ecosystem](https://github.com/python-social-auth/social-core),
it implements the needed functionality to integrate
[social-auth-core](https://github.com/python-social-auth/social-core)
in a Django based project.
## Django version
This project will focus on the currently supported Django releases as
stated on the [Django Project Supported Versions table](https://www.djangoproject.com/download/#supported-versions).
Backward compatibility with unsupported versions won't be enforced.
## Documentation
Project documentation is available at http://python-social-auth.readthedocs.org/.
## Setup
```shell
$ pip install social-auth-app-django
```
## Contributing
See the [CONTRIBUTING.md](CONTRIBUTING.md) document for details.
## Versioning
This project follows [Semantic Versioning 2.0.0](http://semver.org/spec/v2.0.0.html).
## License
This project follows the BSD license. See the [LICENSE](LICENSE) for details.
## Donations
This project is maintened on my spare time, consider donating to keep
it improving.
[![Donate](https://img.shields.io/badge/Donate-PayPal-orange.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=matiasaguirre%40gmail%2ecom&lc=US&item_name=Python%20Social%20Auth&no_note=0&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHostedGuest)
Keywords: django,social auth
Platform: UNKNOWN
Classifier: Development Status :: 4 - Beta
Classifier: Topic :: Internet
Classifier: License :: OSI Approved :: BSD License
Classifier: Intended Audience :: Developers
Classifier: Environment :: Web Environment
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
......@@ -2,6 +2,7 @@
[![Build Status](https://travis-ci.org/python-social-auth/social-app-django.svg?branch=master)](https://travis-ci.org/python-social-auth/social-app-django)
[![Donate](https://img.shields.io/badge/Donate-PayPal-orange.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=matiasaguirre%40gmail%2ecom&lc=US&item_name=Python%20Social%20Auth&no_note=0&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHostedGuest)
[![PyPI version](https://badge.fury.io/py/social-auth-app-django.svg)](https://badge.fury.io/py/social-auth-app-django)
Python Social Auth is an easy to setup social authentication/registration
mechanism with support for several frameworks and auth providers.
......@@ -45,7 +46,7 @@ This project follows the BSD license. See the [LICENSE](LICENSE) for details.
## Donations
This project is maintened on my spare time, consider donating to keep
This project is maintained on my spare time, consider donating to keep
it improving.
[![Donate](https://img.shields.io/badge/Donate-PayPal-orange.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=matiasaguirre%40gmail%2ecom&lc=US&item_name=Python%20Social%20Auth&no_note=0&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHostedGuest)
[flake8]
max-line-length = 119
# Ignore some well known paths
exclude = .venv,.tox,dist,doc,build,*.egg,db/env.py,db/versions/*.py,site
[nosetests]
verbosity = 2
with-coverage = 1
cover-erase = 1
cover-package = social
rednose = 1
[egg_info]
tag_build =
tag_date = 0
verbosity=2
with-coverage=1
cover-erase=1
cover-package=social
rednose=1
......@@ -34,7 +34,9 @@ setup(
url='https://github.com/python-social-auth/social-app-django',
packages=[
'social_django',
'social_django.migrations'
'social_django.migrations',
'social_django.management',
'social_django.management.commands',
],
long_description=long_description(),
install_requires=load_requirements(),
......
Metadata-Version: 1.1
Name: social-auth-app-django
Version: 2.1.0
Summary: Python Social Authentication, Django integration.
Home-page: https://github.com/python-social-auth/social-app-django
Author: Matias Aguirre
Author-email: matiasaguirre@gmail.com
License: BSD
Description-Content-Type: UNKNOWN
Description: # Python Social Auth - Django
[![Build Status](https://travis-ci.org/python-social-auth/social-app-django.svg?branch=master)](https://travis-ci.org/python-social-auth/social-app-django)
[![Donate](https://img.shields.io/badge/Donate-PayPal-orange.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=matiasaguirre%40gmail%2ecom&lc=US&item_name=Python%20Social%20Auth&no_note=0&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHostedGuest)
Python Social Auth is an easy to setup social authentication/registration
mechanism with support for several frameworks and auth providers.
## Description
This is the [Django](https://www.djangoproject.com/) component of the
[python-social-auth ecosystem](https://github.com/python-social-auth/social-core),
it implements the needed functionality to integrate
[social-auth-core](https://github.com/python-social-auth/social-core)
in a Django based project.
## Django version
This project will focus on the currently supported Django releases as
stated on the [Django Project Supported Versions table](https://www.djangoproject.com/download/#supported-versions).
Backward compatibility with unsupported versions won't be enforced.
## Documentation
Project documentation is available at http://python-social-auth.readthedocs.org/.
## Setup
```shell
$ pip install social-auth-app-django
```
## Contributing
See the [CONTRIBUTING.md](CONTRIBUTING.md) document for details.
## Versioning
This project follows [Semantic Versioning 2.0.0](http://semver.org/spec/v2.0.0.html).
## License
This project follows the BSD license. See the [LICENSE](LICENSE) for details.
## Donations
This project is maintened on my spare time, consider donating to keep
it improving.
[![Donate](https://img.shields.io/badge/Donate-PayPal-orange.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=matiasaguirre%40gmail%2ecom&lc=US&item_name=Python%20Social%20Auth&no_note=0&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHostedGuest)
Keywords: django,social auth
Platform: UNKNOWN
Classifier: Development Status :: 4 - Beta
Classifier: Topic :: Internet
Classifier: License :: OSI Approved :: BSD License
Classifier: Intended Audience :: Developers
Classifier: Environment :: Web Environment
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
CHANGELOG.md
LICENSE
MANIFEST.in
README.md
dev-requirements.txt
manage.py
requirements.txt
setup.cfg
setup.py
social_auth_app_django.egg-info/PKG-INFO
social_auth_app_django.egg-info/SOURCES.txt
social_auth_app_django.egg-info/dependency_links.txt
social_auth_app_django.egg-info/not-zip-safe
social_auth_app_django.egg-info/requires.txt
social_auth_app_django.egg-info/top_level.txt
social_django/__init__.py
social_django/admin.py
social_django/compat.py
social_django/config.py
social_django/context_processors.py
social_django/fields.py
social_django/managers.py
social_django/middleware.py
social_django/models.py
social_django/storage.py
social_django/strategy.py
social_django/urls.py
social_django/utils.py
social_django/views.py
social_django/management/__init__.py
social_django/management/commands/__init__.py
social_django/management/commands/clearsocial.py
social_django/migrations/0001_initial.py
social_django/migrations/0002_add_related_name.py
social_django/migrations/0003_alter_email_max_length.py
social_django/migrations/0004_auto_20160423_0400.py
social_django/migrations/0005_auto_20160727_2333.py
social_django/migrations/0006_partial.py
social_django/migrations/0007_code_timestamp.py
social_django/migrations/0008_partial_timestamp.py
social_django/migrations/__init__.py
tests/__init__.py
tests/compat.py
tests/settings.py
tests/test_admin.py
tests/test_context_processors.py
tests/test_middleware.py
tests/test_models.py
tests/test_strategy.py
tests/test_views.py
tests/urls.py
\ No newline at end of file
__version__ = '2.1.0'
__version__ = '3.1.0'
from social_core.backends.base import BaseAuth
......
......@@ -16,7 +16,7 @@ except ImportError:
def get_rel_model(field):
if django.VERSION >= (2, 0):
if django.VERSION >= (1, 9):
return field.remote_field.model
user_model = field.rel.to
......
import json
import six
import functools
import django
from django.core.exceptions import ValidationError
from django.conf import settings
from django.db import models
from django.utils.encoding import force_text
from social_core.utils import setting_name
try:
from django.utils.encoding import smart_unicode as smart_text
smart_text # placate pyflakes
except ImportError:
from django.utils.encoding import smart_text
# SubfieldBase causes RemovedInDjango110Warning in 1.8 and 1.9, and
# will not work in 1.10 or later
if django.VERSION[:2] >= (1, 8):
field_metaclass = type
else:
from django.db.models import SubfieldBase
field_metaclass = SubfieldBase
field_class = functools.partial(six.with_metaclass, field_metaclass)
if getattr(settings, setting_name('POSTGRES_JSONFIELD'), False):
from django.contrib.postgres.fields import JSONField as JSONFieldBase
else:
JSONFieldBase = field_class(models.TextField)
JSONFieldBase = models.TextField
class JSONField(JSONFieldBase):
......@@ -41,7 +23,7 @@ class JSONField(JSONFieldBase):
kwargs.setdefault('default', dict)
super(JSONField, self).__init__(*args, **kwargs)
def from_db_value(self, value, expression, connection, context):
def from_db_value(self, value, *args, **kwargs):
return self.to_python(value)
def to_python(self, value):
......@@ -56,10 +38,6 @@ class JSONField(JSONFieldBase):
value = six.text_type(value, 'utf-8')
if isinstance(value, six.string_types):
try:
# with django 1.6 i have '"{}"' as default value here
if value[0] == value[-1] == '"':
value = value[1:-1]
return json.loads(value)
except Exception as err:
raise ValidationError(str(err))
......@@ -85,10 +63,9 @@ class JSONField(JSONFieldBase):
def value_to_string(self, obj):
"""Return value from object converted to string properly"""
return smart_text(self.value_from_object(obj))
return force_text(self.value_from_object(obj))
def value_from_object(self, obj):
"""Return value dumped to string."""
orig_val = super(JSONField, self).value_from_object(obj)
return self.get_prep_value(orig_val)
# -*- coding: utf-8 -*-
import six
from django.apps import apps
from django.conf import settings
from django.contrib import messages
from django.contrib.messages.api import MessageFailure
......@@ -33,17 +34,21 @@ class SocialAuthExceptionMiddleware(MiddlewareMixin):
backend_name = getattr(backend, 'name', 'unknown-backend')
message = self.get_message(request, exception)
social_logger.error(message)
url = self.get_redirect_uri(request, exception)
try:
messages.error(request, message,
extra_tags='social-auth ' + backend_name)
except MessageFailure:
if url:
url += ('?' in url and '&' or '?') + \
'message={0}&backend={1}'.format(urlquote(message),
backend_name)
if apps.is_installed('django.contrib.messages'):
social_logger.info(message)
try:
messages.error(request, message,
extra_tags='social-auth ' + backend_name)
except MessageFailure:
if url:
url += ('?' in url and '&' or '?') + \
'message={0}&backend={1}'.format(urlquote(message),
backend_name)
else:
social_logger.error(message)
if url:
return redirect(url)
......
......@@ -2,6 +2,7 @@
import base64
import six
import sys
from django.core.exceptions import FieldDoesNotExist
from django.db import transaction
from django.db.utils import IntegrityError
......@@ -58,8 +59,16 @@ class DjangoUserMixin(UserMixin):
@classmethod
def create_user(cls, *args, **kwargs):
username_field = cls.username_field()
if 'username' in kwargs and username_field not in kwargs:
kwargs[username_field] = kwargs.pop('username')
if 'username' in kwargs:
if username_field not in kwargs:
kwargs[username_field] = kwargs.pop('username')
else:
# If username_field is 'email' and there is no field named "username"
# then latest should be removed from kwargs.
try:
cls.user_model()._meta.get_field('username')
except FieldDoesNotExist:
kwargs.pop('username')
try:
if hasattr(transaction, 'atomic'):
# In Django versions that have an "atomic" transaction decorator / context
......@@ -152,7 +161,11 @@ class DjangoAssociationMixin(AssociationMixin):
except cls.DoesNotExist:
assoc = cls(server_url=server_url,
handle=association.handle)
assoc.secret = base64.encodestring(association.secret)
try:
assoc.secret = base64.encodebytes(association.secret).decode()
except AttributeError:
assoc.secret = base64.encodestring(association.secret).decode()
assoc.issued = association.issued
assoc.lifetime = association.lifetime
assoc.assoc_type = association.assoc_type
......
......@@ -28,7 +28,7 @@ def auth(request, backend):
@psa('{0}:complete'.format(NAMESPACE))
def complete(request, backend, *args, **kwargs):
"""Authentication complete view"""
return do_complete(request.backend, _do_login, request.user,
return do_complete(request.backend, _do_login, user=request.user,
redirect_name=REDIRECT_FIELD_NAME, request=request,
*args, **kwargs)
......
......@@ -188,6 +188,7 @@ class TestAssociation(TestCase):
qs = Association.get(handle='a')
self.assertEqual(qs.count(), 1)
self.assertEqual(qs[0].secret, 'Yg==\n')
Association.remove(ids_to_delete=[qs.first().id])
self.assertEqual(Association.objects.count(), 0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment