django-email-as-username 1.6.2

User authentication with email addresses instead of usernames
django-email-as-username is a Django app that allows you to treat users as having only email addresses, instead of usernames.

- Provides an email auth backend and helper functions for creating users.
- Patches the Django admin to handle email based user authentication.
- Overides the createsuperuser command to create users with email only.
- Treats email authentication as case-insensitive.

Installation

Install from PyPI:

pip install django-email-as-username

Add 'emailusernames' to INSTALLED_APPS.

INSTALLED_APPS = (
 ...
 'emailusernames',
)


Set EmailAuthBackend as your authentication backend:

AUTHENTICATION_BACKENDS = (
 'emailusernames.backends.EmailAuthBackend',
)


Usage

Creating users

You should create users using the create_user and create_superuser functions.

from emailusernames.utils import create_user, create_superuser

create_user('me@example.com', 'password')
create_superuser('admin@example.com', 'password')


Retrieving users

You can retrieve users, using case-insensitive email matching, with the get_user function. Similarly you can use user_exists to test if a given user exists.

from emailusernames.utils import get_user, user_exists

user = get_user('someone@example.com')
...

if user_exists('someone@example.com'):
 ...


Updating users

You can update a user's email and save the instance, without having to also modify the username.

user.email = 'other@example.com'
user.save()


Note that the user.username attribute will always return the email address, but behind the scenes it will be stored as a hashed version of the user's email.

Authenticating users

You should use email and password keyword args in calls to authenticate, rather than the usual username and password.

from django.contrib.auth import authenticate

user = authenticate(email='someone@example.com', password='password')
if user:
 ...
else:
 ...

User Forms

emailusernames provides the following forms that you can use for authenticating, creating and updating users:

- emailusernames.forms.EmailAuthenticationForm
- emailusernames.forms.EmailAdminAuthenticationForm
- emailusernames.forms.UserCreationForm
- emailusernames.forms.UserChangeForm

Using Django's built-in login view

If you're using django.contrib.auth.views.login in your urlconf, you'll want to make sure you pass through EmailAuthenticationForm as an argument to the view.

urlpatterns = patterns('',
 ...
 url(r'^auth/login$', 'django.contrib.auth.views.login',
 {'authentication_form': EmailAuthenticationForm}, name='login'),
 ...
)

last updated on:
July 10th, 2012, 22:06 GMT
price:
FREE!
homepage:
github.com
license type:
BSD License 
developed by:
Tom Christie
category:
ROOT \ Internet \ HTTP (WWW)
django-email-as-username
Download Button

In a hurry? Add it to your Download Basket!

user rating

UNRATED
0.0/5
 

0/5

Rate it!

Add your review!

SUBMIT