- Timestamp:
- 7 Jun 2025, 02:06:59 (5 days ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/branches/uli-recaptcha/src/waeup/kofa/zcml.py
r8057 r18083 17 17 ## 18 18 from zope.component.zcml import handler 19 from waeup.kofa.interfaces import IDataCenterConfig 19 from waeup.kofa.interfaces import IDataCenterConfig, IReCaptchaConfig 20 20 21 21 def data_center_conf(context, path): … … 49 49 {'path':path}, IDataCenterConfig, '') 50 50 ) 51 52 53 def recaptcha_conf(context, public_key, private_key, hostname, min_score): 54 """Handler for ZCML ``recaptcha`` directive. 55 56 Registers a global utility under IReCaptchaConfig and containing a 57 dictionary with entries: `enabled`, `public_key`, `private__key` and `url`. 58 59 The directive can be put into site.zcml like this: 60 61 - Add to the header: 62 ``xmlns:kofa="http://namespaces.waeup.org/kofa"`` 63 64 - Then, after including waeup.kofa: 65 ``<kofa:recaptcha 66 public_key="<YOUR_PUBKEY_HERE>" 67 private_key="<YOUR_PRIVKEY_HERE>" 68 hostname="mysite.com" 69 min_score="0.7" 70 />`` 71 72 In a running instance (where some directive like above was 73 processed during startup), one can then ask for the 74 IReCaptchaConfig utility: 75 76 >>> from waeup.kofa.interfaces import IReCaptchaConfig 77 >>> from zope.component import getUtility 78 >>> getUtility(IRecaptchaConfig) 79 {'enabled': False, 80 'public_key': '<GOOGLE_SITEKEY', 81 'private_key': 'GOOGLE_PRIVATE_SITE_KEY', 82 'hostname': 'mydomain.com' 83 'min_score': Decimal(0.7)} 84 85 """ 86 context.action( 87 discriminator = ('utility', IReCaptchaConfig, ''), 88 callable = handler, 89 args = ('registerUtility', 90 { 91 'public_key': public_key, 92 'private_key': private_key, 93 'hostname': hostname, 94 'min_score': min_score 95 }, IReCaptchaConfig, '') 96 )
Note: See TracChangeset for help on using the changeset viewer.