tangentlabs/django-oscar — pull request #324 by elbaschid (2012-09-30 01:59:49+00:00)
Title: Check for existing email when updating profile

A user in Oscar is identified by email address instead of the
username. This is, however, not set as a ``unique`` constraint
in the user model in ``django.contrib.auth.models.User``. Checks
if an email already exists are carried out when a user registers
but are ignored when a registered user changes their
profile. This can lead to multiple users having the same email
address which should not happen.

I provide a failing test with a mixin that can be used in both
the ``UserForm`` and ``UserAndProfileForm`` to clean the email
field when validating the form. A ``ValidationError`` is raised
when a user with this email address already exists and is not
the currently edited instance (makes sure that profile updates
with unchanged email work still).

I am not sure if this is the best way of handling the validation.
Feedback is welcome.

*Note:* It might also be worth considering to change to a custom
``User`` model when Oscar starts using Django 1.5 as it now
supports swappable user models. It would allow for making the
email field truely unique.