django-unique-user-email
Enable login-by-email with the default User model for your Django project by making auth.User.email unique.
A quick note on why?
Django's leaky battery is its recommendation that you create a custom user model. Auth is so central and so standard that, into the high-nines (99.99%?), the vast majority of projects should never need to customise the central auth model. This is a battery that Django should very much provide.
There's a complexity tax from exposing the auth model. There's a performance tax as the auth model becomes a generic dumping ground for User related data that has nothing to do with authentication. There's a learning tax as users hit the custom user model, and the (frankly, misplaced) warnings about it's importance.
Again, the vast majority of projects should never need to customise the central auth model.
Can I login with my email?
Most projects, all folks wanted was login-by-email.
By making the default auth.User model have unique email field, and a few other bits and bobs, this is enabled.
The goal of this package is to give you the tools you need for login-by-email with Django's default User model. I believe this should be a option in Django itself, so it's a proof-of-concept for a future discussion there too.
A longer discussion, Coming Soon. Until then I did a blog post that says a little more.
Overview
-
Install from
pip:pip install django-unique-user-email -
Add to
INSTALLED_APPSINSTALLED_APPS = [ "django.contrib.admin", "django.contrib.auth", "django.contrib.contenttypes", "django.contrib.sessions", "django.contrib.messages", "django.contrib.staticfiles", "unique_user_email", ... ] -
Migrate to add the unique constraint to
User.email. -
Install auth backend to allow email login
AUTHENTICATION_BACKENDS = [ 'unique_user_email.backend.EmailBackend', 'django.contrib.auth.backends.ModelBackend', ] -
Use the custom
AuthenticationFormto login withusernameoremail.# urls.py from django.contrib.auth.views import LoginView from unique_user_email.forms import AuthenticationForm urlpatterns = [ # Route LoginView before other auth views to match first. # https://docs.djangoproject.com/en/dev/topics/auth/default/#module-django.contrib.auth.views path( "accounts/login/", LoginView.as_view(form_class=AuthenticationForm), name="login", ), ... ]
Fuller tutorial, Coming Soon.
Testing
-
Clone the repo, create a virtual environment, and
pip install -e .the package. -
You can run with
just test.This wraps the full command:
django-admin test --settings=tests.settings --pythonpath=.
Metadata
Release files for django-unique-user-email 23.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-unique-user-email-23.2.tar.gz | 10.0 kB | Without provenance | Details for django-unique-user-email-23.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_unique_user_email-23.2-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for django_unique_user_email-23.2-py2.py3-none-any.whl |
Total release size: 16.5 kB
Release files / django-unique-user-email-23.2.tar.gz
| Download URL | django-unique-user-email-23.2.tar.gz |
|---|---|
| Size | 10.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1da83203fcecedcf57da8542fa67ce24ff89f6b16be082448da836e61be69d05
|
|
BLAKE2b-256 checksum How to use checksums |
45d6f58c29f99628b2f3af6129406a31b09185a46fa87e25086d95e371e3deeb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.28.1
|
Release files / django_unique_user_email-23.2-py2.py3-none-any.whl
| Download URL | django_unique_user_email-23.2-py2.py3-none-any.whl |
|---|---|
| Size | 6.5 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
cf613006ef0112f4952eebccc3d8e1df1583abac90550eb20abd02d8834e6219
|
|
BLAKE2b-256 checksum How to use checksums |
3efc7256e1385d2ce944c87424493394e3884d5660d99fa825fdce3bfb543fdb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.28.1
|
Security for django-unique-user-email 23.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.