forked from wger-project/wger
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For certain deployments, users should not be able to register on their own, but should be added by the appropriate gym managers. This can now be configured in the global settings file Fixes wger-project#220
- Loading branch information
1 parent
ffa5ac1
commit 1fa2888
Showing
8 changed files
with
83 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,11 +34,15 @@ def test_registration_captcha(self): | |
Tests that the correct form is used depending on global | ||
configuration settings | ||
''' | ||
with self.settings(WGER_SETTINGS={'USE_RECAPTCHA': True, 'REMOVE_WHITESPACE': False}): | ||
with self.settings(WGER_SETTINGS={'USE_RECAPTCHA': True, | ||
'REMOVE_WHITESPACE': False, | ||
'ALLOW_REGISTRATION': True}): | ||
response = self.client.get(reverse('core:user:registration')) | ||
self.assertIsInstance(response.context['form'], RegistrationForm) | ||
|
||
with self.settings(WGER_SETTINGS={'USE_RECAPTCHA': False, 'REMOVE_WHITESPACE': False}): | ||
with self.settings(WGER_SETTINGS={'USE_RECAPTCHA': False, | ||
'REMOVE_WHITESPACE': False, | ||
'ALLOW_REGISTRATION': True}): | ||
response = self.client.get(reverse('core:user:registration')) | ||
self.assertIsInstance(response.context['form'], RegistrationFormNoCaptcha) | ||
|
||
|
@@ -84,16 +88,28 @@ def test_register(self): | |
self.assertEqual(response.status_code, 200) | ||
self.assertEqual(count_before + 1, count_after) | ||
|
||
# No email | ||
registration_data['email'] = '' | ||
response = self.client.post(reverse('core:user:registration'), registration_data) | ||
count_after = User.objects.count() | ||
self.assertEqual(response.status_code, 302) | ||
self.assertEqual(count_before + 2, count_after) | ||
def test_registration_deactivated(self): | ||
''' | ||
Test that with deactivated registration no users can register | ||
''' | ||
|
||
# Already logged in | ||
response = self.client.post(reverse('core:user:registration'), registration_data) | ||
count_after = User.objects.count() | ||
self.assertEqual(response.status_code, 302) | ||
self.assertEqual(count_before + 2, count_after) | ||
self.assertIn('dashboard', response['Location']) | ||
with self.settings(WGER_SETTINGS={'USE_RECAPTCHA': False, | ||
'REMOVE_WHITESPACE': False, | ||
'ALLOW_REGISTRATION': False}): | ||
|
||
# Fetch the registration page | ||
response = self.client.get(reverse('core:user:registration')) | ||
self.assertEqual(response.status_code, 302) | ||
|
||
# Fill in the registration form | ||
registration_data = {'username': 'myusername', | ||
'password1': 'secret', | ||
'password2': 'secret', | ||
'email': '[email protected]', | ||
'g-recaptcha-response': 'PASSED', } | ||
count_before = User.objects.count() | ||
|
||
response = self.client.post(reverse('core:user:registration'), registration_data) | ||
count_after = User.objects.count() | ||
self.assertEqual(response.status_code, 302) | ||
self.assertEqual(count_before, count_after) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# This file is part of wger Workout Manager. | ||
# | ||
# wger Workout Manager is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# wger Workout Manager is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
|
||
import logging | ||
|
||
from django.conf import settings | ||
|
||
from django.shortcuts import render | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def features(request): | ||
''' | ||
Render the features page | ||
''' | ||
|
||
context = {'allow_registration': settings.WGER_SETTINGS['ALLOW_REGISTRATION']} | ||
return render(request, 'functions.html', context) |