source: products/quintagroup.plonecomments/trunk/quintagroup/plonecomments/skins/quintagroup_plonecomments/validate_report_abuse.vpy @ 1628

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

Fixed validation scripts parameters

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=message='', email='', require_email=False, comment_id=None
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
15try:
16    content = context.parentsInThread()[0]
17except AttributeError:
18    content = context
19
20pm = getToolByName(context, 'portal_membership')
21pp = getToolByName(context, 'portal_properties')
22if pm.isAnonymousUser():
23    if not pp.qPloneComments.getProperty('enable_anonymous_report_abuse'):
24        raise Exception, "Abuse Report not allowed."
25else:
26    if not pp.qPloneComments.getProperty('enable_authenticated_report_abuse'):
27        raise Exception, "Abuse Report not allowed."
28
29if not message:
30    state.setError('message', PloneMessageFactory(u'Please submit a message.'), 'message_required')
31
32if require_email:
33    if not (email and context.portal_registration.isValidEmail(email)):
34        state.setError('email', _(u'Please submit an email address.'), 'email_required')
35
36if hasattr(context, 'captcha_validator'):
37    context.captcha_validator()
38
39isForAnonymous = pp['qPloneComments'].getProperty('enable_anonymous_commenting', None)
40if isForAnonymous:
41    pm = getToolByName(context, 'portal_membership')
42    isAnonym = pm.isAnonymousUser()
43    if isAnonym:
44        req = context.REQUEST
45        if not (req.form.has_key('creator') and not req.form['creator'] == ""):
46            state.setError('creator', _(u'Please enter your name.'), 'name_required')
47
48        try:
49            captcha_view = context.restrictedTraverse('@@captcha')
50            if not captcha_view.verify(captcha):
51                state.setError('captcha', _(u'You must correctly enter the word.'), 'captcha')
52        except:
53            # no collective.captcha installed
54            pass
55
56if state.getErrors():
57    context.plone_utils.addPortalMessage(_(u'Please correct the indicated errors.'))
58    return state.set(status='failure')
59else:
60    return state
Note: See TracBrowser for help on using the repository browser.