diff --git a/fridge_lock.sublime-project b/ELAB-RFID-locks.sublime-project similarity index 100% rename from fridge_lock.sublime-project rename to ELAB-RFID-locks.sublime-project diff --git a/ELAB-RFID-locks.sublime-workspace b/ELAB-RFID-locks.sublime-workspace new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/ELAB-RFID-locks.sublime-workspace @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/server.py b/server.py index 923dc7a..a3d167e 100644 --- a/server.py +++ b/server.py @@ -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/') +@requires_auth def getCardInfo(cardID): return send_from_directory('cards', cardID + '.json') @app.route('/addcard///') +@requires_auth def addCard(cardID, name, authCode): authCode = int(authCode) data = {} diff --git a/server.pyc b/server.pyc index 2dd1b3d..c74721d 100644 Binary files a/server.pyc and b/server.pyc differ