Added HTTP Basic Auth
This commit is contained in:
@@ -1,13 +1,30 @@
|
||||
from functools import wraps
|
||||
from flask import Flask
|
||||
from flask import render_template, send_from_directory
|
||||
from flask import render_template, send_from_directory, request, Response
|
||||
import json, time
|
||||
app = Flask(__name__)
|
||||
|
||||
def check_auth(username, password):
|
||||
return username == 'davide' and password == 'pwd'
|
||||
|
||||
def authenticate():
|
||||
return Response('Could not verify access level. Please retry', 401, {'WWW-Authenticate' : 'Basic realm="Login Required"'})
|
||||
|
||||
def requires_auth(f):
|
||||
@wraps(f)
|
||||
def decorated(*args, **kwargs):
|
||||
auth = request.authorization
|
||||
if not auth or not check_auth(auth.username, auth.password):
|
||||
return authenticate()
|
||||
return f(*args, **kwargs)
|
||||
return decorated
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
return '{"onFire": false}'
|
||||
|
||||
@app.route('/status')
|
||||
@requires_auth
|
||||
def somehtml():
|
||||
history = []
|
||||
with open('history.json', 'r') as json_data:
|
||||
@@ -18,19 +35,23 @@ def somehtml():
|
||||
return render_template('status.html', events = history[::-1])
|
||||
|
||||
@app.route('/users')
|
||||
@requires_auth
|
||||
def users():
|
||||
return 'You have reached Users'
|
||||
|
||||
@app.route('/history')
|
||||
@requires_auth
|
||||
def history():
|
||||
return 'You have reached history'
|
||||
|
||||
@app.route('/getcardinfo/<cardID>')
|
||||
@requires_auth
|
||||
def getCardInfo(cardID):
|
||||
return send_from_directory('cards', cardID + '.json')
|
||||
|
||||
|
||||
@app.route('/addcard/<cardID>/<name>/<authCode>')
|
||||
@requires_auth
|
||||
def addCard(cardID, name, authCode):
|
||||
authCode = int(authCode)
|
||||
data = {}
|
||||
|
||||
Reference in New Issue
Block a user