def dispatch_request(self): config = app.config['yada_config'] mongo = app.config['yada_mongo'] if not request.args.get('rid'): return '{"error": "rid not in query params"}' result = BU.verify_message(config, mongo, request.args.get('rid'), session.get('siginin_code'), config.public_key, request.args.get('id').replace(' ', '+')) return json.dumps({'authenticated': True if result[1] else False})
def home(): session.setdefault('id', str(uuid.uuid4())) if request.method == 'POST': bulletin_secret = request.form.get('bulletin_secret', '') if not bulletin_secret: return redirect('/?error') # generate a transaction which contains a signin message containing the current sessions identifier txn = TransactionFactory(bulletin_secret=bulletin_secret, public_key=Config.public_key, private_key=Config.private_key, signin=session.get('id'), fee=0.01).transaction # send the transaction to our own serve instance, which saves it to miner_transactions # the miner looks in miner_transactions to include in a block when it finds a new block for peer in Peers.peers: print peer.host, peer.port requests.post("http://{host}:{port}/newtransaction".format( host=peer.host, port=peer.port), txn.to_json(), headers={"Content-Type": "application/json"}) return redirect('/?bulletin_secret=%s' % urllib.quote_plus(bulletin_secret)) elif request.method == 'GET': bulletin_secret = request.args.get('bulletin_secret', '') rid = TU.generate_rid(bulletin_secret) txns = BU.get_transactions_by_rid(rid, rid=True) txns2 = BU.get_transactions_by_rid(rid, rid=True, raw=True) half1 = False half2 = False for txn in txns: if txn['public_key'] == Config.public_key: half1 = True for txn in txns2: if txn['public_key'] != Config.public_key: half2 = True registered = half1 and half2 sent, received = BU.verify_message(rid, session['id']) session['loggedin'] = received return render_template('index.html', session_id=str(session.get('id')), registered=str(registered), sent=str(sent), received=str(received), loggedin=str(session['loggedin']), bulletin_secret=str(bulletin_secret), rid=str(rid)) else: return redirect('/')