Changeset 7284
- Timestamp:
- 6 Dec 2011, 15:50:22 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/browser/captcha.py
r7283 r7284 24 24 import urllib2 25 25 from zope import schema 26 from zope.component import getUtilitiesFor 26 27 from zope.interface import Interface 27 28 from zope.publisher.interfaces.http import IHTTPRequest … … 91 92 By default we require no configuration data. 92 93 """ 94 95 class ICaptchaChooser(Interface): 96 """A chooser that collects available captchas. 97 """ 98 def getAvailCaptchas(self): 99 """Return a dict of available captchas with registered names as keys. 100 """ 101 102 def getCaptcha(self): 103 """Get captcha chosen for a certain site or default. 104 """ 105 106 def getConfigData(self, captcha): 107 """Get a dict of config data for a certain captcha. 108 """ 109 110 def setConfigData(self, captcha, key, value): 111 """Set a certain configuration key for a certain captcha. 112 """ 113 114 # 115 # Global captcha chooser 116 # 117 from zope.publisher.browser import TestRequest 118 class CaptchaChooser(grok.GlobalUtility): 119 120 grok.implements(ICaptchaChooser) 121 122 def getAvailCaptchas(self): 123 """Get all available captchas registered as utils for ICaptcha. 124 125 The default captcha (as it most probably is a copy of another 126 registered captcha) is left out of the result. 127 128 Result will be a dict with registration names as keys and the 129 specific captcha instances as values. 130 """ 131 result = getUtilitiesFor(ICaptcha) 132 return dict([x for x in result 133 if x != u'']) 134 135 def getCaptcha(self): 136 site = grok.getSite() 137 name = '' 138 if site is None: 139 # return the default captcha, registered without name 140 return getUtility(ICaptcha) 141 name = site.get('configuration', None).get('captcha', u'') 142 return getUtility(ICaptcha, name=name) 93 143 94 144 # … … 109 159 return 110 160 111 class NullCaptcha( grok.Adapter):161 class NullCaptcha(object): 112 162 """A captcha that does not expect any input. 113 163 … … 120 170 maintainer decides not to use it at all. 121 171 """ 122 grok.context(IHTTPRequest)123 172 grok.implements(ICaptcha) 124 grok.name('No captcha') 125 126 def __init__(self, context=None): 127 self.context = None 173 #grok.name(u'No captcha') 128 174 129 175 def verify(self, captcha_request): … … 133 179 return u'' 134 180 181 182 # This captcha is registered twice: one time as a 'no captcha' captcha 183 # and then also as the default captcha (with empty name) 184 grok.global_utility(NullCaptcha, name=u'No captcha') 185 grok.global_utility(NullCaptcha, name=u'') 135 186 136 187 #
Note: See TracChangeset for help on using the changeset viewer.