Index: quintagroup.z3cform.captcha/tags/1.0.2/MANIFEST.in
===================================================================
--- quintagroup.z3cform.captcha/tags/1.0.2/MANIFEST.in (revision 3614)
+++ quintagroup.z3cform.captcha/tags/1.0.2/MANIFEST.in (revision 3614)
@@ -0,0 +1,3 @@
+recursive-include docs *
+recursive-include quintagroup *
+global-exclude *pyc
Index: quintagroup.z3cform.captcha/tags/1.0.2/README.txt
===================================================================
--- quintagroup.z3cform.captcha/tags/1.0.2/README.txt (revision 3614)
+++ quintagroup.z3cform.captcha/tags/1.0.2/README.txt (revision 3614)
@@ -0,0 +1,48 @@
+Introduction
+============
+
+quintagroup.z3cform.captcha is a package that allows to add captcha to the z3c.form.
+As a result such forms are prevented from automatic submit.
+
+Captchas in a z3c form
+----------------------
+
+Using quintagroup.z3cform.captcha in a z3c.form form is simple.
+Just add a Captcha field to your schema, use CaptchaWidgetFactory
+widget factory for this field and away you go:
+
+ >>> from zope.interface import Interface
+ >>> from z3c.form import form, field
+ >>> from quintagroup.z3cform.captcha import Captcha
+ >>> from quintagroup.z3cform.captcha import CaptchaWidgetFactory
+
+Now define form schema with Captch field
+
+ >>> class ICaptchaSchema(Interface):
+ ... captcha = Captcha(
+ ... title=_(u'Type the code'),
+ ... description=_(u'Type the code from the picture shown below.'))
+
+And set proper widget factory for the captcha field
+
+ >>> class CaptchaForm(form.Form):
+ ... fields = field.Fields(ICaptchaSchema)
+ ... fields['captcha'].widgetFactory = CaptchaWidgetFactory
+
+
+and z3c.form will take care of the rest. The widget associated with this field
+will render the captcha and verify the use input automatically.
+
+Supported Plone versions
+------------------------
+
+quintagroup.z3cform.captcha was tested with Plone 3.0.6, 3.1.7, 3.2.3, 3.3.4.
+
+Authors
+-------
+
+* Taras Melnychuk
+* Andriy Mylenkyi
+* Vitaliy Stepanov
+
+Copyright (c) "Quintagroup": http://quintagroup.com, 2004-2010
Index: quintagroup.z3cform.captcha/tags/1.0.2/docs/HISTORY.txt
===================================================================
--- quintagroup.z3cform.captcha/tags/1.0.2/docs/HISTORY.txt (revision 3614)
+++ quintagroup.z3cform.captcha/tags/1.0.2/docs/HISTORY.txt (revision 3614)
@@ -0,0 +1,26 @@
+Changelog
+=========
+
+1.0.2 (2013-10-16)
+------------------
+
+* PPP fixes
+
+* Fixed Exception for python 2.4
+
+* removed unused import
+
+* Updated classifiers
+
+* fixed ViewPageTemplateFile import
+
+1.0.1 (2011-10-28)
+------------------
+
+* Fixed kss inline validation
+
+1.0 (2010-04-29)
+----------------
+
+* Initial release
+
Index: quintagroup.z3cform.captcha/tags/1.0.2/docs/INSTALL.txt
===================================================================
--- quintagroup.z3cform.captcha/tags/1.0.2/docs/INSTALL.txt (revision 3614)
+++ quintagroup.z3cform.captcha/tags/1.0.2/docs/INSTALL.txt (revision 3614)
@@ -0,0 +1,40 @@
+quintagroup.z3cform.captcha Installation
+=======================
+
+ * When you're reading this you have probably already run
+ ``easy_install quintagroup.z3cform.captcha``. Find out how to install setuptools
+ (and EasyInstall) here:
+ http://peak.telecommunity.com/DevCenter/EasyInstall
+
+ * Create a file called ``quintagroup.z3cform.captcha-configure.zcml`` in the
+ ``/path/to/instance/etc/package-includes`` directory. The file
+ should only contain this::
+
+
+
+
+Alternatively, if you are using zc.buildout and the plone.recipe.zope2instance
+recipe to manage your project, you can do this:
+
+ * Add ``quintagroup.z3cform.captcha`` to the list of eggs to install, e.g.:
+
+ [buildout]
+ ...
+ eggs =
+ ...
+ quintagroup.z3cform.captcha
+
+ * Tell the plone.recipe.zope2instance recipe to install a ZCML slug:
+
+ [instance]
+ recipe = plone.recipe.zope2instance
+ ...
+ zcml =
+ quintagroup.z3cform.captcha
+
+ * Re-run buildout, e.g. with:
+
+ $ ./bin/buildout
+
+You can skip the ZCML slug if you are going to explicitly include the package
+from another package's configure.zcml file.
Index: quintagroup.z3cform.captcha/tags/1.0.2/docs/LICENSE.GPL
===================================================================
--- quintagroup.z3cform.captcha/tags/1.0.2/docs/LICENSE.GPL (revision 3614)
+++ quintagroup.z3cform.captcha/tags/1.0.2/docs/LICENSE.GPL (revision 3614)
@@ -0,0 +1,225 @@
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
Index: quintagroup.z3cform.captcha/tags/1.0.2/docs/LICENSE.txt
===================================================================
--- quintagroup.z3cform.captcha/tags/1.0.2/docs/LICENSE.txt (revision 3614)
+++ quintagroup.z3cform.captcha/tags/1.0.2/docs/LICENSE.txt (revision 3614)
@@ -0,0 +1,16 @@
+ quintagroup.formlib.captcha is copyright Vitaliy Podoba
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program 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 General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ MA 02111-1307 USA.
Index: quintagroup.z3cform.captcha/tags/1.0.2/quintagroup/__init__.py
===================================================================
--- quintagroup.z3cform.captcha/tags/1.0.2/quintagroup/__init__.py (revision 3614)
+++ quintagroup.z3cform.captcha/tags/1.0.2/quintagroup/__init__.py (revision 3614)
@@ -0,0 +1,6 @@
+# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
+try:
+ __import__('pkg_resources').declare_namespace(__name__)
+except ImportError:
+ from pkgutil import extend_path
+ __path__ = extend_path(__path__, __name__)
Index: quintagroup.z3cform.captcha/tags/1.0.2/quintagroup/z3cform/__init__.py
===================================================================
--- quintagroup.z3cform.captcha/tags/1.0.2/quintagroup/z3cform/__init__.py (revision 3614)
+++ quintagroup.z3cform.captcha/tags/1.0.2/quintagroup/z3cform/__init__.py (revision 3614)
@@ -0,0 +1,6 @@
+# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
+try:
+ __import__('pkg_resources').declare_namespace(__name__)
+except ImportError:
+ from pkgutil import extend_path
+ __path__ = extend_path(__path__, __name__)
Index: quintagroup.z3cform.captcha/tags/1.0.2/quintagroup/z3cform/captcha/__init__.py
===================================================================
--- quintagroup.z3cform.captcha/tags/1.0.2/quintagroup/z3cform/captcha/__init__.py (revision 3614)
+++ quintagroup.z3cform.captcha/tags/1.0.2/quintagroup/z3cform/captcha/__init__.py (revision 3614)
@@ -0,0 +1,5 @@
+from quintagroup.z3cform.captcha import field, widget
+
+Captcha = field.Captcha
+CaptchaWidget = widget.CaptchaWidget
+CaptchaWidgetFactory = widget.CaptchaWidgetFactory
Index: quintagroup.z3cform.captcha/tags/1.0.2/quintagroup/z3cform/captcha/configure.zcml
===================================================================
--- quintagroup.z3cform.captcha/tags/1.0.2/quintagroup/z3cform/captcha/configure.zcml (revision 3614)
+++ quintagroup.z3cform.captcha/tags/1.0.2/quintagroup/z3cform/captcha/configure.zcml (revision 3614)
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Index: quintagroup.z3cform.captcha/tags/1.0.2/quintagroup/z3cform/captcha/error.py
===================================================================
--- quintagroup.z3cform.captcha/tags/1.0.2/quintagroup/z3cform/captcha/error.py (revision 3614)
+++ quintagroup.z3cform.captcha/tags/1.0.2/quintagroup/z3cform/captcha/error.py (revision 3614)
@@ -0,0 +1,7 @@
+from z3c.form import error
+from quintagroup.z3cform.captcha import widget
+
+CaptchaFailureMessage = error.ErrorViewMessage(
+ u'Please re-enter validation code.',
+ error=ValueError,
+ widget=widget.CaptchaWidget)
Index: quintagroup.z3cform.captcha/tags/1.0.2/quintagroup/z3cform/captcha/field.py
===================================================================
--- quintagroup.z3cform.captcha/tags/1.0.2/quintagroup/z3cform/captcha/field.py (revision 3614)
+++ quintagroup.z3cform.captcha/tags/1.0.2/quintagroup/z3cform/captcha/field.py (revision 3614)
@@ -0,0 +1,7 @@
+from zope.interface import implements
+from zope.schema import ASCIILine
+from quintagroup.z3cform.captcha.interfaces import ICaptcha
+
+
+class Captcha(ASCIILine):
+ implements(ICaptcha)
Index: quintagroup.z3cform.captcha/tags/1.0.2/quintagroup/z3cform/captcha/interfaces.py
===================================================================
--- quintagroup.z3cform.captcha/tags/1.0.2/quintagroup/z3cform/captcha/interfaces.py (revision 3614)
+++ quintagroup.z3cform.captcha/tags/1.0.2/quintagroup/z3cform/captcha/interfaces.py (revision 3614)
@@ -0,0 +1,5 @@
+from zope.schema.interfaces import IASCIILine
+
+
+class ICaptcha(IASCIILine):
+ u"""A field for captcha validation"""
Index: quintagroup.z3cform.captcha/tags/1.0.2/quintagroup/z3cform/captcha/meta.zcml
===================================================================
--- quintagroup.z3cform.captcha/tags/1.0.2/quintagroup/z3cform/captcha/meta.zcml (revision 3614)
+++ quintagroup.z3cform.captcha/tags/1.0.2/quintagroup/z3cform/captcha/meta.zcml (revision 3614)
@@ -0,0 +1,4 @@
+
+
+
Index: quintagroup.z3cform.captcha/tags/1.0.2/quintagroup/z3cform/captcha/tests.py
===================================================================
--- quintagroup.z3cform.captcha/tags/1.0.2/quintagroup/z3cform/captcha/tests.py (revision 3614)
+++ quintagroup.z3cform.captcha/tags/1.0.2/quintagroup/z3cform/captcha/tests.py (revision 3614)
@@ -0,0 +1,172 @@
+import re
+import unittest
+
+from zope.interface import alsoProvides
+from zope.schema.interfaces import IField
+from zope.component import queryMultiAdapter
+from zope.app.form.interfaces import ConversionError
+
+from z3c.form import form
+from z3c.form.interfaces import IFormLayer
+from z3c.form.interfaces import IValidator
+from z3c.form.interfaces import IFieldWidget
+from z3c.form.interfaces import IErrorViewSnippet
+
+from Products.Five import zcml
+from Products.Five import fiveconfigure
+from Testing import ZopeTestCase as ztc
+from Products.PloneTestCase.layer import onsetup
+from Products.PloneTestCase import PloneTestCase as ptc
+
+from quintagroup.captcha.core.utils import decrypt, getWord, parseKey
+from quintagroup.captcha.core.tests.base import testPatch
+from quintagroup.captcha.core.tests.testWidget import addTestLayer
+
+from quintagroup.z3cform.captcha import Captcha
+from quintagroup.z3cform.captcha import CaptchaWidget
+from quintagroup.z3cform.captcha import CaptchaWidgetFactory
+from quintagroup.z3cform.captcha.validator import CaptchaValidator
+
+
+@onsetup
+def setup_product():
+ fiveconfigure.debug_mode = True
+ # Register z3c namespace first (work before plone-3.3)
+ import z3c.form
+ zcml.load_config('meta.zcml', z3c.form)
+ # Now register quintagroup.z3cform.captcha package
+ import quintagroup.captcha.core
+ import quintagroup.z3cform.captcha
+ zcml.load_config('configure.zcml', quintagroup.z3cform.captcha)
+ fiveconfigure.debug_mode = False
+ ztc.installPackage('quintagroup.captcha.core')
+
+setup_product()
+ptc.setupPloneSite(extension_profiles=['quintagroup.captcha.core:default', ])
+
+
+class TestRegistrations(ptc.PloneTestCase):
+
+ def afterSetUp(self):
+ self.request = self.app.REQUEST
+ alsoProvides(self.request, IFormLayer)
+
+ def testCaptchaFieldInterface(self):
+ self.assertEqual(IField.implementedBy(Captcha), True)
+
+ def testCaptchaWidgetInterface(self):
+ self.assertEqual(
+ IFieldWidget.implementedBy(CaptchaWidgetFactory), True)
+
+ def testWidgetRegistration(self):
+ cfield = Captcha()
+ cwidget = queryMultiAdapter((cfield, self.request), IFieldWidget)
+ self.assertNotEqual(cwidget, None)
+
+ def testValidatorRegistration(self):
+ cfield = Captcha()
+ cvalidator = queryMultiAdapter(
+ (None, self.request, None, cfield, None),
+ IValidator)
+ self.assertNotEqual(cvalidator, None)
+
+ def testErrorViewRegistration(self):
+ cfield = Captcha()
+ cwidget = queryMultiAdapter((cfield, self.request), IFieldWidget)
+ error = ValueError()
+ eview = queryMultiAdapter(
+ (error, self.request, cwidget, cfield, None, None),
+ IErrorViewSnippet)
+ self.assertNotEqual(eview, None)
+
+
+class TestCaptchaWidget(ptc.PloneTestCase):
+
+ def afterSetUp(self):
+ self.request = self.app.REQUEST
+ alsoProvides(self.request, IFormLayer)
+
+ cform = form.BaseForm(self.portal, self.request)
+ cform.prefix = ""
+ cwidget = CaptchaWidget(self.request)
+ cwidget.form = cform
+ self.html = cwidget.render()
+
+ def testHidden(self):
+ HIDDENTAG = ']*(?:' \
+ '(?:type="hidden"\s*)|' \
+ '(?:name="hashkey"\s*)|' \
+ '(?:value="(?P[0-9a-fA-F]+)"\s*)' \
+ '){3}/>'
+ open('/tmp/z3c.form.html', 'w').write(self.html)
+ hidden = re.search(HIDDENTAG, self.html)
+ self.assertTrue(hidden and hidden.group('value'))
+
+ def testImg(self):
+ IMAGETAG = ']*src=\"' \
+ '(?P[^\"]*/getCaptchaImage/[0-9a-fA-F]+)' \
+ '\"[^>]*>'
+ img = re.search(IMAGETAG, self.html)
+ self.assertTrue(img and img.group('src'))
+
+ def testTextField(self):
+ FIELDTAG = ']*type=\"text\"\s*[^>]*>'
+ self.assertEqual(re.search(FIELDTAG, self.html) is not None, True)
+
+
+class TestCaptchaValidator(ptc.PloneTestCase):
+
+ def afterSetUp(self):
+ self.request = self.app.REQUEST
+ alsoProvides(self.request, IFormLayer)
+ # prepare context
+ self.loginAsPortalOwner()
+ testPatch()
+ addTestLayer(self)
+ self.captcha_key = self.portal.captcha_key
+ # prepare captcha data
+ self.hashkey = self.portal.getCaptcha()
+ self.request.form['hashkey'] = self.hashkey
+ # prepare validator
+ cform = form.BaseForm(self.portal, self.request)
+ cform.prefix = ""
+ cwidget = CaptchaWidget(self.request)
+ cwidget.form = cform
+ self.validator = CaptchaValidator(self.portal, self.request, None,
+ None, cwidget)
+
+ def testSubmitRightCaptcha(self):
+ decrypted = decrypt(self.captcha_key, self.hashkey)
+ key = getWord(int(parseKey(decrypted)['key']) - 1)
+ try:
+ self.validator.validate(key)
+ except ConversionError, e:
+ self.fail("Rised unexpected %s error on right captcha submit" % e)
+
+ def testSubmitWrongCaptcha(self):
+ try:
+ self.validator.validate("wrong key")
+ except ValueError, e:
+ self.assertEqual(str(e), u'Please re-enter validation code.')
+ else:
+ self.fail("No ValueError rised on wrong captcha key submit")
+
+ def testSubmitRightCaptchaTwice(self):
+ decrypted = decrypt(self.captcha_key, self.hashkey)
+ key = getWord(int(parseKey(decrypted)['key']) - 1)
+ self.validator.validate(key)
+ try:
+ self.validator.validate(key)
+ except ValueError, e:
+ self.assertEqual(str(e), u'Please re-enter validation code.')
+ else:
+ self.fail("No ValueError rised on right captcha key "
+ "submitting twice")
+
+
+def test_suite():
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.makeSuite(TestRegistrations))
+ suite.addTest(unittest.makeSuite(TestCaptchaWidget))
+ suite.addTest(unittest.makeSuite(TestCaptchaValidator))
+ return suite
Index: quintagroup.z3cform.captcha/tags/1.0.2/quintagroup/z3cform/captcha/validator.py
===================================================================
--- quintagroup.z3cform.captcha/tags/1.0.2/quintagroup/z3cform/captcha/validator.py (revision 3614)
+++ quintagroup.z3cform.captcha/tags/1.0.2/quintagroup/z3cform/captcha/validator.py (revision 3614)
@@ -0,0 +1,52 @@
+from DateTime import DateTime
+
+from zope.interface import Interface
+from zope.component import adapts
+from zope.i18n import MessageFactory
+
+from Products.CMFCore.utils import getToolByName
+
+from quintagroup.captcha.core.utils import decrypt, parseKey, encrypt1, getWord
+
+from z3c.form.validator import SimpleFieldValidator
+
+from quintagroup.z3cform.captcha.interfaces import ICaptcha
+
+_ = MessageFactory('quintagroup.z3cform.captcha')
+
+
+class CaptchaValidator(SimpleFieldValidator):
+ """Captcha validator"""
+
+ adapts(Interface, Interface, Interface, ICaptcha, Interface)
+
+ def validate(self, value):
+ # Verify the user input against the captcha
+ if 'kss_z3cform_inline_validation' in self.request['URL']:
+ return
+ context = self.context
+ request = self.request
+ value = value or ''
+ captcha_type = context.getCaptchaType()
+ if captcha_type in ['static', 'dynamic']:
+ hashkey = request.get('%shashkey' % self.widget.form.prefix, '')
+ decrypted_key = decrypt(context.captcha_key, hashkey)
+ parsed_key = parseKey(decrypted_key)
+
+ index = parsed_key['key']
+ date = parsed_key['date']
+
+ if captcha_type == 'static':
+ img = getattr(context, '%s.jpg' % index)
+ solution = img.title
+ enc = encrypt1(value)
+ else:
+ enc = value
+ solution = getWord(int(index))
+
+ captcha_tool = getToolByName(context, 'portal_captchas')
+ if (enc != solution) or (captcha_tool.has_key(decrypted_key)) or \
+ (DateTime().timeTime() - float(date) > 3600):
+ raise ValueError(_(u'Please re-enter validation code.'))
+ else:
+ captcha_tool.addExpiredKey(decrypted_key)
Index: quintagroup.z3cform.captcha/tags/1.0.2/quintagroup/z3cform/captcha/widget.py
===================================================================
--- quintagroup.z3cform.captcha/tags/1.0.2/quintagroup/z3cform/captcha/widget.py (revision 3614)
+++ quintagroup.z3cform.captcha/tags/1.0.2/quintagroup/z3cform/captcha/widget.py (revision 3614)
@@ -0,0 +1,46 @@
+from zope.interface import implementer
+
+from z3c.form import interfaces
+from z3c.form import widget
+
+from Products.CMFCore.utils import getToolByName
+
+from z3c.form.browser.text import TextWidget
+
+
+class CaptchaError(Exception):
+ def __init__(self, value):
+ self.value = value
+
+ def __str__(self):
+ return repr(self.value)
+
+
+class CaptchaWidget(TextWidget):
+
+ def getCaptcha(self):
+ try:
+ return self.form.context.getCaptcha()
+ except AttributeError:
+ raise CaptchaError('quintagroup.captcha.core not installed. '
+ 'Install quintagroup.captcha.core using '
+ 'Quickinstaller or Plone Control Panel')
+
+ def render(self):
+ key = self.getCaptcha()
+ portal_url = getToolByName(self.form.context, 'portal_url')()
+ image_url = "%s/getCaptchaImage/%s" % (portal_url, key)
+
+ return u"""
+ %s
+ """ % (
+ key,
+ self.form.prefix,
+ super(CaptchaWidget, self).render(),
+ image_url)
+ return super(CaptchaWidget, self).template(self)
+
+
+@implementer(interfaces.IFieldWidget)
+def CaptchaWidgetFactory(field, request):
+ return widget.FieldWidget(field, CaptchaWidget(request))
Index: quintagroup.z3cform.captcha/tags/1.0.2/setup.py
===================================================================
--- quintagroup.z3cform.captcha/tags/1.0.2/setup.py (revision 3614)
+++ quintagroup.z3cform.captcha/tags/1.0.2/setup.py (revision 3614)
@@ -0,0 +1,55 @@
+from setuptools import setup, find_packages
+import os
+
+version = '1.0.2'
+
+setup(name='quintagroup.z3cform.captcha',
+ version=version,
+ description="Captcha field for z3cform based on "
+ "quintagroup.captcha.core package",
+ long_description=open("README.txt").read() + "\n" +
+ open(os.path.join("docs", "HISTORY.txt")).read(),
+ classifiers=[
+ "Development Status :: 5 - Production/Stable",
+ "Environment :: Web Environment",
+ "Framework :: Plone",
+ "Framework :: Plone :: 3.2",
+ "Framework :: Plone :: 3.3",
+ "Framework :: Plone :: 4.0",
+ "Framework :: Plone :: 4.1",
+ "Framework :: Plone :: 4.2",
+ "Framework :: Plone :: 4.3",
+ "Framework :: Zope2",
+ "Framework :: Zope3",
+ "License :: OSI Approved :: GNU General Public License (GPL)",
+ "Operating System :: OS Independent",
+ "Programming Language :: Python",
+ "Topic :: Security",
+ "Topic :: Software Development :: Libraries :: Python Modules",
+ ],
+ keywords='plone z3c form captcha',
+ author='Quintagroup',
+ author_email='support@quintagroup.com',
+ url='http://svn.quintagroup.com/products/quintagroup.z3cform.captcha/',
+ license='GPL',
+ packages=find_packages(exclude=['ez_setup']),
+ namespace_packages=['quintagroup', 'quintagroup.z3cform'],
+ include_package_data=True,
+ zip_safe=False,
+ install_requires=[
+ 'setuptools',
+ 'quintagroup.captcha.core',
+ 'z3c.form',
+ # 'zope.schema',
+ # 'zope.i18n',
+ # 'zope.component',
+ # 'zope.interface',
+ # 'zope.app.pagetemplate',
+ # 'Products.CMFCore',
+ ],
+ entry_points="""
+ # -*- Entry points: -*-
+ [z3c.autoinclude.plugin]
+ target = plone
+ """,
+ )