mirror of
https://git.wownero.com/wownero/wownero-funding-system.git
synced 2024-08-15 00:53:45 +00:00
Include QR codes on the proposal page; added API route
This commit is contained in:
parent
75c7f49842
commit
531072d2aa
15 changed files with 191 additions and 21 deletions
|
@ -1,11 +1,13 @@
|
|||
from datetime import datetime
|
||||
from flask import request, redirect, Response, abort, render_template, url_for, flash, make_response, send_from_directory, jsonify
|
||||
from flask.ext.login import login_user , logout_user , current_user , login_required, current_user
|
||||
from flask import jsonify, send_from_directory, Response, request
|
||||
from flask_yoloapi import endpoint, parameter
|
||||
|
||||
import settings
|
||||
from funding.bin.utils import get_ip
|
||||
from funding.bin.qr import QrCodeGenerator
|
||||
from funding.factory import app, db_session
|
||||
from funding.orm.orm import Proposal, User
|
||||
|
||||
|
||||
@app.route('/api/1/proposals')
|
||||
@endpoint.api(
|
||||
parameter('status', type=int, location='args', default=1),
|
||||
|
@ -21,6 +23,7 @@ def api_proposals_get(status, cat, limit, offset):
|
|||
return 'error', 500
|
||||
return [p.json for p in proposals]
|
||||
|
||||
|
||||
@app.route('/api/1/convert/wow-usd')
|
||||
@endpoint.api(
|
||||
parameter('amount', type=int, location='args', required=True)
|
||||
|
@ -28,4 +31,33 @@ def api_proposals_get(status, cat, limit, offset):
|
|||
def api_coin_usd(amount):
|
||||
from funding.bin.utils import Summary, coin_to_usd
|
||||
prices = Summary.fetch_prices()
|
||||
return jsonify(usd=coin_to_usd(amt=amount, btc_per_coin=prices['coin-btc'], usd_per_btc=prices['btc-usd']))
|
||||
return jsonify(usd=coin_to_usd(amt=amount, btc_per_coin=prices['coin-btc'], usd_per_btc=prices['btc-usd']))
|
||||
|
||||
|
||||
@app.route('/api/1/qr')
|
||||
@endpoint.api(
|
||||
parameter('address', type=str, location='args', required=True)
|
||||
)
|
||||
def api_qr_generate(address):
|
||||
"""
|
||||
Generate a QR image. Subject to IP throttling.
|
||||
:param address: valid receiving address
|
||||
:return:
|
||||
"""
|
||||
from funding.factory import cache
|
||||
|
||||
throttling_seconds = 3
|
||||
ip = get_ip()
|
||||
cache_key = 'qr_ip_%s' % ip
|
||||
hit = cache.get(cache_key)
|
||||
if hit and ip not in ['127.0.0.1', 'localhost']:
|
||||
return Response('Wait a bit before generating a new QR', 403)
|
||||
cache.set(cache_key, {}, throttling_seconds)
|
||||
|
||||
qr = QrCodeGenerator()
|
||||
if not qr.exists(address):
|
||||
created = qr.create(address)
|
||||
if not created:
|
||||
raise Exception('Could not create QR code')
|
||||
|
||||
return send_from_directory('static/qr', '%s.png' % address)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue