-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
49 lines (34 loc) · 1.29 KB
/
app.py
File metadata and controls
49 lines (34 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from flask import Flask, render_template, request, Response
from functools import wraps
from config import ADMIN_USER, ADMIN_PASSWORD, GOOGLE_API_KEY
from services import AuthenticationService, CheckinService, DatabaseService
app = Flask(__name__)
db_svc = DatabaseService()
db_svc.setup_tables()
auth_svc = AuthenticationService()
auth_svc.add_admin_user(ADMIN_USER, ADMIN_PASSWORD)
checkin_svc = CheckinService(db_svc)
def requires_auth(f):
@wraps(f)
def decorated(*args, **kwargs):
auth = request.authorization
if not auth or not auth_svc.authenticate(auth.username, auth.password):
return Response('Could not verify your access level for that URL.\n'
'You have to login with proper credentials', 401,
{'WWW-Authenticate': 'Basic realm="Login Required"'})
return f(*args, **kwargs)
return decorated
@app.route('/checkin', methods=['POST'])
def checkin():
data = request.form
try:
checkin_svc.checkin(data['name'], data['lat'], data['lng'])
except:
pass
@app.route('/admin')
@requires_auth
def admin():
checkins = checkin_svc.get_checkins()
return render_template('admin.html', checkins=checkins, google_api_key=GOOGLE_API_KEY)
if __name__ == '__main__':
app.run()