|
| 1 | +================ |
| 2 | +Django Mail Auth |
| 3 | +================ |
| 4 | + |
| 5 | +|version| |ci| |coverage| |license| |
| 6 | + |
| 7 | +.. figure:: sample.png |
| 8 | + :width: 425 |
| 9 | + :alt: screenshot from a login form |
| 10 | + |
| 11 | +Django Mail Auth is a lightweight authentication backend for Django, |
| 12 | +that does not require users to remember passwords. |
| 13 | + |
| 14 | +Django Mail Auth features: |
| 15 | + |
| 16 | +- custom user model support |
| 17 | +- drop in Django admin support |
| 18 | +- drop in Django User replacement |
| 19 | +- extendable SMS support |
| 20 | + |
| 21 | +This project was originally inspired by `Is it time for password-less login?`__ by `Ben Brown`_. |
| 22 | + |
| 23 | +__ http://notes.xoxco.com/post/27999787765/is-it-time-for-password-less-login |
| 24 | +.. _`Ben Brown`: http://twitter.com/benbrown |
| 25 | + |
| 26 | +Installation |
| 27 | +------------ |
| 28 | + |
| 29 | +Run this command to install ``django-mail-auth``:: |
| 30 | + |
| 31 | + pip install django-mail-auth |
| 32 | + |
| 33 | + |
| 34 | +Setup |
| 35 | +----- |
| 36 | + |
| 37 | +First add `mailauth` to you installed apps:: |
| 38 | + |
| 39 | + INSTALLED_APPS = [ |
| 40 | + # Django's builtin apps… |
| 41 | + |
| 42 | + 'mailauth', |
| 43 | + 'mailauth.contrib.admin', # optional |
| 44 | + 'mailauth.contrib.auth', # optional |
| 45 | + |
| 46 | + # other apps… |
| 47 | + ] |
| 48 | + |
| 49 | +`mailauth.contrib.admin` is optional and will replace the admin's login |
| 50 | +with token based authentication too. |
| 51 | + |
| 52 | +`mailauth.contrib.auth` is optional and provides a new Django User model. |
| 53 | +The new User model needs to be enabled via the ``AUTH_USER_MODEL`` setting:: |
| 54 | + |
| 55 | + AUTH_USER_MODEL = 'mailauth.EmailUser' |
| 56 | + |
| 57 | +Next you will need to add the new authentication backend:: |
| 58 | + |
| 59 | + AUTHENTICATION_BACKENDS = ( |
| 60 | + # default, but now optional |
| 61 | + # This should be removed if |
| 62 | + 'django.contrib.auth.backends.ModelBackend', |
| 63 | + |
| 64 | + # The new access token based authentication backend |
| 65 | + 'mailauth.backends.MailAuthBackend', |
| 66 | + ) |
| 67 | + |
| 68 | +Django's `ModelBackend` is only only needed, if you still want to support |
| 69 | +password based authentication. If you don't, simply remove it from the list. |
| 70 | + |
| 71 | +Last but not least, go to your URL root config `urls.py` and add the following:: |
| 72 | + |
| 73 | + from django.urls import path |
| 74 | + |
| 75 | + |
| 76 | + urlpatterns = [ |
| 77 | + path('accounts/', include('mailauth.urls')), |
| 78 | + ] |
| 79 | + |
| 80 | +That's it! |
| 81 | + |
| 82 | +.. note:: Don't forget to setup you Email backend! |
| 83 | + |
| 84 | +.. |version| image:: https://img.shields.io/pypi/v/django-mail-auth.svg |
| 85 | + :target: https://pypi.python.org/pypi/django-mail-auth/ |
| 86 | +.. |ci| image:: https://travis-ci.com/codingjoe/django-mail-auth.svg?branch=master |
| 87 | + :target: https://travis-ci.com/codingjoe/django-mail-auth |
| 88 | +.. |coverage| image:: https://codecov.io/gh/codingjoe/django-mail-auth/branch/master/graph/badge.svg |
| 89 | + :target: https://codecov.io/gh/codingjoe/django-mail-auth |
| 90 | +.. |license| image:: https://img.shields.io/badge/license-APL2-blue.svg |
| 91 | + :target: LICENSE |
0 commit comments