django-email-login /

Filename Size Date modified Message
email_login
example
30 B
3.8 KB
372 B

django-email-login

Goals

The goal of this app is to easily transform django's auth system to allow login with an email address, instead of a username. This should work inside the admin as well as outside. Therefore, email addresses need to be unique.

The username of the User will be the hash of its email adress. As it means nothing, it will be hidden in the admin changelist view.

No registration or confirmation email is sent when the user signs up.

All default Django auth views are provided for you, with templates. There are HAML templates if you like. Some of the code is based upon instructions by Peyman <http://peyman-django.blogspot.com/>.

Usage

  1. Append 'email_login' to your INSTALLED_APPS setting

  2. Insert 'email_login.auth_backend.EmailBackend' as first in the AUTHENTICATION_BACKENDS settings tuple.

  3. Configure your email settings, for password reset:

    EMAIL_HOST = 'smtp.gmail.com'
    EMAIL_PORT = "587"
    EMAIL_HOST_USER = '<your email address>'
    EMAIL_HOST_PASSWORD = '<your email password>'
    EMAIL_USE_TLS = True
    
  4. Configure your settings site domain in the admin panel, so that it does not appear as example.com when password reset emails are sent.

  5. Add the following in your root urls.py after admin.autodiscover():

    # Insert email_login overrides
    from email_login import useradmin, adminsite
    site = adminsite.EmailLoginAdminSite()
    # duplicate the normal admin's registry until ticket #8500 get's fixed
    site._registry = admin.site._registry
    
  6. Instead of using:

    # Uncomment the next line to enable the admin:
    (r'^admin/', include(admin.site.urls)),
    

    use:

    # Uncomment the next line to enable the admin:
    (r'^admin/', include(site.urls)),
    

    to include the admin in your root urls.py.

  7. If you DON'T want to use our templates and signup code without registration or confirmation email, comment out this line in email_login/urls.py:

    urlpatterns += our_auth_urls
    
  8. Alternately, if you want default Django auth views and templates, uncomment this line in email_login/urls.py:

    #urlpatterns += auth_urls
    
  9. To use login outside of the admin, add:

    (r'^account/', include('email_login.urls')),
    

    to your urls.py

Note

Your admin account needs to have an email address, otherwise you won't be able to sign in!

Note

The admin will display the username in the top right corner of the logged in user if the user has no firstname. If you want to override that, over- ride the admin/base.html template.

In conjunction with django-user-creation

(NOTE: I haven't tried the following, and my fork may have deprecated the following. -jpt)

If you want to use this app in conjunction with django-user-creation, you have to create your own ModelAdmin for User. You may do so by adding a useradmin.py file to your project with the following contents:

from django.contrib import admin
from django.contrib.auth.models import User
from user_creation.forms import EmailAccountCreationForm
from email_login.useradmin import EmailLoginAdmin


class MyUserAdmin(EmailLoginAdmin):
    add_form = EmailAccountCreationForm
    add_fieldsets = (
        (None, {
            'classes': ('wide',),
            'fields': ('email', 'password1', 'password2', 'email_user')}
        ),
    )

admin.site.unregister(User)
admin.site.register(User, MyUserAdmin)

and adding the line import useradmin to your urls.py after the overrides described above.

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.