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
......@@ -4,12 +4,11 @@ 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 rest_framework.exceptions import ValidationError
from djoser import utils
from djoser.compat import get_user_email, get_user_email_field_name
from djoser.conf import settings
from rest_framework import exceptions, serializers
from rest_framework.exceptions import ValidationError
User = get_user_model()
......@@ -29,54 +28,36 @@ class UserSerializer(serializers.ModelSerializer):
instance_email = get_user_email(instance)
if instance_email != validated_data[email_field]:
instance.is_active = False
instance.save(update_fields=['is_active'])
return super(UserSerializer, self).update(instance, validated_data)
class CurrentUserSerializer(UserSerializer):
def __init__(self, *args, **kwargs):
# Warn user about serializer split
warnings.simplefilter('default')
warnings.warn(
(
'Current user endpoints now use their own serializer setting. '
'For more information, see: '
'https://djoser.readthedocs.io/en/latest/settings.html#serializers' # noqa
),
DeprecationWarning,
)
# Perform regular init actions
super(CurrentUserSerializer, self).__init__(*args, **kwargs)
instance.save(update_fields=["is_active"])
return super().update(instance, validated_data)
class UserCreateSerializer(serializers.ModelSerializer):
password = serializers.CharField(
style={'input_type': 'password'},
write_only=True
)
password = serializers.CharField(style={"input_type": "password"}, write_only=True)
default_error_messages = {
'cannot_create_user': settings.CONSTANTS.messages.CANNOT_CREATE_USER_ERROR,
"cannot_create_user": settings.CONSTANTS.messages.CANNOT_CREATE_USER_ERROR
}
class Meta:
model = User
fields = tuple(User.REQUIRED_FIELDS) + (
settings.LOGIN_FIELD, User._meta.pk.name, 'password',
settings.LOGIN_FIELD,
User._meta.pk.name,
"password",
)
def validate(self, attrs):
user = User(**attrs)
password = attrs.get('password')
password = attrs.get("password")
try:
validate_password(password, user)
except django_exceptions.ValidationError as e:
serializer_error = serializers.as_serializer_error(e)
raise serializers.ValidationError({
'password': serializer_error['non_field_errors']
})
raise serializers.ValidationError(
{"password": serializer_error["non_field_errors"]}
)
return attrs
......@@ -84,7 +65,7 @@ class UserCreateSerializer(serializers.ModelSerializer):
try:
user = self.perform_create(validated_data)
except IntegrityError:
self.fail('cannot_create_user')
self.fail("cannot_create_user")
return user
......@@ -93,77 +74,82 @@ class UserCreateSerializer(serializers.ModelSerializer):
user = User.objects.create_user(**validated_data)
if settings.SEND_ACTIVATION_EMAIL:
user.is_active = False
user.save(update_fields=['is_active'])
user.save(update_fields=["is_active"])
return user
class UserCreatePasswordRetypeSerializer(UserCreateSerializer):
default_error_messages = {
'password_mismatch': settings.CONSTANTS.messages.PASSWORD_MISMATCH_ERROR,
"password_mismatch": settings.CONSTANTS.messages.PASSWORD_MISMATCH_ERROR
}
def __init__(self, *args, **kwargs):
super(UserCreatePasswordRetypeSerializer, self).__init__(*args, **kwargs)
self.fields['re_password'] = serializers.CharField(style={'input_type': 'password'})
super().__init__(*args, **kwargs)
self.fields["re_password"] = serializers.CharField(
style={"input_type": "password"}
)
def validate(self, attrs):
re_password = attrs.pop('re_password')
attrs = super(UserCreatePasswordRetypeSerializer, self).validate(attrs)
if attrs['password'] == re_password:
self.fields.pop("re_password", None)
re_password = attrs.pop("re_password")
attrs = super().validate(attrs)
if attrs["password"] == re_password:
return attrs
else:
self.fail('password_mismatch')
self.fail("password_mismatch")
class TokenCreateSerializer(serializers.Serializer):
password = serializers.CharField(
required=False, style={'input_type': 'password'}
)
password = serializers.CharField(required=False, style={"input_type": "password"})