source: products/quintagroup.plonecomments/trunk/quintagroup/plonecomments/skins/quintagroup_plonecomments/validate_talkback.vpy @ 1840

Last change on this file since 1840 was 1639, checked in by kroman0, 14 years ago

Fixed validating email

File size: 2.2 KB
Line 
1## Controller Script Python "validate_talkback"
2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind state=state
7##bind subpath=traverse_subpath
8##parameters=subject='',body_text='', email='', require_email=False
9##title=validates a discussion entry
10from Products.CMFCore.utils import getToolByName
11from Products.CMFPlone import MessageFactory
12from Products.CMFPlone import PloneMessageFactory
13_ = MessageFactory("quintagroup.plonecomments")
14
15dtool = context.portal_discussion
16try:
17    content = context.parentsInThread()[0]
18except AttributeError:
19    content = context
20
21if not dtool.isDiscussionAllowedFor(content):
22    raise Exception, "Discussion not allowed."
23
24if not subject:
25    state.setError('subject', PloneMessageFactory(u'Please submit a subject.'), 'subject_required')
26
27if not body_text:
28    state.setError('body_text', PloneMessageFactory(u'Please submit a body.'), 'body_required')
29
30if require_email:
31    if not email:
32        state.setError('email', _(u'Please submit an email address.'), 'email_required')
33    elif not context.portal_registration.isValidEmail(email):
34        state.setError('email', _(u'Please submit a valid e-mail address.'), 'email_required')
35
36if hasattr(context, 'captcha_validator'):
37    context.captcha_validator()
38
39pp = getToolByName(context, 'portal_properties')
40isForAnonymous = pp['qPloneComments'].getProperty('enable_anonymous_commenting', None)
41if isForAnonymous:
42    pm = getToolByName(context, 'portal_membership')
43    isAnonym = pm.isAnonymousUser()
44    if isAnonym:
45        req = context.REQUEST
46        if not (req.form.has_key('Creator') and not req.form['Creator'] == ""):
47            state.setError('Creator', _(u'Please enter your name.'), 'name_required')
48
49        try:
50            captcha_view = context.restrictedTraverse('@@captcha')
51            if not captcha_view.verify(captcha):
52                state.setError('captcha', _(u'You must correctly enter the word.'), 'captcha')
53        except:
54            # no collective.captcha installed
55            pass
56
57if state.getErrors():
58    context.plone_utils.addPortalMessage(_(u'Please correct the indicated errors.'))
59    return state.set(status='failure')
60else:
61    return state
Note: See TracBrowser for help on using the repository browser.