Exemplo n.º 1
0
    def decorated_function(*args, **kwargs):
        if 'username' not in session:
            return response(error_code=1003)

        username = session['username']
        cache_key = 'user:{}'.format(username)
        user = cache.get(cache_key)
        if cache.get('user:{}'.format(username)) is None:
            user = Users.query.filter(Users.username == username).first()
            cache.set(cache_key, user, timeout=60)
        if user is None:
            session.pop('username', None)
            return response(error_code=1003)

        g.user = user

        return f(*args, **kwargs)
Exemplo n.º 2
0
 def decorated_function(*args, **kwargs):
     cache_key = key % request.path
     rv = cache.get(cache_key)
     if rv is not None:
         return rv
     rv = f(*args, **kwargs)
     cache.set(cache_key, rv, timeout=timeout)
     return rv
Exemplo n.º 3
0
def get_open_coins() -> [Coins]:
    cache_key = 'open_coins'
    coins = cache.get('open_coins')
    if coins is None:
        coins = Coins.query.filter(Coins.open.is_(True)).all()
        cache.set(cache_key, coins, timeout=60)

    return coins
Exemplo n.º 4
0
def get_coin_with_coin_name(coin_name) -> Coins:
    cache_key = 'coin:' + coin_name
    coin = cache.get(cache_key)

    if coin is None:
        coin = Coins.query.filter(Coins.name == coin_name).first()
        cache.set(cache_key, coin, timeout=600)

    return coin
Exemplo n.º 5
0
def get_address_user(address) -> Users:
    cache_key = 'user:'******'addressAccount').first()
        cache.set(cache_key, _user, timeout=600)

    return _user
Exemplo n.º 6
0
def get_last_ten_minute_pool_accepted_shares(coin_name):
    cache_key = 'last_accepted_shares:%s' % coin_name
    shares = cache.get(cache_key)

    if shares is None:
        shares = db.session.query(func.sum(Shares.pool_difficulty)).filter(Shares.coin_name == coin_name) \
            .filter(Shares.pool_result.is_(True)) \
            .filter(Shares.timestamp > (datetime.utcnow() - timedelta(minutes=10))).all()
        cache.set(cache_key, shares, timeout=60)

    return shares
Exemplo n.º 7
0
def get_block_history_by_paging(coin_name, page, count_per_page):
    cache_key = 'block_history:%s:%s' % (coin_name, page)
    history = cache.get(cache_key)

    if history is None:
        history = Block.query. \
            filter(Block.coin_name == coin_name). \
            filter(Block.mined.is_(True)). \
            order_by(Block.timestamp.desc()).paginate(page, count_per_page, error_out=False)
        cache.set(cache_key, history, timeout=60)

    return history
Exemplo n.º 8
0
def password_reset(uuid):
    username = cache.get(uuid)

    if username is None:
        return response(error_code=1000)

    temp_password = generate_random_string()
    _user = Users.query.filter(Users.username == username).first()
    _user.password = hashlib.sha256(temp_password.encode()).hexdigest()
    db.session.commit()

    if send_temp_password_email(_user.email, _user.username,
                                temp_password) is None:
        return response(error_code=1013)

    cache.delete(uuid)

    return response()