Last active
August 29, 2015 14:02
-
-
Save efruchter/a34e1e6a04da64b8d88e to your computer and use it in GitHub Desktop.
insecure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from flask import Flask, request, redirect, url_for | |
from werkzeug.utils import secure_filename | |
from flask import Flask, jsonify | |
from flask.ext.cors import cross_origin | |
app = Flask(__name__) | |
@app.route('/order', methods=['GET']) | |
@cross_origin() | |
def order(): | |
cost = request.args.get('cost') | |
amount = request.args.get('amount') | |
return jsonify({'amount' : amount, 'cost' : cost, 'error': 0}) | |
@app.route('/ordermediated', methods=['GET']) | |
@cross_origin() | |
def ordermediated(): | |
cost = request.args.get('cost') | |
amount = request.args.get('amount') | |
error = int(cost) != int(amount) * 45 | |
print int(cost), int(amount) | |
if error: | |
amount = int(amount) | |
cost = amount * 45 | |
return jsonify({'amount' : amount, 'cost' : cost, 'error': int(error)}) | |
if __name__ == '__main__': | |
app.run(debug=True,port=5000) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<html> | |
<head> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> | |
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css" /> | |
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script> | |
</head> | |
<body> | |
<strong>Premium Widgets</strong> | |
<br><br> | |
<strong># of Widgets:</strong> | |
<TABLE><TR><TD> | |
<div id="amount_slider"></div><input id="amount_input" value="0" readonly></input> | |
</TD></TR></TABLE> | |
<br><br> | |
Per Widget Price: $<input id="w_price" value="45" readonly></input> | |
<br><br> | |
Total: $<input id="price" value="0" readonly></input> | |
<br><br> | |
<input id="order_button" type="submit" value="Place Order"> | |
<input id="order_button2" type="submit" value="Place Order (mediated)"> | |
<br><br> | |
<div id="results"></div> | |
<script> | |
var request_url = "http://localhost:5000"; | |
$(function() { | |
$('#amount_slider').slider({ | |
range: "min", | |
value: 0, | |
min: 0, | |
max: 20, | |
slide: function( event, ui ) { | |
$('#price').val(ui.value * parseInt($("#w_price").val())); | |
$('#amount_input').val(ui.value); | |
} | |
}); | |
$("#order_button").click( function() { | |
$.get(request_url +"/order", { | |
amount: $("#amount_slider").slider( "values", 1 ), | |
cost: $('#price').val() | |
}).done(function( data ) { | |
if (data['error'] == '0') { | |
window.alert("Order placed for " + data['amount'] + " widgets at a total of $" + data['cost'] + "."); | |
} else { | |
window.alert("Cost error corrected! Order placed for " + data['amount'] + " widgets at a total of $" + data['cost'] + "."); | |
} | |
}); | |
}); | |
$("#order_button2").click( function() { | |
$.get(request_url +"/ordermediated", { | |
amount: $("#amount_slider").slider( "values", 1 ), | |
cost: $('#price').val() | |
}).done(function( data ) { | |
if (data['error'] == '0') { | |
window.alert("Order placed for " + data['amount'] + " widgets at a total of $" + data['cost'] + "."); | |
} else { | |
window.alert("Cost error corrected! Order placed for " + data['amount'] + " widgets at a total of $" + data['cost'] + "."); | |
} | |
}); | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment