Skip to content

Instantly share code, notes, and snippets.

@JoeGannon
Last active March 13, 2019 01:00
Show Gist options
  • Save JoeGannon/b973276dd275a0f9cb8611abbe47feb3 to your computer and use it in GitHub Desktop.
Save JoeGannon/b973276dd275a0f9cb8611abbe47feb3 to your computer and use it in GitHub Desktop.
from flask import Flask
from flask import request
from flask_httpauth import HTTPBasicAuth
app = Flask(__name__)
auth = HTTPBasicAuth()
users = {
}
cache = {}
@app.route('/read', methods=['POST'])
@auth.login_required
def hello():
move = cache['move']
cache['move'] = 'cleared'
return move
@app.route('/set', methods=['POST'])
@auth.login_required
def post_move():
cache['move'] = request.form.get('move')
return cache['move']
@app.route('/shutdown', methods=['POST'])
@auth.login_required
def shutdown():
request.environ.get('werkzeug.server.shutdown')()
return 'Server shutting down...'
@app.route('/secure')
@auth.login_required
def Secure():
return "Hello Bozo!"
@auth.get_password
def get_pw(username):
if username in users:
return users.get(username);
return None
app.run(host='0.0.0.0', port= 5000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment