]> git.openstreetmap.org Git - osqa.git/commitdiff
check whether the private and public ReCaptcha keys are importable, only if they...
authorjordan <jordan@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Wed, 3 Aug 2011 09:16:38 +0000 (09:16 +0000)
committerjordan <jordan@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Wed, 3 Aug 2011 09:16:38 +0000 (09:16 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@1155 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum_modules/localauth/forms.py

index 6facc5dd1ece0e772e39776db5256d4df8a6d92e..ee6157775ae867d52e3d6889b7aa8f31fa1f7c24 100644 (file)
@@ -7,8 +7,6 @@ from django.contrib.auth import authenticate
 from django import forms
 import logging
 
-from forum.settings import RECAPTCHA_PUB_KEY, RECAPTCHA_PRIV_KEY
-
 class ClassicRegisterForm(SetPasswordForm):
     """ legacy registration form """
 
@@ -19,7 +17,14 @@ class ClassicRegisterForm(SetPasswordForm):
     def __init__(self, *args, **kwargs):
         super(ClassicRegisterForm, self).__init__(*args, **kwargs)
 
-        if len(str(RECAPTCHA_PUB_KEY.value)) > 0 and len(str(RECAPTCHA_PRIV_KEY.value)) > 0:
+        # Try importing the ReCapthca public and private keys, Import Error will be raised in case it has been disabled
+        try:
+            from forum.settings import RECAPTCHA_PUB_KEY, RECAPTCHA_PRIV_KEY
+            recaptcha_enabled = len(str(RECAPTCHA_PUB_KEY.value)) > 0 and len(str(RECAPTCHA_PRIV_KEY.value)) > 0
+        except ImportError:
+            recaptcha_enabled = False
+
+        if recaptcha_enabled:
             spam_fields = call_all_handlers('create_anti_spam_field')
             if spam_fields:
                 spam_fields = dict(spam_fields)