From eb98e2422b53f2a7463252a4fb2bf293eb369c5b Mon Sep 17 00:00:00 2001 From: Matt Stevenson Date: Tue, 29 May 2012 22:22:21 +1000 Subject: [PATCH 1/5] Added a test to verify that an invalid user login does not succeed --- usergroup/django_tests/login_test.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/usergroup/django_tests/login_test.py b/usergroup/django_tests/login_test.py index 26abdd3..b256d9e 100644 --- a/usergroup/django_tests/login_test.py +++ b/usergroup/django_tests/login_test.py @@ -28,3 +28,8 @@ def test_nonadmin_login(self): password='password') self.assertTrue(login_status) + def test_nonadmin_invalid_login(self): + """Verify that a user with invalid credentials cannot log in.""" + login_status = self.client.login(username='existing', + password='invalid_password') + self.assertFalse(login_status) From 03deed98c8e92cdcc49700baf52d4c436102c430 Mon Sep 17 00:00:00 2001 From: Matt Stevenson Date: Fri, 1 Jun 2012 23:18:50 +1000 Subject: [PATCH 2/5] Tidied mixed spaces and tabs in accounts urlconf --- accounts/urls.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/accounts/urls.py b/accounts/urls.py index 02a89c4..e453c38 100755 --- a/accounts/urls.py +++ b/accounts/urls.py @@ -18,12 +18,12 @@ 'accounts', url(r'login/*$', auth_views.login, - {'template_name': 'login.html', + {'template_name': 'login.html', 'authentication_form': login_forms.AuthenticationWithInActiveForm, 'extra_context': { 'register_form': register_forms.RegistrationFormUniqueEmail(), - 'providers': PROVIDERS, - 'openid_providers': OPENID_PROVIDERS, + 'providers': PROVIDERS, + 'openid_providers': OPENID_PROVIDERS, }, }), From bc75682f5ba34551c0d8a36ee30e7fa114dac41f Mon Sep 17 00:00:00 2001 From: Matt Stevenson Date: Sat, 2 Jun 2012 01:18:35 +1000 Subject: [PATCH 3/5] Add missing comma in field args, fix signal func arg --- accounts/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/accounts/models.py b/accounts/models.py index 136db8f..95cb3a2 100644 --- a/accounts/models.py +++ b/accounts/models.py @@ -76,7 +76,7 @@ class UserEmail(models.Model): ) verified_on = models.DateTimeField(null=True, blank=True) - verified_by = models.CharField(max_length=1 choices=VERIFIED_BY_CHOICES) + verified_by = models.CharField(max_length=1, choices=VERIFIED_BY_CHOICES) verification_key = models.CharField(max_length=40) @@ -93,7 +93,7 @@ def create_user_profile(sender, instance, created, **kwargs): def mark_email_as_verified_on_activation(sender, user, request, **kwargs): pass -signals.user_activated.connect(verify_email_on_activation) +signals.user_activated.connect(mark_email_as_verified_on_activation) def merge_on_activation(sender, user, request, **kwargs): pass From 72b5ae5e3653436e3d4646cf25513708f456d8de Mon Sep 17 00:00:00 2001 From: Matt Stevenson Date: Sat, 2 Jun 2012 01:18:53 +1000 Subject: [PATCH 4/5] Tidied-up imports --- accounts/models.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/accounts/models.py b/accounts/models.py index 95cb3a2..35bc0ba 100644 --- a/accounts/models.py +++ b/accounts/models.py @@ -3,9 +3,15 @@ # -*- coding: utf-8 -*- # vim: set ts=4 sw=4 et sts=4 ai: -from django.contrib import admin -from django.db import models +from django.conf import settings from django.contrib.auth.models import User +from django.db import models +from django.db.models.signals import post_save + +from registration import signals +from registration.models import RegistrationManager + +from accounts import merge ## Registration @@ -81,9 +87,6 @@ class UserEmail(models.Model): verification_key = models.CharField(max_length=40) -from django.contrib.auth.models import User -from django.db.models.signals import post_save - def create_user_profile(sender, instance, created, **kwargs): if created: UserProfile.objects.create(user=instance) @@ -113,7 +116,7 @@ def verify_user(backend, user, details, **kw): user.is_active = True user.save() else: - rego = registration.models.RegistrationManager.create_profile(user) + rego = RegistrationManager.create_profile(user) rego.send_verify_email() From f95e8fc3c6e129d5b8b897507fd116d87713f9ee Mon Sep 17 00:00:00 2001 From: Matt Stevenson Date: Sat, 2 Jun 2012 01:21:05 +1000 Subject: [PATCH 5/5] Resolves IntegrityError case from usergroup tests - The UserProfile from accounts requires a primary email address to be attached. - This patch re-orders the create signal for the User so we meet validation requirements. --- accounts/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/accounts/models.py b/accounts/models.py index 35bc0ba..41c3156 100644 --- a/accounts/models.py +++ b/accounts/models.py @@ -89,8 +89,8 @@ class UserEmail(models.Model): def create_user_profile(sender, instance, created, **kwargs): if created: - UserProfile.objects.create(user=instance) - UserEmail.objects.create(user=instance) + primary_email = UserEmail.objects.create(user=instance) + UserProfile.objects.create(user=instance, primary=primary_email) post_save.connect(create_user_profile, sender=User)