| 1 | from random import randint |
|---|
| 2 | |
|---|
| 3 | from Products.CMFCore.utils import getToolByName |
|---|
| 4 | |
|---|
| 5 | from quintagroup.captcha.core.config import CAPTCHA_KEY, CONFIGLET_ID, \ |
|---|
| 6 | ALL_LAYERS, PROPERTY_SHEET |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | def generateKey(length): |
|---|
| 10 | key = '' |
|---|
| 11 | for i in range(length): |
|---|
| 12 | key += str(randint(0, 9)) |
|---|
| 13 | return key |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | def setupVarious(context): |
|---|
| 17 | if context.readDataFile('quintagroup.captcha.core_various.txt') is None: |
|---|
| 18 | return |
|---|
| 19 | |
|---|
| 20 | site = context.getSite() |
|---|
| 21 | |
|---|
| 22 | # set captcha key |
|---|
| 23 | value = generateKey(8) |
|---|
| 24 | if site.hasProperty(CAPTCHA_KEY): |
|---|
| 25 | site._updateProperty(CAPTCHA_KEY, value) |
|---|
| 26 | else: |
|---|
| 27 | site._setProperty(CAPTCHA_KEY, value, 'string') |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | def uninstall(context): |
|---|
| 31 | # Only run step if a flag file is present (e.g. not an extension profile) |
|---|
| 32 | if context.readDataFile('quintagroup.captcha.core_uninstall.txt') is None: |
|---|
| 33 | return |
|---|
| 34 | |
|---|
| 35 | site = context.getSite() |
|---|
| 36 | |
|---|
| 37 | # remove configlet |
|---|
| 38 | cpt = getToolByName(site, 'portal_controlpanel') |
|---|
| 39 | if CONFIGLET_ID in [o.id for o in cpt.listActions()]: |
|---|
| 40 | cpt.unregisterConfiglet(CONFIGLET_ID) |
|---|
| 41 | |
|---|
| 42 | # remove property sheet |
|---|
| 43 | pp = getToolByName(site, 'portal_properties') |
|---|
| 44 | if PROPERTY_SHEET in pp.objectIds(): |
|---|
| 45 | pp.manage_delObjects(ids=[PROPERTY_SHEET]) |
|---|
| 46 | |
|---|
| 47 | # remove captcha key property |
|---|
| 48 | if site.hasProperty(CAPTCHA_KEY): |
|---|
| 49 | site._delProperty(CAPTCHA_KEY) |
|---|