Skip to content

Commit

Permalink
Merge pull request #169 from incuna/email-case-insensitivity
Browse files Browse the repository at this point in the history
Use a case-insensitive email field. (Requires Django 1.11.)
  • Loading branch information
adam-thomas committed Jun 21, 2017
2 parents a4506a1 + 49794d2 commit 6784e33
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 16 deletions.
13 changes: 3 additions & 10 deletions .travis.yml
Expand Up @@ -4,16 +4,9 @@ env:
- DATABASE_URL='postgres://postgres@localhost/user_management'
- TERM='xterm-256color'
matrix:
- TOX_ENV=py27-django18
- TOX_ENV=py27-django19
- TOX_ENV=py33-django18
- TOX_ENV=py34-django18
- TOX_ENV=py35-django18
- TOX_ENV=py34-django19
- TOX_ENV=py35-django19
- TOX_ENV=py27-django110
- TOX_ENV=py34-django110
- TOX_ENV=py35-django110
- TOX_ENV=py27-django111
- TOX_ENV=py34-django111
- TOX_ENV=py35-django111
- TOX_ENV=py27-djangopre
- TOX_ENV=py34-djangopre
- TOX_ENV=py35-djangopre
Expand Down
5 changes: 4 additions & 1 deletion CHANGELOG.md
Expand Up @@ -2,14 +2,17 @@ Changelog for django-user-management

This project uses Semantic Versioning (2.0).

## 17.0.0

* Backwards incompatible: Use `CIEmailField` from Django 1.11 for a case-insensitive email field.

## 16.1.1

* Fix bug using VERIFIED_QUERYSTRING with a LOGIN_URL.

## 16.1.0

* Allow VerifyUserEmailView get_redirect_url function to accept an extra string.

* Allow user login after email verification providing a setting is true in an apps settings file.
This works in Django 1.10.

Expand Down
9 changes: 9 additions & 0 deletions docs/installation.md
Expand Up @@ -37,6 +37,15 @@ If you want to use the `VerifyEmailMixin`, substitute it for `ActiveUserMixin`.
Make sure the app containing your custom user model is added to `settings.INSTALLED_APPS`,
and set `settings.AUTH_USER_MODEL` to be the path to your custom user model.

If you use `EmailUserMixin` or any of its derivatives, you'll need to set up Postgres to support a `CIText` extension in your migration. Add the following to your migration:

from django.contrib.postgres.operations import CITextExtension

operations = [
CITextExtension(),
...
]

## Authtoken

If you have `user_management.api` in your `INSTALLED_APPS`, you'll also need to create a migration in your project for the `AuthToken` model.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
@@ -1,7 +1,7 @@
from setuptools import find_packages, setup


version = '16.1.1'
version = '17.0.0'


install_requires = (
Expand Down
4 changes: 1 addition & 3 deletions tox.ini
Expand Up @@ -9,9 +9,7 @@ deps =
--upgrade
--pre
-rrequirements.txt
django18: Django>=1.8,<1.9
django19: Django>=1.9,<1.10
django110: Django>=1.10,<1.11
django111: Django>=1.11,<1.12
djangopre: Django

commands =
Expand Down
3 changes: 2 additions & 1 deletion user_management/models/mixins.py
@@ -1,5 +1,6 @@
from django.contrib.auth.models import BaseUserManager
from django.contrib.auth.tokens import default_token_generator
from django.contrib.postgres.fields import CIEmailField
from django.contrib.sites.models import Site
from django.core import checks, signing
from django.db import models
Expand Down Expand Up @@ -56,7 +57,7 @@ class Meta:


class EmailUserMixin(models.Model):
email = models.EmailField(
email = CIEmailField(
verbose_name=_('Email address'),
unique=True,
max_length=511,
Expand Down
5 changes: 5 additions & 0 deletions user_management/models/tests/test_models.py
Expand Up @@ -74,6 +74,11 @@ def test_name_methods(self):
self.assertEqual(user.get_full_name(), expected)
self.assertEqual(user.get_short_name(), expected)

def test_case_insensitive_uniqueness(self):
self.model(email='CAPS@example.com').save()
with self.assertRaises(IntegrityError):
self.model(email='caps@example.com').save()


class TestUserManager(TestCase):
manager = models.User.objects
Expand Down
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2017-06-21 10:00
from __future__ import unicode_literals

import django.contrib.postgres.fields.citext
from django.contrib.postgres.operations import CITextExtension
from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('tests', '0001_initial'),
('api', '0002_authtoken_user'),
]

operations = [
CITextExtension(),
migrations.AlterField(
model_name='user',
name='email',
field=django.contrib.postgres.fields.citext.CIEmailField(max_length=511, unique=True, verbose_name='Email address'),
),
]

0 comments on commit 6784e33

Please sign in to comment.