Skip to content

Commit

Permalink
Merge branch 'master' into nephila-feature/html_email_1.2.2
Browse files Browse the repository at this point in the history
Conflicts:
	userena/settings.py
  • Loading branch information
wunki committed Aug 19, 2013
2 parents c60f936 + 93657f8 commit 7a70197
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 20 deletions.
2 changes: 1 addition & 1 deletion demo/demo/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,4 @@
ANONYMOUS_USER_ID = -1

# Test runner
TEST_RUNNER = 'django.test.simple.DjangoTestSuiteRunner'
TEST_RUNNER = 'django_coverage.coverage_runner.CoverageRunner'
3 changes: 3 additions & 0 deletions demo/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ South

# Userena
django-userena

# Coverage for testing
django_coverage
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Userena Introduction
====================

This documentation covers 1.2.1 release of django-userena application. A Django
This documentation covers 1.2.2 release of django-userena application. A Django
application that takes care of your account needs.

Why userena?
Expand Down
7 changes: 7 additions & 0 deletions docs/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@ Default: ``False`` (boolean)
Boolean value that defines if the ``profile_list`` view is enabled within the
project. If so, users can view a list of different profiles.

USERENA_DISABLE_SIGNUP
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Default: ``False`` (boolean)

Boolean value that defines if signups are disabled within the project. If so,
users trying to sign up will be denied.

USERENA_USE_MESSAGES
~~~~~~~~~~~~~~~~~~~~
Default: ``True`` (boolean)
Expand Down
12 changes: 3 additions & 9 deletions run_tests
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
#!/usr/bin/env bash

# TODO: How to tell setup.py to only run some tests.

case $1 in
userena ) echo -e "\033[1mRunning tests for userena.\033[0m"
cmd="coverage run demo/manage.py test userena"
report_cmd="coverage report -m userena/*.py userena/management/commands/*.py"
cmd="demo/manage.py test userena"
;;
umessages ) echo -e "\033[1mRunning tests for umessages.\033[0m"
cmd="coverage run demo/manage.py test umessages"
report_cmd="coverage report -m userena/contrib/umessages/*.py"
cmd="demo/manage.py test umessages"
;;
* ) echo -e "\033[1mRunning all tests.\033[0m"
cmd="coverage run demo/manage.py test userena umessages"
report_cmd="coverage report -m userena/*.py userena/management/commands/*py userena/contrib/umessages/*.py"
cmd="demo/manage.py test userena umessages"
esac

$cmd
$report_cmd
16 changes: 10 additions & 6 deletions userena/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ class UserenaAdmin(UserAdmin, GuardedModelAdmin):
'is_staff', 'is_active', 'date_joined')
list_filter = ('is_staff', 'is_superuser', 'is_active')

try:
admin.site.unregister(get_user_model())
except admin.sites.NotRegistered:
pass

admin.site.register(get_user_model(), UserenaAdmin)
admin.site.register(get_profile_model())
if settings.USERENA_REGISTER_USER:
try:
admin.site.unregister(get_user_model())
except admin.sites.NotRegistered:
pass

admin.site.register(get_user_model(), UserenaAdmin)

if settings.USERENA_REGISTER_PROFILE:
admin.site.register(get_profile_model())
4 changes: 2 additions & 2 deletions userena/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def clean_username(self):
except get_user_model().DoesNotExist:
pass
else:
if UserenaSignup.objects.filter(user__username__iexact=self.cleaned_data['username']).exclude(activation_key=userena_settings.USERENA_ACTIVATED):
if userena_settings.USERENA_ACTIVATION_REQUIRED and UserenaSignup.objects.filter(user__username__iexact=self.cleaned_data['username']).exclude(activation_key=userena_settings.USERENA_ACTIVATED):
raise forms.ValidationError(_('This username is already taken but not confirmed. Please check your email for verification steps.'))
raise forms.ValidationError(_('This username is already taken.'))
if self.cleaned_data['username'].lower() in userena_settings.USERENA_FORBIDDEN_USERNAMES:
Expand All @@ -62,7 +62,7 @@ def clean_username(self):
def clean_email(self):
""" Validate that the e-mail address is unique. """
if get_user_model().objects.filter(email__iexact=self.cleaned_data['email']):
if UserenaSignup.objects.filter(user__email__iexact=self.cleaned_data['email']).exclude(activation_key=userena_settings.USERENA_ACTIVATED):
if userena_settings.USERENA_ACTIVATION_REQUIRED and UserenaSignup.objects.filter(user__email__iexact=self.cleaned_data['email']).exclude(activation_key=userena_settings.USERENA_ACTIVATED):
raise forms.ValidationError(_('This email is already in use but not confirmed. Please check your email for verification steps.'))
raise forms.ValidationError(_('This email is already in use. Please supply a different email.'))
return self.cleaned_data['email']
Expand Down
2 changes: 1 addition & 1 deletion userena/locale/ru/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ msgstr "Имя пользователя"
#: forms.py:32 tests/forms.py:26
msgid "Username must contain only letters, numbers, dots and underscores."
msgstr ""
"Имя пользователя должно содержать только буквы, цифры, точки и подчёркивания."
"Имя пользователя должно содержать только латинские буквы, цифры, точки и подчёркивания."

#: forms.py:35 forms.py:162 templates/userena/profile_detail.html:35
msgid "Email"
Expand Down
8 changes: 8 additions & 0 deletions userena/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@
'USERENA_DISABLE_PROFILE_LIST',
False)

USERENA_DISABLE_SIGNUP = getattr(settings,
'USERENA_DISABLE_SIGNUP',
False)

USERENA_USE_MESSAGES = getattr(settings,
'USERENA_USE_MESSAGES',
True)
Expand All @@ -110,3 +114,7 @@
USERENA_HTML_EMAIL = getattr(settings, 'USERENA_HTML_EMAIL', False)

USERENA_USE_PLAIN_TEMPLATE = getattr(settings, 'USERENA_USE_PLAIN_TEMPLATE', not USERENA_HTML_EMAIL)

USERENA_REGISTER_PROFILE = getattr(settings, 'USERENA_REGISTER_PROFILE', True)

USERENA_REGISTER_USER = getattr(settings, 'USERENA_REGISTER_USER', True)
9 changes: 9 additions & 0 deletions userena/tests/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,15 @@ def test_signup_view(self):

# Back to default
userena_settings.USERENA_WITHOUT_USERNAMES = False

# Check for 403 with signups disabled
userena_settings.USERENA_DISABLE_SIGNUP = True

response = self.client.get(reverse('userena_signup'))
self.assertEqual(response.status_code, 403)

# Back to default
userena_settings.USERENA_DISABLE_SIGNUP = False

def test_signup_view_signout(self):
""" Check that a newly signed user shouldn't be signed in. """
Expand Down
4 changes: 4 additions & 0 deletions userena/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ def signup(request, signup_form=SignupForm,
Form supplied by ``signup_form``.
"""
# If signup is disabled, return 403
if userena_settings.USERENA_DISABLE_SIGNUP:
return HttpResponseForbidden(_("Signups are disabled."))

# If no usernames are wanted and the default form is used, fallback to the
# default form that doesn't display to enter the username.
if userena_settings.USERENA_WITHOUT_USERNAMES and (signup_form == SignupForm):
Expand Down

0 comments on commit 7a70197

Please sign in to comment.