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

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

Fixed validating email

File size: 2.3 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:
34        state.setError('email', _(u'Please submit an email address.'), 'email_required')
35    elif not context.portal_registration.isValidEmail(email):
36        state.setError('email', _(u'Please submit a valid e-mail address.'), 'email_required')
37
38if hasattr(context, 'captcha_validator'):
39    context.captcha_validator()
40
41isForAnonymous = pp['qPloneComments'].getProperty('enable_anonymous_commenting', None)
42if 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
58if state.getErrors():
59    context.plone_utils.addPortalMessage(_(u'Please correct the indicated errors.'))
60    return state.set(status='failure')
61else:
62    return state
Note: See TracBrowser for help on using the repository browser.