def gen_action_token(length=40): if not g.user: return user = g.user token = gen_salt(length=length) cache.set("action_token_{}".format(token), user.id, timeout=300) return token
def generate_csrf_token(self, csrf_context=None): if not self.csrf_enabled: return None csrf = generate_csrf(self.SECRET_KEY, self.TIME_LIMIT) if g.user: cache_value = g.user.id else: cache_value = 0 cache.set("csrf_%s" % csrf, cache_value, self.TIME_LIMIT) return csrf
def generate_csrf_token(self, csrf_context=None): if not self.csrf_enabled: return None csrf = generate_csrf(self.SECRET_KEY, self.TIME_LIMIT) if g.user: cache_value = g.user.id else: cache_value = 0 cache.set(csrf, cache_value, self.TIME_LIMIT) return csrf
def mark_read(self, user): if self.have_read(user): return read_list = cache.get(self.read_cache_key) if read_list: read_list.append(user.id) else: read_list = [user.id] cache.set(self.read_cache_key, read_list) read_mark = ReadTopic(topic=self, user=user) db.session.add(read_mark) db.session.commit()
def get_site_status(): account, node, topic, reply = cache.get_many( 'status-account', 'status-node', 'status-topic', 'status-reply' ) if not account: account = Account.query.count() cache.set('status-account', account) if not node: node = Node.query.count() cache.set('status-node', node) if not topic: topic = Topic.query.count() cache.set('status-topic', topic) if not reply: reply = Reply.query.count() cache.set('status-reply', reply) return dict( account=account, node=node, topic=topic, reply=reply, )
def get_site_status(): account, node, topic, reply = cache.get_many('status-account', 'status-node', 'status-topic', 'status-reply') if not account: account = Account.query.count() cache.set('status-account', account) if not node: node = Node.query.count() cache.set('status-node', node) if not topic: topic = Topic.query.count() cache.set('status-topic', topic) if not reply: reply = Reply.query.count() cache.set('status-reply', reply) return dict( account=account, node=node, topic=topic, reply=reply, )