Commit 0f90ba9a authored by Michael Fladischer's avatar Michael Fladischer

New upstream version 2.0.1

parent 442e5bcc
The MIT License (MIT)
Copyright (c) 2013 SUNSCRAPERS
Copyright (c) 2013-2019 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
......
Metadata-Version: 1.1
Name: djoser
Version: 1.7.0
Version: 2.0.1
Summary: REST version of Django authentication system.
Home-page: https://github.com/sunscrapers/djoser
Author: SUNSCRAPERS
......@@ -11,16 +11,17 @@ Description: ======
======
.. image:: https://img.shields.io/pypi/v/djoser.svg
:target: https://pypi.org/project/djoser
:target: https://pypi.org/project/djoser
.. image:: https://img.shields.io/travis/sunscrapers/djoser/master.svg
:target: https://travis-ci.org/sunscrapers/djoser
:target: https://travis-ci.org/sunscrapers/djoser
.. image:: https://img.shields.io/codecov/c/github/sunscrapers/djoser.svg
:target: https://codecov.io/gh/sunscrapers/djoser
:target: https://codecov.io/gh/sunscrapers/djoser
.. image:: https://img.shields.io/scrutinizer/g/sunscrapers/djoser.svg
:target: https://scrutinizer-ci.com/g/sunscrapers/djoser
.. image:: https://api.codacy.com/project/badge/Grade/c9bf80318d2741e5bb63912a5e0b32dc
:alt: Codacy Badge
:target: https://app.codacy.com/app/dekoza/djoser?utm_source=github.com&utm_medium=referral&utm_content=sunscrapers/djoser&utm_campaign=Badge_Grade_Dashboard
REST implementation of `Django <https://www.djangoproject.com/>`_ authentication
system. **djoser** library provides a set of `Django Rest Framework <https://www.django-rest-framework.org/>`_
......@@ -42,11 +43,11 @@ Description: ======
To be able to run **djoser** you have to meet following requirements:
- Python (2.7, 3.4, 3.5, 3.6)
- Django (1.11, 2.0, 2.1, 2.2)
- Django REST Framework (3.7, 3.8, 3.9)
- Python (3.5, 3.6, 3.7, 3.8)
- Django (1.11, 2.2)
- Django REST Framework (3.9, 3.10)
Bear in mind that for Django-2.x you will need at least Python 3.5
If you need to support other versions, please use djoser<2.
Installation
============
......@@ -93,11 +94,8 @@ Description: ======
$ pip install django djangorestframework
$ pip install -r requirements.txt
If you are running djoser tests on Python 2.7 you also need to install **mock** library.
.. code-block:: bash
$ pip install mock # only on Python 2.7
$ cd testproject
$ ./manage.py test
......@@ -106,7 +104,7 @@ Description: ======
.. code-block:: bash
$ pip install tox
$ tox
$ tox -p all
You can also play with test project by running following commands:
......@@ -124,21 +122,17 @@ Description: ======
- `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 :: 5 - Production/Stable
Classifier: Framework :: Django
Classifier: Framework :: Django :: 1.11
Classifier: Framework :: Django :: 2.0
Classifier: Framework :: Django :: 2.1
Classifier: Framework :: Django :: 2.2
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
......@@ -3,16 +3,17 @@ djoser
======
.. image:: https://img.shields.io/pypi/v/djoser.svg
:target: https://pypi.org/project/djoser
:target: https://pypi.org/project/djoser
.. image:: https://img.shields.io/travis/sunscrapers/djoser/master.svg
:target: https://travis-ci.org/sunscrapers/djoser
:target: https://travis-ci.org/sunscrapers/djoser
.. image:: https://img.shields.io/codecov/c/github/sunscrapers/djoser.svg
:target: https://codecov.io/gh/sunscrapers/djoser
:target: https://codecov.io/gh/sunscrapers/djoser
.. image:: https://img.shields.io/scrutinizer/g/sunscrapers/djoser.svg
:target: https://scrutinizer-ci.com/g/sunscrapers/djoser
.. image:: https://api.codacy.com/project/badge/Grade/c9bf80318d2741e5bb63912a5e0b32dc
:alt: Codacy Badge
:target: https://app.codacy.com/app/dekoza/djoser?utm_source=github.com&utm_medium=referral&utm_content=sunscrapers/djoser&utm_campaign=Badge_Grade_Dashboard
REST implementation of `Django <https://www.djangoproject.com/>`_ authentication
system. **djoser** library provides a set of `Django Rest Framework <https://www.django-rest-framework.org/>`_
......@@ -34,11 +35,11 @@ Requirements
To be able to run **djoser** you have to meet following requirements:
- Python (2.7, 3.4, 3.5, 3.6)
- Django (1.11, 2.0, 2.1, 2.2)
- Django REST Framework (3.7, 3.8, 3.9)
- Python (3.5, 3.6, 3.7, 3.8)
- Django (1.11, 2.2)
- Django REST Framework (3.9, 3.10)
Bear in mind that for Django-2.x you will need at least Python 3.5
If you need to support other versions, please use djoser<2.
Installation
============
......@@ -85,11 +86,8 @@ requirements manually:
$ pip install django djangorestframework
$ pip install -r requirements.txt
If you are running djoser tests on Python 2.7 you also need to install **mock** library.
.. code-block:: bash
$ pip install mock # only on Python 2.7
$ cd testproject
$ ./manage.py test
......@@ -98,7 +96,7 @@ If you need to run tests against all supported Python and Django versions then i
.. code-block:: bash
$ pip install tox
$ tox
$ tox -p all
You can also play with test project by running following commands:
......@@ -116,4 +114,3 @@ List of projects related to Django, REST and authentication:
- `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)
Metadata-Version: 1.1
Name: djoser
Version: 1.7.0
Version: 2.0.1
Summary: REST version of Django authentication system.
Home-page: https://github.com/sunscrapers/djoser
Author: SUNSCRAPERS
......@@ -11,16 +11,17 @@ Description: ======
======
.. image:: https://img.shields.io/pypi/v/djoser.svg
:target: https://pypi.org/project/djoser
:target: https://pypi.org/project/djoser
.. image:: https://img.shields.io/travis/sunscrapers/djoser/master.svg
:target: https://travis-ci.org/sunscrapers/djoser
:target: https://travis-ci.org/sunscrapers/djoser
.. image:: https://img.shields.io/codecov/c/github/sunscrapers/djoser.svg
:target: https://codecov.io/gh/sunscrapers/djoser
:target: https://codecov.io/gh/sunscrapers/djoser
.. image:: https://img.shields.io/scrutinizer/g/sunscrapers/djoser.svg
:target: https://scrutinizer-ci.com/g/sunscrapers/djoser
.. image:: https://api.codacy.com/project/badge/Grade/c9bf80318d2741e5bb63912a5e0b32dc
:alt: Codacy Badge
:target: https://app.codacy.com/app/dekoza/djoser?utm_source=github.com&utm_medium=referral&utm_content=sunscrapers/djoser&utm_campaign=Badge_Grade_Dashboard
REST implementation of `Django <https://www.djangoproject.com/>`_ authentication
system. **djoser** library provides a set of `Django Rest Framework <https://www.django-rest-framework.org/>`_
......@@ -42,11 +43,11 @@ Description: ======
To be able to run **djoser** you have to meet following requirements:
- Python (2.7, 3.4, 3.5, 3.6)
- Django (1.11, 2.0, 2.1, 2.2)
- Django REST Framework (3.7, 3.8, 3.9)
- Python (3.5, 3.6, 3.7, 3.8)
- Django (1.11, 2.2)
- Django REST Framework (3.9, 3.10)
Bear in mind that for Django-2.x you will need at least Python 3.5
If you need to support other versions, please use djoser<2.
Installation
============
......@@ -93,11 +94,8 @@ Description: ======
$ pip install django djangorestframework
$ pip install -r requirements.txt
If you are running djoser tests on Python 2.7 you also need to install **mock** library.
.. code-block:: bash
$ pip install mock # only on Python 2.7
$ cd testproject
$ ./manage.py test
......@@ -106,7 +104,7 @@ Description: ======
.. code-block:: bash
$ pip install tox
$ tox
$ tox -p all
You can also play with test project by running following commands:
......@@ -124,21 +122,17 @@ Description: ======
- `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 :: 5 - Production/Stable
Classifier: Framework :: Django
Classifier: Framework :: Django :: 1.11
Classifier: Framework :: Django :: 2.0
Classifier: Framework :: Django :: 2.1
Classifier: Framework :: Django :: 2.2
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
......@@ -19,6 +19,9 @@ djoser.egg-info/SOURCES.txt
djoser.egg-info/dependency_links.txt
djoser.egg-info/requires.txt
djoser.egg-info/top_level.txt
djoser/locale/ka/LC_MESSAGES/django.mo
djoser/locale/pl/LC_MESSAGES/django.mo
djoser/locale/ru_RU/LC_MESSAGES/django.mo
djoser/social/__init__.py
djoser/social/serializers.py
djoser/social/urls.py
......@@ -29,7 +32,10 @@ djoser/social/token/__init__.py
djoser/social/token/jwt.py
djoser/templates/email/activation.html
djoser/templates/email/confirmation.html
djoser/templates/email/password_changed_confirmation.html
djoser/templates/email/password_reset.html
djoser/templates/email/username_changed_confirmation.html
djoser/templates/email/username_reset.html
djoser/urls/__init__.py
djoser/urls/authtoken.py
djoser/urls/base.py
......
__version__ = "1.7.0"
__version__ = "2.0.1"
from djoser.conf import settings
__all__ = ['settings']
__all__ = ["settings"]
def get_user_email(user):
......
import warnings
from django.apps import apps
from django.conf import settings as django_settings
from django.core.exceptions import ImproperlyConfigured
from django.test.signals import setting_changed
from django.utils import six
from django.utils.functional import LazyObject
from django.utils.module_loading import import_string
DJOSER_SETTINGS_NAMESPACE = 'DJOSER'
DJOSER_SETTINGS_NAMESPACE = "DJOSER"
auth_module, user_model = django_settings.AUTH_USER_MODEL.rsplit('.', 1)
auth_module, user_model = django_settings.AUTH_USER_MODEL.rsplit(".", 1)
User = apps.get_model(auth_module, user_model)
......@@ -22,7 +19,7 @@ class ObjDict(dict):
if isinstance(val, str):
val = import_string(val)
elif isinstance(val, (list, tuple)):
val = [import_string(v) if type(v) is str else v for v in val]
val = [import_string(v) if isinstance(v, str) else v for v in val]
self[item] = val
except KeyError:
val = super(ObjDict, self).__getattribute__(item)
......@@ -31,87 +28,88 @@ class ObjDict(dict):
default_settings = {
'LOGIN_FIELD': User.USERNAME_FIELD,
'SEND_ACTIVATION_EMAIL': False,
'SEND_CONFIRMATION_EMAIL': False,
'USER_CREATE_PASSWORD_RETYPE': False,
'SET_PASSWORD_RETYPE': False,
'SET_USERNAME_RETYPE': False,
'PASSWORD_RESET_CONFIRM_RETYPE': False,
'PASSWORD_RESET_SHOW_EMAIL_NOT_FOUND': False,
'PASSWORD_VALIDATORS': [],
'TOKEN_MODEL': 'rest_framework.authtoken.models.Token',
'SERIALIZERS': ObjDict({
'activation':
'djoser.serializers.ActivationSerializer',
'password_reset':
'djoser.serializers.PasswordResetSerializer',
'password_reset_confirm':
'djoser.serializers.PasswordResetConfirmSerializer',
'password_reset_confirm_retype':
'djoser.serializers.PasswordResetConfirmRetypeSerializer',
'set_password':
'djoser.serializers.SetPasswordSerializer',
'set_password_retype':
'djoser.serializers.SetPasswordRetypeSerializer',
'set_username':
'djoser.serializers.SetUsernameSerializer',
'set_username_retype':
'djoser.serializers.SetUsernameRetypeSerializer',
'user_create':
'djoser.serializers.UserCreateSerializer',
'user_create_password_retype':
'djoser.serializers.UserCreatePasswordRetypeSerializer',
'user_delete':
'djoser.serializers.UserDeleteSerializer',
'user':
'djoser.serializers.UserSerializer',
'current_user':
'djoser.serializers.CurrentUserSerializer',
'token':
'djoser.serializers.TokenSerializer',
'token_create':
'djoser.serializers.TokenCreateSerializer',
}),
'EMAIL': ObjDict({
'activation': 'djoser.email.ActivationEmail',
'confirmation': 'djoser.email.ConfirmationEmail',
'password_reset': 'djoser.email.PasswordResetEmail',
}),
'CONSTANTS': ObjDict({
'messages': 'djoser.constants.Messages',
}),
'LOGOUT_ON_PASSWORD_CHANGE': False,
'CREATE_SESSION_ON_LOGIN': False,
'USER_EMAIL_FIELD_NAME': 'email',
'SOCIAL_AUTH_TOKEN_STRATEGY': 'djoser.social.token.jwt.TokenStrategy',
'SOCIAL_AUTH_ALLOWED_REDIRECT_URIS': [],
'PERMISSIONS': ObjDict({
'activation': ['rest_framework.permissions.AllowAny'],
'password_reset': ['rest_framework.permissions.AllowAny'],
'password_reset_confirm': ['rest_framework.permissions.AllowAny'],
'set_password': ['djoser.permissions.CurrentUserOrAdmin'],
'set_username': ['rest_framework.permissions.IsAuthenticated'],
'user_create': ['rest_framework.permissions.AllowAny'],
'user_delete': ['djoser.permissions.CurrentUserOrAdmin'],
'user': ['djoser.permissions.CurrentUserOrAdminOrReadOnly'],
'user_list': ['djoser.permissions.CurrentUserOrAdminOrReadOnly'],
'token_create': ['rest_framework.permissions.AllowAny'],
'token_destroy': ['rest_framework.permissions.IsAuthenticated'],
}),
"LOGIN_FIELD": User.USERNAME_FIELD,
"SEND_ACTIVATION_EMAIL": False,
"SEND_CONFIRMATION_EMAIL": False,
"USER_CREATE_PASSWORD_RETYPE": False,
"SET_PASSWORD_RETYPE": False,
"PASSWORD_RESET_CONFIRM_RETYPE": False,
"SET_USERNAME_RETYPE": False,
"USERNAME_RESET_CONFIRM_RETYPE": False,
"PASSWORD_RESET_SHOW_EMAIL_NOT_FOUND": False,
"USERNAME_RESET_SHOW_EMAIL_NOT_FOUND": False,
"PASSWORD_CHANGED_EMAIL_CONFIRMATION": False,
"USERNAME_CHANGED_EMAIL_CONFIRMATION": False,
"TOKEN_MODEL": "rest_framework.authtoken.models.Token",
"SERIALIZERS": ObjDict(
{
"activation": "djoser.serializers.ActivationSerializer",
"password_reset": "djoser.serializers.SendEmailResetSerializer",
"password_reset_confirm": "djoser.serializers.PasswordResetConfirmSerializer",
"password_reset_confirm_retype": "djoser.serializers.PasswordResetConfirmRetypeSerializer",
"set_password": "djoser.serializers.SetPasswordSerializer",
"set_password_retype": "djoser.serializers.SetPasswordRetypeSerializer",
"set_username": "djoser.serializers.SetUsernameSerializer",
"set_username_retype": "djoser.serializers.SetUsernameRetypeSerializer",
"username_reset": "djoser.serializers.SendEmailResetSerializer",
"username_reset_confirm": "djoser.serializers.UsernameResetConfirmSerializer",
"username_reset_confirm_retype": "djoser.serializers.UsernameResetConfirmRetypeSerializer",
"user_create": "djoser.serializers.UserCreateSerializer",
"user_create_password_retype": "djoser.serializers.UserCreatePasswordRetypeSerializer",
"user_delete": "djoser.serializers.UserDeleteSerializer",
"user": "djoser.serializers.UserSerializer",
"current_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",
"password_changed_confirmation": "djoser.email.PasswordChangedConfirmationEmail",
"username_changed_confirmation": "djoser.email.UsernameChangedConfirmationEmail",
"username_reset": "djoser.email.UsernameResetEmail",
}
),
"CONSTANTS": ObjDict({"messages": "djoser.constants.Messages"}),
"LOGOUT_ON_PASSWORD_CHANGE": False,
"CREATE_SESSION_ON_LOGIN": False,
"SOCIAL_AUTH_TOKEN_STRATEGY": "djoser.social.token.jwt.TokenStrategy",
"SOCIAL_AUTH_ALLOWED_REDIRECT_URIS": [],
"HIDE_USERS": True,
"PERMISSIONS": ObjDict(
{
"activation": ["rest_framework.permissions.AllowAny"],
"password_reset": ["rest_framework.permissions.AllowAny"],
"password_reset_confirm": ["rest_framework.permissions.AllowAny"],
"set_password": ["djoser.permissions.CurrentUserOrAdmin"],
"username_reset": ["rest_framework.permissions.AllowAny"],
"username_reset_confirm": ["rest_framework.permissions.AllowAny"],
"set_username": ["djoser.permissions.CurrentUserOrAdmin"],
"user_create": ["rest_framework.permissions.AllowAny"],
"user_delete": ["djoser.permissions.CurrentUserOrAdmin"],
"user": ["djoser.permissions.CurrentUserOrAdmin"],
"user_list": ["djoser.permissions.CurrentUserOrAdmin"],
"token_create": ["rest_framework.permissions.AllowAny"],
"token_destroy": ["rest_framework.permissions.IsAuthenticated"],
}
),
}
SETTINGS_TO_IMPORT = ['TOKEN_MODEL', 'SOCIAL_AUTH_TOKEN_STRATEGY']
SETTINGS_TO_IMPORT = ["TOKEN_MODEL", "SOCIAL_AUTH_TOKEN_STRATEGY"]
class Settings(object):
class Settings:
def __init__(self, default_settings, explicit_overriden_settings=None):
if explicit_overriden_settings is None:
explicit_overriden_settings = {}
overriden_settings = getattr(
django_settings, DJOSER_SETTINGS_NAMESPACE, {}
) or explicit_overriden_settings
overriden_settings = (
getattr(django_settings, DJOSER_SETTINGS_NAMESPACE, {})
or explicit_overriden_settings
)
self._load_default_settings()
self._override_settings(overriden_settings)
......@@ -141,30 +139,13 @@ class LazySettings(LazyObject):
def _setup(self, explicit_overriden_settings=None):
self._wrapped = Settings(default_settings, explicit_overriden_settings)
def get(self, key):
"""
This function is here only to provide backwards compatibility in
case anyone uses old settings interface.
It is strongly encouraged to use dot notation.
"""
warnings.warn(
'The settings.get(key) is superseded by the dot attribute access.',
PendingDeprecationWarning
)
try:
return getattr(self, key)
except AttributeError:
raise ImproperlyConfigured('Missing settings: {}[\'{}\']'.format(
DJOSER_SETTINGS_NAMESPACE, key)
)
settings = LazySettings()
def reload_djoser_settings(*args, **kwargs):
global settings
setting, value = kwargs['setting'], kwargs['value']
setting, value = kwargs["setting"], kwargs["value"]
if setting == DJOSER_SETTINGS_NAMESPACE:
settings._setup(explicit_overriden_settings=value)
......
......@@ -2,18 +2,13 @@ from django.utils.translation import ugettext_lazy as _
class Messages(object):
INVALID_CREDENTIALS_ERROR = _('Unable to log in with provided credentials.')
INACTIVE_ACCOUNT_ERROR = _('User account is disabled.')
INVALID_TOKEN_ERROR = _('Invalid token for given user.')
INVALID_UID_ERROR = _('Invalid user id or user doesn\'t exist.')
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.')
EMAIL_NOT_FOUND = _('User with given email does not exist.')
CANNOT_CREATE_USER_ERROR = _('Unable to create account.')
USER_WITHOUT_EMAIL_FIELD_ERROR = _(
'User model does not contain specified email field. '
'Please see http://djoser.readthedocs.io/en/latest/settings.html#'
'USER_EMAIL_FIELD_NAME for more details.'
)
INVALID_CREDENTIALS_ERROR = _("Unable to log in with provided credentials.")
INACTIVE_ACCOUNT_ERROR = _("User account is disabled.")
INVALID_TOKEN_ERROR = _("Invalid token for given user.")
INVALID_UID_ERROR = _("Invalid user id or user doesn't exist.")
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.")
EMAIL_NOT_FOUND = _("User with given email does not exist.")
CANNOT_CREATE_USER_ERROR = _("Unable to create account.")
from django.contrib.auth.tokens import default_token_generator
from templated_mail.mail import BaseEmailMessage
from djoser import utils
from djoser.conf import settings
from templated_mail.mail import BaseEmailMessage
class ActivationEmail(BaseEmailMessage):
template_name = 'email/activation.html'
template_name = "email/activation.html"
def get_context_data(self):
context = super(ActivationEmail, self).get_context_data()
# ActivationEmail can be deleted
context = super().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)
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'
template_name = "email/confirmation.html"
class PasswordResetEmail(BaseEmailMessage):
template_name = 'email/password_reset.html'
template_name = "email/password_reset.html"
def get_context_data(self):
# PasswordResetEmail can be deleted
context = super().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
class PasswordChangedConfirmationEmail(BaseEmailMessage):
template_name = "email/password_changed_confirmation.html"
class UsernameChangedConfirmationEmail(BaseEmailMessage):
template_name = "email/username_changed_confirmation.html"
class UsernameResetEmail(BaseEmailMessage):
template_name = "email/username_reset.html"
def get_context_data(self):
context = super(PasswordResetEmail, self).get_context_data()
context = super().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)
user = context.get("user")
context["uid"] = utils.encode_uid(user.pk)
context["token"] = default_token_generator.make_token(user)
context["url"] = settings.USERNAME_RESET_CONFIRM_URL.format(**context)
return context
This diff is collapsed.
from djoser.conf import settings
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
......@@ -13,51 +11,45 @@ class ProviderAuthSerializer(serializers.Serializer):
user = serializers.CharField(read_only=True)
def create(self, validated_data):
user = validated_data['user']
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'])
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')
redirect_uri = strategy.session_get("redirect_uri")
backend_name = self.context['view'].kwargs['provider']
backend = load_backend(
strategy, backend_name, redirect_uri=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}
return {"user": user}
def _validate_state(self, value):
request = self.context['request']
request = self.context["request"]
strategy = load_strategy(request)
redirect_uri = strategy.session_get('redirect_uri')
redirect_uri = strategy.session_get("redirect_uri")
backend_name = self.context['view'].kwargs['provider']
backend = load_backend(
strategy, backend_name, redirect_uri=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.'
"State could not be found in request data."
)
except exceptions.AuthStateMissing:
raise serializers.ValidationError(
'State could not be found in server-side session data.'
"State could not be found in server-side session data."
)
except exceptions.AuthStateForbidden:
raise serializers.ValidationError(
'Invalid state has been provided.'
)
raise serializers.ValidationError("Invalid state has been provided.")
return value
......@@ -3,9 +3,10 @@ class TokenStrategy:
def obtain(cls, user):
from rest_framework_simplejwt.tokens import RefreshToken
from django.utils.six import text_type
refresh = RefreshToken.for_user(user)
return {
'access': text_type(refresh.access_token),
'refresh': text_type(refresh),
'user': user,
"access": text_type(refresh.access_token),
"refresh": text_type(refresh),
"user": user,
}
from django.conf.urls import url
from djoser.social import views
urlpatterns = [
url(
r'^o/(?P<provider>\S+)/$',
r"^o/(?P<provider>\S+)/$",
views.ProviderAuthView.as_view(),
name='provider-auth'
),
name="provider-auth",
)
]
from djoser.conf import settings
from djoser.social.serializers import ProviderAuthSerializer
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')
redirect_uri = request.GET.get("redirect_uri")
if redirect_uri not in settings.SOCIAL_AUTH_ALLOWED_REDIRECT_URIS: