{ "info": { "author": "Christian Kreuzberger", "author_email": "ckreuzberger@anexia-it.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Environment :: Web Environment", "Framework :: Django", "Framework :: Django :: 1.11", "Framework :: Django :: 2.0", "Framework :: Django :: 2.1", "Framework :: Django :: 2.2", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Topic :: Internet :: WWW/HTTP", "Topic :: Internet :: WWW/HTTP :: Dynamic Content" ], "description": "# Django Rest Password Reset\n\n[![PyPI version](https://badge.fury.io/py/django-rest-passwordreset.svg)](https://badge.fury.io/py/django-rest-passwordreset)\n[![Build Status](https://travis-ci.org/anx-ckreuzberger/django-rest-passwordreset.svg?branch=master)](https://travis-ci.org/anx-ckreuzberger/django-rest-passwordreset)\n\nThis python package provides a simple password reset strategy for django rest framework, where users can request password \nreset tokens via their registered e-mail address.\n\nThe main idea behind this package is to not make any assumptions about how the token is delivered to the end-user (e-mail, text-message, etc...).\nInstead, this package provides a signal that can be reacted on (e.g., by sending an e-mail or a text message).\n\nThis package basically provides two REST endpoints:\n\n* Request a token\n* Verify (confirm) a token (and change the password)\n\n## Quickstart\n\n1. Install the package from pypi using pip:\n```bash\npip install django-rest-passwordreset\n```\n\n2. Add ``django_rest_passwordreset`` to your ``INSTALLED_APPS`` (after ``rest_framework``) within your Django settings file:\n```python\nINSTALLED_APPS = (\n ...\n 'django.contrib.auth',\n ...\n 'rest_framework',\n ...\n 'django_rest_passwordreset',\n ...\n)\n```\n\n3. This package provides two endpoints, which can be included by including ``django_rest_passwordreset.urls`` in your ``urls.py`` as follows:\n```python\nfrom django.conf.urls import url, include\n\n\nurlpatterns = [\n ...\n url(r'^api/password_reset/', include('django_rest_passwordreset.urls', namespace='password_reset')),\n ...\n] \n```\n**Note**: You can adapt the url to your needs.\n\n### Endpoints\n\nThe following endpoints are provided:\n\n * `POST ${API_URL}/reset_password/` - request a reset password token by using the ``email`` parameter\n * `POST ${API_URL}/reset_password/confirm/` - using a valid ``token``, the users password is set to the provided ``password``\n \nwhere `${API_URL}/` is the url specified in your *urls.py* (e.g., `api/password_reset/`)\n \n\n### Configuration / Settings\n\nThe following settings can be set in Djangos ``settings.py`` file:\n\n* `DJANGO_REST_MULTITOKENAUTH_RESET_TOKEN_EXPIRY_TIME` - time in hours about how long the token is active (Default: 24)\n\n **Please note**: expired tokens are automatically cleared based on this setting in every call of ``ResetPasswordRequestToken.post``.\n \n### Signals\n\n* ``reset_password_token_created(sender, instance, reset_password_token)`` Fired when a reset password token is generated\n* ``pre_password_reset(user)`` - fired just before a password is being reset\n* ``post_password_reset(user)`` - fired after a password has been reset\n\n### Example for sending an e-mail\n\n1. Create two new django templates: `email/user_reset_password.html` and `email/user_reset_password.txt`. Those templates will contain the e-mail message sent to the user, aswell as the password reset link (or token).\nWithin the templates, you can access the following context variables: `current_user`, `username`, `email`, `reset_password_url`. Feel free to adapt this to your needs.\n\n2. Add the following code, which contains a Django Signal, to your application (see [this part of the django documentation](https://docs.djangoproject.com/en/1.11/topics/signals/#connecting-receiver-functions) for more information on where to put signals).\n```python\nfrom django.core.mail import EmailMultiAlternatives\nfrom django.dispatch import receiver\nfrom django.template.loader import render_to_string\nfrom django.urls import reverse\n\nfrom django_rest_passwordreset.signals import reset_password_token_created\n\n\n@receiver(reset_password_token_created)\ndef password_reset_token_created(sender, instance, reset_password_token, *args, **kwargs):\n \"\"\"\n Handles password reset tokens\n When a token is created, an e-mail needs to be sent to the user\n :param sender: View Class that sent the signal\n :param instance: View Instance that sent the signal\n :param reset_password_token: Token Model Object\n :param args:\n :param kwargs:\n :return:\n \"\"\"\n # send an e-mail to the user\n context = {\n 'current_user': reset_password_token.user,\n 'username': reset_password_token.user.username,\n 'email': reset_password_token.user.email,\n 'reset_password_url': \"{}?token={}\".format(reverse('password_reset:reset-password-request'), reset_password_token.key)\n }\n\n # render email text\n email_html_message = render_to_string('email/user_reset_password.html', context)\n email_plaintext_message = render_to_string('email/user_reset_password.txt', context)\n\n msg = EmailMultiAlternatives(\n # title:\n \"Password Reset for {title}\".format(title=\"Some website title\"),\n # message:\n email_plaintext_message,\n # from:\n \"noreply@somehost.local\",\n # to:\n [reset_password_token.user.email]\n )\n msg.attach_alternative(email_html_message, \"text/html\")\n msg.send()\n\n```\n\n3. You should now be able to use the endpoints to request a password reset token via your e-mail address. \nIf you want to test this locally, I recommend using some kind of fake mailserver (such as maildump).\n\n\n## Custom Token Generator\n\nBy default, a random string token of length 10 to 50 is generated using the ``RandomStringTokenGenerator`` class.\nThis library offers a possibility to configure the params of ``RandomStringTokenGenerator`` as well as switch to\nanother token generator, e.g. ``RandomNumberTokenGenerator``. You can also generate your own token generator class.\n\nYou can change that by adding \n```python\nDJANGO_REST_PASSWORDRESET_TOKEN_CONFIG = {\n \"CLASS\": ...,\n \"OPTIONS\": {...}\n}\n```\ninto Django settings.py file.\n\n\n### RandomStringTokenGenerator\nThis is the default configuration. \n```python\nDJANGO_REST_PASSWORDRESET_TOKEN_CONFIG = {\n \"CLASS\": \"django_rest_passwordreset.tokens.RandomStringTokenGenerator\"\n}\n```\n\nYou can configure the length as follows:\n```python\nDJANGO_REST_PASSWORDRESET_TOKEN_CONFIG = {\n \"CLASS\": \"django_rest_passwordreset.tokens.RandomStringTokenGenerator\",\n \"OPTIONS\": {\n \"min_length\": 20,\n \"max_lenght\": 30\n }\n}\n```\n \n\n### RandomNumberTokenGenerator\n```python\nDJANGO_REST_PASSWORDRESET_TOKEN_CONFIG = {\n \"CLASS\": \"django_rest_passwordreset.tokens.RandomNumberTokenGenerator\"\n}\n```\n\nYou can configure the minimum and maximum number as follows:\n```python\nDJANGO_REST_PASSWORDRESET_TOKEN_CONFIG = {\n \"CLASS\": \"django_rest_passwordreset.tokens.RandomNumberTokenGenerator\",\n \"OPTIONS\": {\n \"min_number\": 1500,\n \"max_number\": 9999\n }\n}\n```\n\n\n### Write your own Token Generator\n\nPlease see [token_configuration/django_rest_passwordreset/tokens.py](token_configuration/django_rest_passwordreset/tokens.py) for example implementation of number and string token generator.\n\nThe basic idea is to create a new class that inherits from BaseTokenGenerator, takes arbitrary arguments (`args` and `kwargs`)\nin the ``__init__`` function as well as implementing a `generate_token` function.\n\n```python\nfrom django_rest_passwordreset.tokens import BaseTokenGenerator\n\n\nclass RandomStringTokenGenerator(BaseTokenGenerator):\n \"\"\"\n Generates a random string with min and max length using os.urandom and binascii.hexlify\n \"\"\"\n\n def __init__(self, min_length=10, max_length=50, *args, **kwargs):\n self.min_length = min_length\n self.max_length = max_length\n\n def generate_token(self, *args, **kwargs):\n \"\"\" generates a pseudo random code using os.urandom and binascii.hexlify \"\"\"\n # determine the length based on min_length and max_length\n length = random.randint(self.min_length, self.max_length)\n\n # generate the token using os.urandom and hexlify\n return binascii.hexlify(\n os.urandom(self.max_length)\n ).decode()[0:length]\n```\n\n\n## Compatibility Matrix\n\nThis library should be compatible with the latest Django and Django Rest Framework Versions. For reference, here is\na matrix showing the guaranteed and tested compatibility.\n\ndjango-rest-passwordreset Version | Django Versions | Django Rest Framework Versions\n--------------------------------- | ----------------| ------------------------------\n0.9.7 | 1.8, 1.11, 2.0, 2.1 | 3.6 - 3.9\n1.0 (WIP) | 1.11, 2.0, 2.2 | 3.6 - 3.9\n\n## Documentation / Browsable API\n\nThis package supports the [DRF auto-generated documentation](https://www.django-rest-framework.org/topics/documenting-your-api/) (via `coreapi`) as well as the [DRF browsable API](https://www.django-rest-framework.org/topics/browsable-api/).\n\n![drf_browsable_email_validation](docs/browsable_api_email_validation.png \"Browsable API E-Mail Validation\")\n\n![drf_browsable_password_validation](docs/browsable_api_password_validation.png \"Browsable API E-Mail Validation\")\n\n![coreapi_docs](docs/coreapi_docs.png \"Core API Docs\")\n\n\n## Known Issues\n\n### Django 2.1 Migrations - Multiple Primary keys for table ...\nDjango 2.1 introduced a breaking change for migrations (see [Django Issue #29790](https://code.djangoproject.com/ticket/29790)). We therefore had to rewrite the migration [0002_pk_migration.py](django_rest_passwordreset/migrations/0002_pk_migration.py) such that it covers Django versions before (`<`) 2.1 and later (`>=`) 2.1.\n\nSome information is written down in Issue #8.\n\n## Contributions\n\nThis library tries to follow the unix philosophy of \"do one thing and do it well\" (which is providing a basic password reset endpoint for Django Rest Framework). Contributions are welcome in the form of pull requests and issues! If you create a pull request, please make sure that you are not introducing breaking changes. \n\n## Tests\n\nSee folder [tests/](tests/). Basically, all endpoints are covered with multiple\nunit tests.\n\nUse this code snippet to run tests:\n```bash\npip install -r requirements_test.txt\npython setup.py install\ncd tests\npython manage.py test\n```\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/anx-ckreuzberger/django-rest-passwordreset", "keywords": "", "license": "BSD License", "maintainer": "", "maintainer_email": "", "name": "django-rest-passwordreset", "package_url": "https://pypi.org/project/django-rest-passwordreset/", "platform": "", "project_url": "https://pypi.org/project/django-rest-passwordreset/", "project_urls": { "Homepage": "https://github.com/anx-ckreuzberger/django-rest-passwordreset" }, "release_url": "https://pypi.org/project/django-rest-passwordreset/1.0.0/", "requires_dist": null, "requires_python": "", "summary": "An extension of django rest framework, providing a configurable password reset strategy", "version": "1.0.0" }, "last_serial": 5653702, "releases": { "0.9.0": [ { "comment_text": "", "digests": { "md5": "88a203534ab76d7bdb2076598e54c5ca", "sha256": "52ff86fa214a4a0967631067cd32f805c2f6f8fe692c144b8374e327009293e6" }, "downloads": -1, "filename": "django-rest-passwordreset-0.9.0.tar.gz", "has_sig": false, "md5_digest": "88a203534ab76d7bdb2076598e54c5ca", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9795, "upload_time": "2017-08-10T05:41:26", "url": "https://files.pythonhosted.org/packages/70/1c/c004943e76918c276c964581f93181334a789ec82d149e8315a3a0cdf694/django-rest-passwordreset-0.9.0.tar.gz" } ], "0.9.1": [ { "comment_text": "", "digests": { "md5": "856c9788517aecd51ddc656b46348d39", "sha256": "eb7146dca4272fc2a769fd6ad9f6f6d3779818fb362794ed51f4eb48a75adfaf" }, "downloads": -1, "filename": "django-rest-passwordreset-0.9.1.tar.gz", "has_sig": false, "md5_digest": "856c9788517aecd51ddc656b46348d39", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9817, "upload_time": "2017-08-10T05:43:56", "url": "https://files.pythonhosted.org/packages/e6/fa/ba520f7a19b1bd092a5e17d0fe0f291907908a25f64998871e0ef86ebd78/django-rest-passwordreset-0.9.1.tar.gz" } ], "0.9.3": [ { "comment_text": "", "digests": { "md5": "4c4c989e5d5f3f893cac9444e3019d51", "sha256": "d7d00048040327f97cffd10e0a90573f0d4f4ba182437ba7367585a6d46ecb09" }, "downloads": -1, "filename": "django-rest-passwordreset-0.9.3.tar.gz", "has_sig": false, "md5_digest": "4c4c989e5d5f3f893cac9444e3019d51", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9899, "upload_time": "2018-05-08T15:00:56", "url": "https://files.pythonhosted.org/packages/fc/90/fc7b27ae2de0f75dfaeb5d2c8bede3b68625930be653ca108e226b625369/django-rest-passwordreset-0.9.3.tar.gz" } ], "0.9.4": [ { "comment_text": "", "digests": { "md5": "e18dd782c97f8797bfabeab99578c112", "sha256": "cb917af9d7054b2d46353ca5970b13884ac52dd0451a40630ce300042e186f8c" }, "downloads": -1, "filename": "django-rest-passwordreset-0.9.4.tar.gz", "has_sig": false, "md5_digest": "e18dd782c97f8797bfabeab99578c112", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9920, "upload_time": "2018-06-08T13:03:31", "url": "https://files.pythonhosted.org/packages/d9/82/1a20c167d3f99a1a07716c8499572948b1fe10c5dd176a17ba7703b15189/django-rest-passwordreset-0.9.4.tar.gz" } ], "0.9.5": [ { "comment_text": "", "digests": { "md5": "c6cac251417b0860676154684b761677", "sha256": "9671c5a63701a9d10bd1ac314ca8dc988194590672787fc9b6cf5b83fdc487c0" }, "downloads": -1, "filename": "django-rest-passwordreset-0.9.5.tar.gz", "has_sig": false, "md5_digest": "c6cac251417b0860676154684b761677", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13222, "upload_time": "2018-08-27T07:20:40", "url": "https://files.pythonhosted.org/packages/a6/7d/0be489a69e8b5e91fb9326af0ad19958e800c332db6512c417a7bacb7d77/django-rest-passwordreset-0.9.5.tar.gz" } ], "0.9.6": [ { "comment_text": "", "digests": { "md5": "10c4e610ae364e2d92c320bbdf0b29d8", "sha256": "ebfea9c2a108cf1acdac02ef42bba9ddb09458e31e621452b1ab57016d39e7db" }, "downloads": -1, "filename": "django-rest-passwordreset-0.9.6.tar.gz", "has_sig": false, "md5_digest": "10c4e610ae364e2d92c320bbdf0b29d8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13193, "upload_time": "2018-10-16T15:00:36", "url": "https://files.pythonhosted.org/packages/f8/64/62745c76f6e5028136b03799d1d22b2e6856da825ef4e5c569fa7b0502f9/django-rest-passwordreset-0.9.6.tar.gz" } ], "0.9.7": [ { "comment_text": "", "digests": { "md5": "6e433e7ae4942c4965026379fa2f8802", "sha256": "dabbceab96a0b2424e91e95ae453f2dd1f28aee297846b74cc544c0bed566bd5" }, "downloads": -1, "filename": "django-rest-passwordreset-0.9.7.tar.gz", "has_sig": false, "md5_digest": "6e433e7ae4942c4965026379fa2f8802", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14167, "upload_time": "2018-10-17T06:34:37", "url": "https://files.pythonhosted.org/packages/25/80/e0aef1953f920af2a88aea374efd7057199da5b6b05cda96695cd2117f2d/django-rest-passwordreset-0.9.7.tar.gz" } ], "1.0.0": [ { "comment_text": "", "digests": { "md5": "d6d77c9e730096f4d1d679735a3fc74c", "sha256": "abd27349cd5702d3704f87412a2cd51630b5da95a3ffde01f123e586d7d46b5a" }, "downloads": -1, "filename": "django-rest-passwordreset-1.0.0.tar.gz", "has_sig": false, "md5_digest": "d6d77c9e730096f4d1d679735a3fc74c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 200303, "upload_time": "2019-04-15T07:13:24", "url": "https://files.pythonhosted.org/packages/34/f5/8bf32378a9183bbef9f195d4c4fb2a4ce97b2e56b1f88214434a2036bb64/django-rest-passwordreset-1.0.0.tar.gz" } ], "1.0.0a1": [ { "comment_text": "", "digests": { "md5": "e9ae5b163e799a807ef85b9d36728d80", "sha256": "0431c8fee320d9266af6ecc1a77042a8eabafb4e6c879197d553f4976bd351f4" }, "downloads": -1, "filename": "django-rest-passwordreset-1.0.0a1.tar.gz", "has_sig": false, "md5_digest": "e9ae5b163e799a807ef85b9d36728d80", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 200066, "upload_time": "2019-02-18T16:16:52", "url": "https://files.pythonhosted.org/packages/b3/c1/d9120cc9e30bf2948fe5a7f5f3ec25efa0ba4c4c86bfb9f1471906ed7c0c/django-rest-passwordreset-1.0.0a1.tar.gz" } ], "1.0.0a2": [ { "comment_text": "", "digests": { "md5": "7526b97a27c539b37198a9aa9f4917a6", "sha256": "c1ffe212d2eb35968e5221044d833e6ec4aea1fadc81c4125ce2b126cc83dc0b" }, "downloads": -1, "filename": "django-rest-passwordreset-1.0.0a2.tar.gz", "has_sig": false, "md5_digest": "7526b97a27c539b37198a9aa9f4917a6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 200236, "upload_time": "2019-03-25T06:55:11", "url": "https://files.pythonhosted.org/packages/f5/be/b0393a401a1684190cb0ed568d1913ea98082d50b8955c6c04292046b763/django-rest-passwordreset-1.0.0a2.tar.gz" } ], "1.0.0a3": [ { "comment_text": "", "digests": { "md5": "5e32fdbe363755eb29dffbacbcdce8f2", "sha256": "e53ccd45ddeb6d5dee1d9db7d304cc9055ace26f3de945e9589e89c416b563a1" }, "downloads": -1, "filename": "django-rest-passwordreset-1.0.0a3.tar.gz", "has_sig": false, "md5_digest": "5e32fdbe363755eb29dffbacbcdce8f2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 200256, "upload_time": "2019-03-28T13:14:33", "url": "https://files.pythonhosted.org/packages/2b/d9/e4d8fdd479ec64f917599333fd6836e46145c2e5e82d27c9d36f33b9ba27/django-rest-passwordreset-1.0.0a3.tar.gz" } ], "1.1.0rc1": [ { "comment_text": "", "digests": { "md5": "ac1676802446d22c3e7a4998fedf6202", "sha256": "4a0d745ff7a668dc01219d7b38c2fc234dbb039630fead62d7fcc48241842ee6" }, "downloads": -1, "filename": "django-rest-passwordreset-1.1.0rc1.tar.gz", "has_sig": false, "md5_digest": "ac1676802446d22c3e7a4998fedf6202", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 201794, "upload_time": "2019-05-28T06:03:38", "url": "https://files.pythonhosted.org/packages/db/be/e047a687825cee889d9cdbf50bf7315444f84c78d0a3bffde1cf61445b90/django-rest-passwordreset-1.1.0rc1.tar.gz" } ], "1.1.0rc2": [ { "comment_text": "", "digests": { "md5": "4209bccc8d1026f70a690ddad0cdce4b", "sha256": "0edb7ab5c73704ecfe7f8d8e02fccfc25e23675ec020a8c7e3c1cd7892744e00" }, "downloads": -1, "filename": "django_rest_passwordreset-1.1.0rc2-py3.6.egg", "has_sig": false, "md5_digest": "4209bccc8d1026f70a690ddad0cdce4b", "packagetype": "bdist_egg", "python_version": "3.6", "requires_python": null, "size": 43634, "upload_time": "2019-08-09T05:56:20", "url": "https://files.pythonhosted.org/packages/25/52/39037835d180d0a5f743d37bde3b1130707c1a61aaa3370c5c76b3512faf/django_rest_passwordreset-1.1.0rc2-py3.6.egg" }, { "comment_text": "", "digests": { "md5": "0aa9845597299d071ecaa2d681d601e4", "sha256": "b06b6c42b39b5f85ffc4450b947a1d3ce30a6c3b35269aad047e6435e3f03474" }, "downloads": -1, "filename": "django-rest-passwordreset-1.1.0rc2.tar.gz", "has_sig": false, "md5_digest": "0aa9845597299d071ecaa2d681d601e4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 202692, "upload_time": "2019-07-31T14:02:02", "url": "https://files.pythonhosted.org/packages/05/93/03a242b0bf54be9c3f6823836446444454842f9d556f7809c12c5f3f8199/django-rest-passwordreset-1.1.0rc2.tar.gz" } ], "1.1.0rc3": [ { "comment_text": "", "digests": { "md5": "ab21fe3aee37eab13e46e7544990b6b6", "sha256": "fbf6d326a14c2080a9f44b70aaad780cd9d82489cef50d4dd7d7c32f5617bb03" }, "downloads": -1, "filename": "django-rest-passwordreset-1.1.0rc3.tar.gz", "has_sig": false, "md5_digest": "ab21fe3aee37eab13e46e7544990b6b6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 204242, "upload_time": "2019-08-09T05:56:24", "url": "https://files.pythonhosted.org/packages/ac/fa/d6f265e4b77e59c747d858b86c4bad3a5a28c03ec5314e38c44ce8855b15/django-rest-passwordreset-1.1.0rc3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "d6d77c9e730096f4d1d679735a3fc74c", "sha256": "abd27349cd5702d3704f87412a2cd51630b5da95a3ffde01f123e586d7d46b5a" }, "downloads": -1, "filename": "django-rest-passwordreset-1.0.0.tar.gz", "has_sig": false, "md5_digest": "d6d77c9e730096f4d1d679735a3fc74c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 200303, "upload_time": "2019-04-15T07:13:24", "url": "https://files.pythonhosted.org/packages/34/f5/8bf32378a9183bbef9f195d4c4fb2a4ce97b2e56b1f88214434a2036bb64/django-rest-passwordreset-1.0.0.tar.gz" } ] }