Self hosted FLOSS fitness/workout, nutrition and weight tracker
Don't use captcha fields when registering through an app
Roland Geidera352a05133b9
diff --git a/wger/manager/forms.py b/wger/manager/forms.pyindex 2d9dcb5cf..da2e8e451 100644--- a/wger/manager/forms.py+++ b/wger/manager/forms.py@@ -80,11 +80,25 @@ class UserEmailForm(ModelForm):class RegistrationForm(UserCreationForm, UserEmailForm):+ '''+ Registration form+ '''captcha = ReCaptchaField(attrs={'theme': 'clean'},label=_('Confirmation text'),help_text=_('As a security measure, please enter the previous words'),)+class RegistrationFormNoCaptcha(UserCreationForm, UserEmailForm):+ '''+ Registration form without captcha field++ This is used when registering through an app, in that case there is not+ such a spam danger and simplifies the registration process on a mobile+ device.+ '''+ pass++class DemoUserForm(Form):captcha = ReCaptchaField(attrs={'theme': 'clean'},label=_('Confirmation text'),diff --git a/wger/manager/views/user.py b/wger/manager/views/user.pyindex aa5f41b8d..e6795058c 100644--- a/wger/manager/views/user.py+++ b/wger/manager/views/user.py@@ -39,6 +39,7 @@ from wger.exercises.models import Languagefrom wger.manager.forms import UserPreferencesFormfrom wger.manager.forms import UserEmailFormfrom wger.manager.forms import RegistrationForm+from wger.manager.forms import RegistrationFormNoCaptchafrom wger.utils.constants import USER_TABfrom wger.utils.user_agents import check_request_amazon, check_request_android@@ -75,13 +76,17 @@ def registration(request):template_data = {}template_data.update(csrf(request))+ # Don't use captcha when registering through an app+ is_app = check_request_amazon(request) or check_request_android(request)+ FormClass = RegistrationFormNoCaptcha if is_app else RegistrationForm+if request.method == 'POST':# If the user is already logged in, redirectif request.user.is_authenticated():return HttpResponseRedirect(reverse('dashboard'))- form = RegistrationForm(data=request.POST)+ form = FormClass(data=request.POST)# If the data is valid, log in and redirectif form.is_valid():@@ -103,7 +108,7 @@ def registration(request):messages.success(request, _('You were successfully registered'))return HttpResponseRedirect(reverse('dashboard'))else:- form = RegistrationForm()+ form = FormClass()template_data['form'] = formtemplate_data['title'] = _('Register')