def log(self, session): session.update({ 'updated': datetime.utcnow().isoformat(), 'ua': self.request.environ.get('HTTP_USER_AGENT', 'unknown'), 'ip': get_ip(self.request), 'userid': self.user.getId(), 'id': self.session_id }) # default of 5 hr sessions # ideally this matches cookie timeout cache.set(self.cache_key, session, expire=60 * 60 * 5)
def issue_country_exception(self, user, country): # capture information about the request data = { 'referrer': self.request.get_header('REFERER'), 'user_agent': self.request.get_header('USER_AGENT'), 'ip': get_ip(self.request), 'username': user.getUserName(), 'userid': user.getId(), 'country': country, 'timestamp': time.time(), 'code': get_random_string(50), 'granted': False } cache_key = self.get_country_exception_cache_key(user.getId()) cache.set(cache_key, data, 12 * 60 * 60) # valid for 12 hours return data