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

New upstream version 2.0.1

parent 442e5bcc
The MIT License (MIT) 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 Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
......
Metadata-Version: 1.1 Metadata-Version: 1.1
Name: djoser Name: djoser
Version: 1.7.0 Version: 2.0.1
Summary: REST version of Django authentication system. Summary: REST version of Django authentication system.
Home-page: https://github.com/sunscrapers/djoser Home-page: https://github.com/sunscrapers/djoser
Author: SUNSCRAPERS Author: SUNSCRAPERS
...@@ -11,16 +11,17 @@ Description: ====== ...@@ -11,16 +11,17 @@ Description: ======
====== ======
.. image:: https://img.shields.io/pypi/v/djoser.svg .. 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 .. 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 .. 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 .. image:: https://api.codacy.com/project/badge/Grade/c9bf80318d2741e5bb63912a5e0b32dc
:target: https://scrutinizer-ci.com/g/sunscrapers/djoser :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 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/>`_ system. **djoser** library provides a set of `Django Rest Framework <https://www.django-rest-framework.org/>`_
...@@ -42,11 +43,11 @@ Description: ====== ...@@ -42,11 +43,11 @@ Description: ======
To be able to run **djoser** you have to meet following requirements: To be able to run **djoser** you have to meet following requirements:
- Python (2.7, 3.4, 3.5, 3.6) - Python (3.5, 3.6, 3.7, 3.8)
- Django (1.11, 2.0, 2.1, 2.2) - Django (1.11, 2.2)
- Django REST Framework (3.7, 3.8, 3.9) - 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 Installation
============ ============
...@@ -93,11 +94,8 @@ Description: ====== ...@@ -93,11 +94,8 @@ Description: ======
$ pip install django djangorestframework $ pip install django djangorestframework
$ pip install -r requirements.txt $ 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 .. code-block:: bash
$ pip install mock # only on Python 2.7
$ cd testproject $ cd testproject
$ ./manage.py test $ ./manage.py test
...@@ -106,7 +104,7 @@ Description: ====== ...@@ -106,7 +104,7 @@ Description: ======
.. code-block:: bash .. code-block:: bash
$ pip install tox $ pip install tox
$ tox $ tox -p all
You can also play with test project by running following commands: You can also play with test project by running following commands:
...@@ -124,21 +122,17 @@ Description: ====== ...@@ -124,21 +122,17 @@ Description: ======
- `django-oauth-toolkit <https://github.com/evonove/django-oauth-toolkit>`_ - `django-oauth-toolkit <https://github.com/evonove/django-oauth-toolkit>`_
- `django-rest-auth <https://github.com/Tivix/django-rest-auth>`_ - `django-rest-auth <https://github.com/Tivix/django-rest-auth>`_
- `django-rest-framework-digestauth <https://github.com/juanriaza/django-rest-framework-digestauth>`_ (not maintained) - `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 Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable Classifier: Development Status :: 5 - Production/Stable
Classifier: Framework :: Django Classifier: Framework :: Django
Classifier: Framework :: Django :: 1.11 Classifier: Framework :: Django :: 1.11
Classifier: Framework :: Django :: 2.0
Classifier: Framework :: Django :: 2.1
Classifier: Framework :: Django :: 2.2 Classifier: Framework :: Django :: 2.2
Classifier: Intended Audience :: Developers Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python 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.5
Classifier: Programming Language :: Python :: 3.6 Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7 Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
...@@ -3,16 +3,17 @@ djoser ...@@ -3,16 +3,17 @@ djoser
====== ======
.. image:: https://img.shields.io/pypi/v/djoser.svg .. 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 .. 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 .. 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 .. image:: https://api.codacy.com/project/badge/Grade/c9bf80318d2741e5bb63912a5e0b32dc
:target: https://scrutinizer-ci.com/g/sunscrapers/djoser :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 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/>`_ system. **djoser** library provides a set of `Django Rest Framework <https://www.django-rest-framework.org/>`_
...@@ -34,11 +35,11 @@ Requirements ...@@ -34,11 +35,11 @@ Requirements
To be able to run **djoser** you have to meet following requirements: To be able to run **djoser** you have to meet following requirements:
- Python (2.7, 3.4, 3.5, 3.6) - Python (3.5, 3.6, 3.7, 3.8)
- Django (1.11, 2.0, 2.1, 2.2) - Django (1.11, 2.2)
- Django REST Framework (3.7, 3.8, 3.9) - 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 Installation
============ ============
...@@ -85,11 +86,8 @@ requirements manually: ...@@ -85,11 +86,8 @@ requirements manually:
$ pip install django djangorestframework $ pip install django djangorestframework
$ pip install -r requirements.txt $ 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 .. code-block:: bash
$ pip install mock # only on Python 2.7
$ cd testproject $ cd testproject
$ ./manage.py test $ ./manage.py test
...@@ -98,7 +96,7 @@ If you need to run tests against all supported Python and Django versions then i ...@@ -98,7 +96,7 @@ If you need to run tests against all supported Python and Django versions then i
.. code-block:: bash .. code-block:: bash
$ pip install tox $ pip install tox
$ tox $ tox -p all
You can also play with test project by running following commands: You can also play with test project by running following commands:
...@@ -116,4 +114,3 @@ List of projects related to Django, REST and authentication: ...@@ -116,4 +114,3 @@ List of projects related to Django, REST and authentication:
- `django-oauth-toolkit <https://github.com/evonove/django-oauth-toolkit>`_ - `django-oauth-toolkit <https://github.com/evonove/django-oauth-toolkit>`_
- `django-rest-auth <https://github.com/Tivix/django-rest-auth>`_ - `django-rest-auth <https://github.com/Tivix/django-rest-auth>`_
- `django-rest-framework-digestauth <https://github.com/juanriaza/django-rest-framework-digestauth>`_ (not maintained) - `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 Metadata-Version: 1.1
Name: djoser Name: djoser
Version: 1.7.0 Version: 2.0.1
Summary: REST version of Django authentication system. Summary: REST version of Django authentication system.
Home-page: https://github.com/sunscrapers/djoser Home-page: https://github.com/sunscrapers/djoser
Author: SUNSCRAPERS Author: SUNSCRAPERS
...@@ -11,16 +11,17 @@ Description: ====== ...@@ -11,16 +11,17 @@ Description: ======
====== ======
.. image:: https://img.shields.io/pypi/v/djoser.svg .. 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 .. 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 .. 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 .. image:: https://api.codacy.com/project/badge/Grade/c9bf80318d2741e5bb63912a5e0b32dc
:target: https://scrutinizer-ci.com/g/sunscrapers/djoser :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 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/>`_ system. **djoser** library provides a set of `Django Rest Framework <https://www.django-rest-framework.org/>`_
...@@ -42,11 +43,11 @@ Description: ====== ...@@ -42,11 +43,11 @@ Description: ======
To be able to run **djoser** you have to meet following requirements: To be able to run **djoser** you have to meet following requirements:
- Python (2.7, 3.4, 3.5, 3.6) - Python (3.5, 3.6, 3.7, 3.8)
- Django (1.11, 2.0, 2.1, 2.2) - Django (1.11, 2.2)
- Django REST Framework (3.7, 3.8, 3.9) - 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 Installation
============ ============
...@@ -93,11 +94,8 @@ Description: ====== ...@@ -93,11 +94,8 @@ Description: ======
$ pip install django djangorestframework $ pip install django djangorestframework
$ pip install -r requirements.txt $ 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 .. code-block:: bash
$ pip install mock # only on Python 2.7
$ cd testproject $ cd testproject
$ ./manage.py test $ ./manage.py test
...@@ -106,7 +104,7 @@ Description: ====== ...@@ -106,7 +104,7 @@ Description: ======
.. code-block:: bash .. code-block:: bash
$ pip install tox $ pip install tox
$ tox $ tox -p all
You can also play with test project by running following commands: You can also play with test project by running following commands:
...@@ -124,21 +122,17 @@ Description: ====== ...@@ -124,21 +122,17 @@ Description: ======
- `django-oauth-toolkit <https://github.com/evonove/django-oauth-toolkit>`_ - `django-oauth-toolkit <https://github.com/evonove/django-oauth-toolkit>`_
- `django-rest-auth <https://github.com/Tivix/django-rest-auth>`_ - `django-rest-auth <https://github.com/Tivix/django-rest-auth>`_
- `django-rest-framework-digestauth <https://github.com/juanriaza/django-rest-framework-digestauth>`_ (not maintained) - `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 Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable Classifier: Development Status :: 5 - Production/Stable
Classifier: Framework :: Django Classifier: Framework :: Django
Classifier: Framework :: Django :: 1.11 Classifier: Framework :: Django :: 1.11
Classifier: Framework :: Django :: 2.0
Classifier: Framework :: Django :: 2.1
Classifier: Framework :: Django :: 2.2 Classifier: Framework :: Django :: 2.2
Classifier: Intended Audience :: Developers Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python 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.5
Classifier: Programming Language :: Python :: 3.6 Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7 Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
...@@ -19,6 +19,9 @@ djoser.egg-info/SOURCES.txt ...@@ -19,6 +19,9 @@ djoser.egg-info/SOURCES.txt
djoser.egg-info/dependency_links.txt djoser.egg-info/dependency_links.txt
djoser.egg-info/requires.txt djoser.egg-info/requires.txt
djoser.egg-info/top_level.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/__init__.py
djoser/social/serializers.py djoser/social/serializers.py
djoser/social/urls.py djoser/social/urls.py
...@@ -29,7 +32,10 @@ djoser/social/token/__init__.py ...@@ -29,7 +32,10 @@ djoser/social/token/__init__.py
djoser/social/token/jwt.py djoser/social/token/jwt.py
djoser/templates/email/activation.html djoser/templates/email/activation.html
djoser/templates/email/confirmation.html djoser/templates/email/confirmation.html
djoser/templates/email/password_changed_confirmation.html
djoser/templates/email/password_reset.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/__init__.py
djoser/urls/authtoken.py djoser/urls/authtoken.py
djoser/urls/base.py djoser/urls/base.py
......
__version__ = "1.7.0" __version__ = "2.0.1"
from djoser.conf import settings from djoser.conf import settings
__all__ = ['settings'] __all__ = ["settings"]
def get_user_email(user): def get_user_email(user):
......
import warnings
from django.apps import apps from django.apps import apps
from django.conf import settings as django_settings from django.conf import settings as django_settings
from django.core.exceptions import ImproperlyConfigured
from django.test.signals import setting_changed from django.test.signals import setting_changed
from django.utils import six from django.utils import six
from django.utils.functional import LazyObject from django.utils.functional import LazyObject
from django.utils.module_loading import import_string 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) User = apps.get_model(auth_module, user_model)
...@@ -22,7 +19,7 @@ class ObjDict(dict): ...@@ -22,7 +19,7 @@ class ObjDict(dict):
if isinstance(val, str): if isinstance(val, str):
val = import_string(val) val = import_string(val)
elif isinstance(val, (list, tuple)): 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 self[item] = val
except KeyError: except KeyError:
val = super(ObjDict, self).__getattribute__(item) val = super(ObjDict, self).__getattribute__(item)
...@@ -31,87 +28,88 @@ class ObjDict(dict): ...@@ -31,87 +28,88 @@ class ObjDict(dict):
default_settings = { default_settings = {
'LOGIN_FIELD': User.USERNAME_FIELD, "LOGIN_FIELD": User.USERNAME_FIELD,
'SEND_ACTIVATION_EMAIL': False, "SEND_ACTIVATION_EMAIL": False,
'SEND_CONFIRMATION_EMAIL': False, "SEND_CONFIRMATION_EMAIL": False,
'USER_CREATE_PASSWORD_RETYPE': False, "USER_CREATE_PASSWORD_RETYPE": False,
'SET_PASSWORD_RETYPE': False, "SET_PASSWORD_RETYPE": False,
'SET_USERNAME_RETYPE': False, "PASSWORD_RESET_CONFIRM_RETYPE": False,
'PASSWORD_RESET_CONFIRM_RETYPE': False, "SET_USERNAME_RETYPE": False,
'PASSWORD_RESET_SHOW_EMAIL_NOT_FOUND': False, "USERNAME_RESET_CONFIRM_RETYPE": False,
'PASSWORD_VALIDATORS': [], "PASSWORD_RESET_SHOW_EMAIL_NOT_FOUND": False,
'TOKEN_MODEL': 'rest_framework.authtoken.models.Token', "USERNAME_RESET_SHOW_EMAIL_NOT_FOUND": False,
'SERIALIZERS': ObjDict({ "PASSWORD_CHANGED_EMAIL_CONFIRMATION": False,
'activation': "USERNAME_CHANGED_EMAIL_CONFIRMATION": False,
'djoser.serializers.ActivationSerializer', "TOKEN_MODEL": "rest_framework.authtoken.models.Token",
'password_reset': "SERIALIZERS": ObjDict(
'djoser.serializers.PasswordResetSerializer', {
'password_reset_confirm': "activation": "djoser.serializers.ActivationSerializer",
'djoser.serializers.PasswordResetConfirmSerializer', "password_reset": "djoser.serializers.SendEmailResetSerializer",
'password_reset_confirm_retype': "password_reset_confirm": "djoser.serializers.PasswordResetConfirmSerializer",
'djoser.serializers.PasswordResetConfirmRetypeSerializer', "password_reset_confirm_retype": "djoser.serializers.PasswordResetConfirmRetypeSerializer",
'set_password': "set_password": "djoser.serializers.SetPasswordSerializer",
'djoser.serializers.SetPasswordSerializer', "set_password_retype": "djoser.serializers.SetPasswordRetypeSerializer",
'set_password_retype': "set_username": "djoser.serializers.SetUsernameSerializer",
'djoser.serializers.SetPasswordRetypeSerializer', "set_username_retype": "djoser.serializers.SetUsernameRetypeSerializer",
'set_username': "username_reset": "djoser.serializers.SendEmailResetSerializer",
'djoser.serializers.SetUsernameSerializer', "username_reset_confirm": "djoser.serializers.UsernameResetConfirmSerializer",
'set_username_retype': "username_reset_confirm_retype": "djoser.serializers.UsernameResetConfirmRetypeSerializer",
'djoser.serializers.SetUsernameRetypeSerializer', "user_create": "djoser.serializers.UserCreateSerializer",
'user_create': "user_create_password_retype": "djoser.serializers.UserCreatePasswordRetypeSerializer",
'djoser.serializers.UserCreateSerializer', "user_delete": "djoser.serializers.UserDeleteSerializer",
'user_create_password_retype': "user": "djoser.serializers.UserSerializer",
'djoser.serializers.UserCreatePasswordRetypeSerializer', "current_user": "djoser.serializers.UserSerializer",
'user_delete': "token": "djoser.serializers.TokenSerializer",
'djoser.serializers.UserDeleteSerializer', "token_create": "djoser.serializers.TokenCreateSerializer",
'user': }
'djoser.serializers.UserSerializer', ),
'current_user': "EMAIL": ObjDict(
'djoser.serializers.CurrentUserSerializer', {
'token': "activation": "djoser.email.ActivationEmail",
'djoser.serializers.TokenSerializer', "confirmation": "djoser.email.ConfirmationEmail",
'token_create': "password_reset": "djoser.email.PasswordResetEmail",
'djoser.serializers.TokenCreateSerializer', "password_changed_confirmation": "djoser.email.PasswordChangedConfirmationEmail",
}), "username_changed_confirmation": "djoser.email.UsernameChangedConfirmationEmail",
'EMAIL': ObjDict({ "username_reset": "djoser.email.UsernameResetEmail",
'activation': 'djoser.email.ActivationEmail', }
'confirmation': 'djoser.email.ConfirmationEmail', ),
'password_reset': 'djoser.email.PasswordResetEmail', "CONSTANTS": ObjDict({"messages": "djoser.constants.Messages"}),
}), "LOGOUT_ON_PASSWORD_CHANGE": False,
'CONSTANTS': ObjDict({ "CREATE_SESSION_ON_LOGIN": False,
'messages': 'djoser.constants.Messages', "SOCIAL_AUTH_TOKEN_STRATEGY": "djoser.social.token.jwt.TokenStrategy",
}), "SOCIAL_AUTH_ALLOWED_REDIRECT_URIS": [],
'LOGOUT_ON_PASSWORD_CHANGE': False, "HIDE_USERS": True,
'CREATE_SESSION_ON_LOGIN': False, "PERMISSIONS": ObjDict(
'USER_EMAIL_FIELD_NAME': 'email', {
'SOCIAL_AUTH_TOKEN_STRATEGY': 'djoser.social.token.jwt.TokenStrategy', "activation": ["rest_framework.permissions.AllowAny"],
'SOCIAL_AUTH_ALLOWED_REDIRECT_URIS': [], "password_reset": ["rest_framework.permissions.AllowAny"],
'PERMISSIONS': ObjDict({ "password_reset_confirm": ["rest_framework.permissions.AllowAny"],
'activation': ['rest_framework.permissions.AllowAny'], "set_password": ["djoser.permissions.CurrentUserOrAdmin"],
'password_reset': ['rest_framework.permissions.AllowAny'], "username_reset": ["rest_framework.permissions.AllowAny"],
'password_reset_confirm': ['rest_framework.permissions.AllowAny'], "username_reset_confirm": ["rest_framework.permissions.AllowAny"],
'set_password': ['djoser.permissions.CurrentUserOrAdmin'], "set_username": ["djoser.permissions.CurrentUserOrAdmin"],
'set_username': ['rest_framework.permissions.IsAuthenticated'], "user_create": ["rest_framework.permissions.AllowAny"],
'user_create': ['rest_framework.permissions.AllowAny'], "user_delete": ["djoser.permissions.CurrentUserOrAdmin"],
'user_delete': ['djoser.permissions.CurrentUserOrAdmin'], "user": ["djoser.permissions.CurrentUserOrAdmin"],
'user': ['djoser.permissions.CurrentUserOrAdminOrReadOnly'], "user_list": ["djoser.permissions.CurrentUserOrAdmin"],
'user_list': ['djoser.permissions.CurrentUserOrAdminOrReadOnly'], "token_create": ["rest_framework.permissions.AllowAny"],
'token_create': ['rest_framework.permissions.AllowAny'], "token_destroy": ["rest_framework.permissions.IsAuthenticated"],
'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): def __init__(self, default_settings, explicit_overriden_settings=None):
if explicit_overriden_settings is None: if explicit_overriden_settings is None:
explicit_overriden_settings = {} explicit_overriden_settings = {}
overriden_settings = getattr( overriden_settings = (
django_settings, DJOSER_SETTINGS_NAMESPACE, {} getattr(django_settings, DJOSER_SETTINGS_NAMESPACE, {})
) or explicit_overriden_settings or explicit_overriden_settings
)
self._load_default_settings() self._load_default_settings()
self._override_settings(overriden_settings) self._override_settings(overriden_settings)
...@@ -141,30 +139,13 @@ class LazySettings(LazyObject): ...@@ -141,30 +139,13 @@ class LazySettings(LazyObject):
def _setup(self, explicit_overriden_settings=None): def _setup(self, explicit_overriden_settings=None):
self._wrapped = Settings(default_settings, explicit_overriden_settings) 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() settings = LazySettings()
def reload_djoser_settings(*args, **kwargs): def reload_djoser_settings(*args, **kwargs):
global settings global settings
setting, value = kwargs['setting'], kwargs['value'] setting, value = kwargs["setting"], kwargs["value"]
if setting == DJOSER_SETTINGS_NAMESPACE: if setting == DJOSER_SETTINGS_NAMESPACE:
settings._setup(explicit_overriden_settings=value) settings._setup(explicit_overriden_settings=value)
......
...@@ -2,18 +2,13 @@ from django.utils.translation import ugettext_lazy as _ ...@@ -2,18 +2,13 @@ from django.utils.translation import ugettext_lazy as _
class Messages(object): class Messages(object):
INVALID_CREDENTIALS_ERROR = _('Unable to log in with provided credentials.') INVALID_CREDENTIALS_ERROR = _("Unable to log in with provided credentials.")
INACTIVE_ACCOUNT_ERROR = _('User account is disabled.') INACTIVE_ACCOUNT_ERROR = _("User account is disabled.")
INVALID_TOKEN_ERROR = _('Invalid token for given user.') INVALID_TOKEN_ERROR = _("Invalid token for given user.")
INVALID_UID_ERROR = _('Invalid user id or user doesn\'t exist.') INVALID_UID_ERROR = _("Invalid user id or user doesn't exist.")
STALE_TOKEN_ERROR = _('Stale token for given user.') STALE_TOKEN_ERROR = _("Stale token for given user.")
PASSWORD_MISMATCH_ERROR = _('The two password fields didn\'t match.') PASSWORD_MISMATCH_ERROR = _("The two password fields didn't match.")
USERNAME_MISMATCH_ERROR = _('The two {0} fields didn\'t match.') USERNAME_MISMATCH_ERROR = _("The two {0} fields didn't match.")
INVALID_PASSWORD_ERROR = _('Invalid password.') INVALID_PASSWORD_ERROR = _("Invalid password.")
EMAIL_NOT_FOUND = _('User with given email does not exist.') EMAIL_NOT_FOUND = _("User with given email does not exist.")
CANNOT_CREATE_USER_ERROR = _('Unable to create account.') 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.'
)
from django.contrib.auth.tokens import default_token_generator from django.contrib.auth.tokens import default_token_generator
from templated_mail.mail import BaseEmailMessage
from djoser import utils from djoser import utils
from djoser.conf import settings from djoser.conf import settings
from templated_mail.mail import BaseEmailMessage
class ActivationEmail(BaseEmailMessage): class ActivationEmail(BaseEmailMessage):
template_name = 'email/activation.html' template_name = "email/activation.html"
def get_context_data(self): 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') user = context.get("user")
context['uid'] = utils.encode_uid(user.pk) context["uid"] = utils.encode_uid(user.pk)
context['token'] = default_token_generator.make_token(user) context["token"] = default_token_generator.make_token(user)
context['url'] = settings.ACTIVATION_URL.format(**context) context["url"] = settings.ACTIVATION_URL.format(**context)
return context return context
class ConfirmationEmail(BaseEmailMessage): class ConfirmationEmail(BaseEmailMessage):
template_name = 'email/confirmation.html' template_name = "email/confirmation.html"
class PasswordResetEmail(BaseEmailMessage): 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): def get_context_data(self):
context = super(PasswordResetEmail, self).get_context_data() context = super().get_context_data()
user = context.get('user') user = context.get("user")
context['uid'] = utils.encode_uid(user.pk) context["uid"] = utils.encode_uid(user.pk)