I'm working on the next version of NCPC.org (currently targeting Plone 3.1.6)
and think I have a nicer solution (Matt can smack me if I'm wrong).

(1) Install qPloneCaptchas (
http://svn.quintagroup.com/products/qPloneCaptchas/tags/1.3.3/ )
(2) Install membrane and remember (I'm using the eggs so currently 1.1b3 and
1.1b1, respectively)
(3) Install custom usertype (NcpcUser) based on sampleremember.

Now, what I've done in the skins folder of NcpcUser is override some remember
skins files to incorporate qPloneCaptcha: reg_form.cpt, reg_form.cpt.metadata,
and validate_registration.vpy. The diffs are below.

Off-topic-but-related: I also override captcha_widget.pt in NcpcUser's skins
so I can color the field's background if the user gets the captcha wrong (see
http://talk.quintagroup.com/forums/plone-captchas/124119462 ).

Now, the captcha is tied to the registration form, not the user. And, we're no
longer dependent on an external captcha server (which has, on occasion, gone
down). And the captchas are prettier. :)

reg_form.cpt:
84c84
< <div metal:use-macro="here/captcha_widget/macros/captcha"></div>
---
>

reg_form.cpt.metadata
5c5
< validators = validate_registration
---
> validators = validate_registration, validate_base

validate_registration.vpy
11,32d10
<
< # This merges together code from
< # remember/validate_registration.vpy,
< # archetypes/validate_base.vpy,
< # and qplonecaptchas/captcha_validator.vpy
<
< from Products.Archetypes import PloneMessageFactory as _
< from Products.Archetypes.utils import addStatusMessage
<
< # Imports for qPloneCaptchas
< from Products.qPloneCaptchas import ProductMessageFactory
< from Products.CMFCore.utils import getToolByName
< from Products.qPloneCaptchas.utils import decrypt, parseKey, \
<      encrypt1, getWord
< from DateTime import DateTime
<
<
<
< request = context.REQUEST
< errors = {}
< errors = context.validate(REQUEST=request, errors=errors, data=1,
metadata=0)
<
52c30
<     state.setError('id', 'You did not enter a login name.', 'invalid_id')
---
>     state.setError('id', 'You did not enter an username.', 'invalid_id')
62,86c40,42
< # Validation for qPloneCaptchas
< test_key = request.get('key', '')
< hashkey = request.get('hashkey', '')
< decrypted_key = decrypt(context.captcha_key, hashkey)
< parsed_key = parseKey(decrypted_key)
<
< index = parsed_key['key']
< date = parsed_key['date']
<
< img = getattr(context, '%s.jpg' % index)
< solution = img.title
< enc = encrypt1(test_key)
< captcha_tool = getToolByName(context, 'portal_captchas')
< if test_key == '' or (enc != solution) or
(captcha_tool.has_key(decrypted_key)) \
<   or (DateTime().timeTime() - float(date)>3600):
<     state.setError('key',
<                    'Please re-enter validation code.',
<                    'key_required')
<
< errors.update(state.getErrors())
<
< if errors:
<     message = _(u'Please correct the indicated errors.')
<     addStatusMessage(request, message, type='error')
<     return state.set(status='failure', errors=errors)
---
> if state.getErrors():
>     return state.set(status='failure',
>                      portal_status_message='Please correct the indicated
> errors')
88,89d43
<     message = _(u'Changes saved.')
<     addStatusMessage(request, message)

Hope it helps!

On Aug 26, 2008 11:55 PM, David Bain wrote:
> Just tried it, works nicely, thanks Matt.
>
> On Tue, Aug 26, 2008 at 2:45 PM, Matt Bowen <[EMAIL PROTECTED]> wrote:
> > I implemented on on NCPC.org (http://www.ncpc.org/createMember) using
> > ATApcha (I think). The only weird part is that the CAPTCHA value is
> > persisted in the user's object, so every time the user updates his/her
> > prefs, s/he needs to complete the CAPTCHA again. Otherwise, it was pretty
> > painless.
> >
> > On Tue, Aug 26, 2008 at 3:36 PM, David Bain <[EMAIL PROTECTED]>wrote:
> >> Has anyone implemented a captcha field in remember? Asking because I'm
> >> about to do it.
> >> Any gotchas?

--
Archive: 
http://www.openplans.org/projects/remember/lists/remember/remember/remember/archive/2008/10/1224170892551
To unsubscribe send an email with subject "unsubscribe" to [EMAIL PROTECTED]  
Please contact [EMAIL PROTECTED] for questions.

Reply via email to