Changeset 3121 in products
- Timestamp:
- Apr 15, 2011 1:00:00 PM (13 years ago)
- Location:
- quintagroup.formlib.captcha/trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.formlib.captcha/trunk/quintagroup/formlib/captcha/example.py
r2810 r3121 8 8 from quintagroup.formlib.captcha import Captcha 9 9 10 10 11 # Define CaptchaFormlibForm form schema 11 12 12 class ICaptchaFormlibFormSchema(Interface): 13 13 label = TextLine(title=u'Label', 14 14 required=False) 15 15 captcha = Captcha(title=u'Type the code') 16 16 17 17 18 # Create adapter for any object to ICaptchaFormlibFormSchema 18 19 # schema interface 19 20 20 class CaptchaFormlibFormAdapter(object): 21 21 implements(ICaptchaFormlibFormSchema) … … 26 26 label = u'' 27 27 captcha = None 28 28 29 29 30 # And at the last define the CaptchaFormlibForm form 30 31 31 class CaptchaFormlibForm(EditForm): 32 32 form_fields = FormFields(ICaptchaFormlibFormSchema) -
quintagroup.formlib.captcha/trunk/quintagroup/formlib/captcha/field.py
r2210 r3121 3 3 from interfaces import ICaptcha 4 4 5 5 6 class Captcha(ASCIILine): 6 7 implements(ICaptcha) -
quintagroup.formlib.captcha/trunk/quintagroup/formlib/captcha/interfaces.py
r2210 r3121 1 1 from zope.schema.interfaces import IASCIILine 2 2 3 3 4 class ICaptcha(IASCIILine): -
quintagroup.formlib.captcha/trunk/quintagroup/formlib/captcha/tests/test_doctests.py
r2806 r3121 15 15 from quintagroup.captcha.core.tests.testWidget import addTestLayer 16 16 17 17 18 class FormlibCaptchaLayer(PloneSite): 18 19 @classmethod … … 29 30 def tearDown(cls): 30 31 pass 31 32 ptc.setupPloneSite(extension_profiles=['quintagroup.captcha.core:default',]) 32 33 ptc.setupPloneSite(extension_profiles=['quintagroup.captcha.core:default', ]) 34 33 35 34 36 class FormlibCaptchaTestCase(ptc.FunctionalTestCase): … … 44 46 self.hashkey = self.portal.getCaptcha() 45 47 decrypted = decrypt(captcha_key, self.hashkey) 46 self.captcha_word = getWord(int(parseKey(decrypted)['key']) -1)48 self.captcha_word = getWord(int(parseKey(decrypted)['key']) - 1) 47 49 48 50 … … 54 56 'README.txt', package='quintagroup.formlib.captcha', 55 57 test_class=FormlibCaptchaTestCase, 56 optionflags=doctest.REPORT_ONLY_FIRST_FAILURE | doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS),57 58 optionflags=doctest.REPORT_ONLY_FIRST_FAILURE | \ 59 doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS), 58 60 ]) 59 61 -
quintagroup.formlib.captcha/trunk/quintagroup/formlib/captcha/tests/test_unittests.py
r2800 r3121 21 21 from quintagroup.formlib.captcha import CaptchaWidget 22 22 23 23 24 @onsetup 24 25 def setup_product(): … … 31 32 32 33 setup_product() 33 ptc.setupPloneSite(extension_profiles=['quintagroup.captcha.core:default', ])34 ptc.setupPloneSite(extension_profiles=['quintagroup.captcha.core:default', ]) 34 35 35 36 … … 79 80 FIELDTAG = '<input\s+[^>]*type=\"text\"\s*[^>]*>' 80 81 self.assertEqual(re.search(FIELDTAG, self.html) is not None, True) 81 82 82 83 83 84 class TestCaptchaWidgetToField(ptc.PloneTestCase): … … 101 102 def testSubmitRightCaptcha(self): 102 103 decrypted = decrypt(self.captcha_key, self.hashkey) 103 key = getWord(int(parseKey(decrypted)['key']) -1)104 key = getWord(int(parseKey(decrypted)['key']) - 1) 104 105 try: 105 106 res = self.widget._toFieldValue(key) 106 107 except ConversionError, e: 107 self.fail("Rised unexpected %s error on right captcha submit" % e.doc()) 108 self.fail("Rised unexpected %s error on right captcha submit" % \ 109 e.doc()) 108 110 else: 109 111 self.assertEqual(res, key) 110 112 111 113 def testSubmitWrongCaptcha(self): 112 114 try: … … 119 121 def testSubmitRightCaptchaTwice(self): 120 122 decrypted = decrypt(self.captcha_key, self.hashkey) 121 key = getWord(int(parseKey(decrypted)['key']) -1)123 key = getWord(int(parseKey(decrypted)['key']) - 1) 122 124 self.widget._toFieldValue(key) 123 125 try: -
quintagroup.formlib.captcha/trunk/quintagroup/formlib/captcha/widget.py
r3098 r3121 23 23 logger = logging.getLogger('quintagroup.formlib.captcha') 24 24 25 25 26 class CaptchaWidget(ASCIIWidget): 26 27 … … 42 43 43 44 site = self.get_site() 44 portal_url = getToolByName(site 45 portal_url = getToolByName(site, 'portal_url')() 45 46 key = site.getCaptcha() 46 47 … … 52 53 return u"""<input type="hidden" value="%s" name="%shashkey" /> 53 54 %s 54 <img src="%s/getCaptchaImage/%s" alt="Enter the word"/>""" % (key, 55 prefix, 56 renderElement(self.tag, **kwargs), 57 portal_url, 58 key) 59 55 <img src="%s/getCaptchaImage/%s" 56 alt="Enter the word"/>""" % (key, 57 prefix, 58 renderElement(self.tag, 59 **kwargs), 60 portal_url, 61 key) 62 60 63 def _toFieldValue(self, input): 61 64 # Verify the user input against the captcha … … 64 67 site = self.get_site() 65 68 captcha_type = site.getCaptchaType() 66 69 67 70 # validate captcha input 68 71 if input and captcha_type in ['static', 'dynamic']: … … 72 75 else: 73 76 prefix = '' 74 77 75 78 hashkey = self.request.get('%shashkey' % prefix, '') 76 79 decrypted_key = decrypt(site.captcha_key, hashkey) 77 80 parsed_key = parseKey(decrypted_key) 78 81 79 82 index = parsed_key['key'] 80 83 date = parsed_key['date'] 81 84 82 85 if captcha_type == 'static': 83 86 img = getattr(site, '%s.jpg' % index) … … 87 90 enc = input 88 91 solution = getWord(int(index)) 89 92 90 93 captcha_tool = getToolByName(site, 'portal_captchas') 91 if (enc != solution) or (captcha_tool.has_key(decrypted_key)) or (DateTime().timeTime() - float(date) > 3600): 94 if (enc != solution) or (decrypted_key in captcha_tool) or \ 95 (DateTime().timeTime() - float(date) > 3600): 92 96 raise ConversionError(_(u'Please re-enter validation code.')) 93 97 else: 94 98 captcha_tool.addExpiredKey(decrypted_key) 95 99 96 100 return super(CaptchaWidget, self)._toFieldValue(input) -
quintagroup.formlib.captcha/trunk/setup.py
r2809 r3121 6 6 setup(name='quintagroup.formlib.captcha', 7 7 version=version, 8 description="Captcha field for formlib based on quintagroup.captcha.core package", 8 description="Captcha field for formlib based on " 9 "quintagroup.captcha.core package", 9 10 long_description=open("README.txt").read() + "\n" + 10 11 open(os.path.join("docs", "HISTORY.txt")).read(), 11 # Get more strings from http://www.python.org/pypi?%3Aaction=list_classifiers12 12 classifiers=[ 13 13 "Framework :: Plone",
Note: See TracChangeset
for help on using the changeset viewer.