Example #1
0
def verify_action_token(token):
    if not g.user:
        return False
    user = g.user
    key = "action_token_{}".format(token)
    user_id = cache.get(key)
    if user_id:
        cache.delete(key)
        return user_id == user.id
    return False
Example #2
0
 def validate_csrf_data(self, data):
     if not validate_csrf(data, self.SECRET_KEY, self.TIME_LIMIT):
         return False
     cache_value = cache.get(data)
     cache.delete(data)
     if cache_value is not None:
         if cache_value == 0:
             return True
         return cache_value == g.user.id
     return False
Example #3
0
 def validate_csrf_data(self, data):
     if not validate_csrf(data, self.SECRET_KEY, self.TIME_LIMIT):
         return False
     key = "csrf_%s" % data
     cache_value = cache.get(key)
     cache.delete(key)
     if cache_value is not None:
         if cache_value == 0:
             return True
         return cache_value == g.user.id
     return False
Example #4
0
 def validate_csrf_data(self, data):
     if current_app.debug:
         return True
     if not validate_csrf(data, self.SECRET_KEY, self.TIME_LIMIT):
         return False
     cache_value = cache.get(data)
     cache.delete(data)
     if cache_value is not None:
         if cache_value == 0:
             return True
         return cache_value == g.user.id
     return False
Example #5
0
def _clear_cache(sender, changes):
    for model, operation in changes:
        if isinstance(model, Account) and operation != 'update':
            cache.delete('status-account')
        if isinstance(model, Node) and operation != 'update':
            cache.delete('status-node')
        if isinstance(model, Topic) and operation != 'update':
            cache.delete('status-topic')
        if isinstance(model, Reply) and operation != 'update':
            cache.delete('status-reply')
Example #6
0
def _clear_cache(sender, changes):
    for model, operation in changes:
        if isinstance(model, Account) and operation != 'update':
            cache.delete('status-account')
        if isinstance(model, Node) and operation != 'update':
            cache.delete('status-node')
        if isinstance(model, Topic) and operation != 'update':
            cache.delete('status-topic')
        if isinstance(model, Reply) and operation != 'update':
            cache.delete('status-reply')
Example #7
0
 def clear_read(self):
     cache.delete(self.read_cache_key)
     ReadTopic.query.filter_by(topic=self).delete()