# Unfortunately we needed more information, like the username that the ticket # belongs to so that content can be created with the correct ownership. And # the username retrieval is quite Zope2-specific. from Acquisition import aq_inner from collective.quickupload import logger from zope.security.interfaces import Unauthorized import AccessControl import random try: from zope.app.cache.ram import RAMCache except ImportError: from zope.ramcache.ram import RAMCache ticketCache = RAMCache() def issueTicket(ident): """ issues a timelimit ticket >>> type(issueTicket(object()))== type('') True """ ticket = str(random.random()) sm = AccessControl.getSecurityManager() user = sm.getUser() if user is None: raise Unauthorized('No currently authenticated user') ticketCache.set(user.getId(), ident, key=dict(ticket=ticket)) return ticket