[1201] | 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 |
---|
[1628] | 8 | ##parameters=message='', email='', require_email=False, comment_id=None |
---|
[1201] | 9 | ##title=validates a discussion entry |
---|
| 10 | from Products.CMFCore.utils import getToolByName |
---|
| 11 | from Products.CMFPlone import MessageFactory |
---|
| 12 | from Products.CMFPlone import PloneMessageFactory |
---|
| 13 | _ = MessageFactory('quintagroup.plonecomments') |
---|
| 14 | |
---|
| 15 | try: |
---|
| 16 | content = context.parentsInThread()[0] |
---|
| 17 | except AttributeError: |
---|
| 18 | content = context |
---|
| 19 | |
---|
| 20 | pm = getToolByName(context, 'portal_membership') |
---|
| 21 | pp = getToolByName(context, 'portal_properties') |
---|
| 22 | if pm.isAnonymousUser(): |
---|
| 23 | if not pp.qPloneComments.getProperty('enable_anonymous_report_abuse'): |
---|
| 24 | raise Exception, "Abuse Report not allowed." |
---|
| 25 | else: |
---|
| 26 | if not pp.qPloneComments.getProperty('enable_authenticated_report_abuse'): |
---|
| 27 | raise Exception, "Abuse Report not allowed." |
---|
| 28 | |
---|
| 29 | if not message: |
---|
| 30 | state.setError('message', PloneMessageFactory(u'Please submit a message.'), 'message_required') |
---|
| 31 | |
---|
| 32 | if require_email: |
---|
[1639] | 33 | if not email: |
---|
[1201] | 34 | state.setError('email', _(u'Please submit an email address.'), 'email_required') |
---|
[1639] | 35 | elif not context.portal_registration.isValidEmail(email): |
---|
| 36 | state.setError('email', _(u'Please submit a valid e-mail address.'), 'email_required') |
---|
[1201] | 37 | |
---|
| 38 | if hasattr(context, 'captcha_validator'): |
---|
| 39 | context.captcha_validator() |
---|
| 40 | |
---|
| 41 | isForAnonymous = pp['qPloneComments'].getProperty('enable_anonymous_commenting', None) |
---|
| 42 | if isForAnonymous: |
---|
| 43 | pm = getToolByName(context, 'portal_membership') |
---|
| 44 | isAnonym = pm.isAnonymousUser() |
---|
| 45 | if isAnonym: |
---|
| 46 | req = context.REQUEST |
---|
| 47 | if not (req.form.has_key('creator') and not req.form['creator'] == ""): |
---|
| 48 | state.setError('creator', _(u'Please enter your name.'), 'name_required') |
---|
| 49 | |
---|
| 50 | try: |
---|
| 51 | captcha_view = context.restrictedTraverse('@@captcha') |
---|
| 52 | if not captcha_view.verify(captcha): |
---|
| 53 | state.setError('captcha', _(u'You must correctly enter the word.'), 'captcha') |
---|
| 54 | except: |
---|
| 55 | # no collective.captcha installed |
---|
| 56 | pass |
---|
| 57 | |
---|
| 58 | if state.getErrors(): |
---|
| 59 | context.plone_utils.addPortalMessage(_(u'Please correct the indicated errors.')) |
---|
| 60 | return state.set(status='failure') |
---|
| 61 | else: |
---|
| 62 | return state |
---|