From 7ddd67ebdc119a7f95a24775c84f3bb5b8f274c5 Mon Sep 17 00:00:00 2001 From: Egil Moeller Date: Fri, 14 Feb 2014 14:50:51 +0100 Subject: Added support for directly posting as anonymous with recaptcha --- askbot/forms.py | 12 ++++++++++-- askbot/templates/widgets/ask_form.html | 12 +++++++++--- askbot/templates/widgets/question_edit_tips.html | 2 +- askbot/views/writers.py | 19 +++++++++++++++---- 4 files changed, 35 insertions(+), 10 deletions(-) diff --git a/askbot/forms.py b/askbot/forms.py index a490a4ac..c0a30679 100644 --- a/askbot/forms.py +++ b/askbot/forms.py @@ -923,11 +923,20 @@ class AskForm(PostAsSomeoneForm, PostPrivatelyForm): required=False, ) + if (not user.is_authenticated() + and askbot_settings.USE_RECAPTCHA + and askbot_settings.ALLOW_ASK_ANONYMOUSLY): + self.fields['recaptcha'] = RecaptchaField( + private_key=askbot_settings.RECAPTCHA_SECRET, + public_key=askbot_settings.RECAPTCHA_KEY, + label='Are you human?', required=True) + #hide ask_anonymously field if getattr(django_settings, 'ASKBOT_MULTILINGUAL', False): self.fields['language'] = LanguageField() - if askbot_settings.ALLOW_ASK_ANONYMOUSLY is False: + if ( not askbot_settings.ALLOW_ASK_ANONYMOUSLY + or not user.is_authenticated()): self.hide_field('ask_anonymously') def clean_ask_anonymously(self): @@ -937,7 +946,6 @@ class AskForm(PostAsSomeoneForm, PostPrivatelyForm): self.cleaned_data['ask_anonymously'] = False return self.cleaned_data['ask_anonymously'] - ASK_BY_EMAIL_SUBJECT_HELP = _( 'Subject line is expected in the format: ' '[tag1, tag2, tag3,...] question title' diff --git a/askbot/templates/widgets/ask_form.html b/askbot/templates/widgets/ask_form.html index df37ba3c..0d3e9e30 100644 --- a/askbot/templates/widgets/ask_form.html +++ b/askbot/templates/widgets/ask_form.html @@ -61,10 +61,16 @@ {% endif %} - {% if not request.user.is_authenticated() %} - + + {% if form.recaptcha.errors %} + {{ form.recaptcha.errors }} + {% endif %} + {{ form.recaptcha }} + + {% if request.user.is_authenticated() or form.recaptcha %} + {% else %} - + {% endif %}
diff --git a/askbot/templates/widgets/question_edit_tips.html b/askbot/templates/widgets/question_edit_tips.html index 636bd38d..78f6d3fb 100644 --- a/askbot/templates/widgets/question_edit_tips.html +++ b/askbot/templates/widgets/question_edit_tips.html @@ -3,7 +3,7 @@ {{ settings.QUESTION_INSTRUCTIONS|safe }} {% else %}