-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
139 lines (115 loc) · 3.96 KB
/
app.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
##flask imports cc
from flask import Flask, request, render_template, session, redirect, url_for, flash
# ihelloltin imports
import json
# local packages
import db
app=Flask(__name__)
# The secret key MUST be set out side of the main if at the bottom
app.secret_key = "the secret key"
################################################################################
#
# Web page routes
#
################################################################################
@app.route("/login",methods=['GET','POST'])
def login():
"""
print a login page and either handle a login or register from the page.
use the nextpage argument in the request to forward to another page once
login is succesful (and store 'user' in the session)
"""
if request.method=='GET':
return render_template("login.html",next=request.args.get('nextpage',"/login"))
elif request.form['button']=='login':
user = request.form['username']
pw = request.form['password']
next = request.form['nextpage']
result = db.checkCredentials(user,pw)
if result==False:
flash("Invalid username or password")
return render_template("login.html",next=request.args.get('nextpage',"/login"))
session['user']=user
return redirect(next)
else:
# register
user = request.form['username']
pw = request.form['password']
next = request.form['nextpage']
result = db.addUser(user,pw)
if result==None:
flash("Couldn't add user");
return render_template("login.html",next=request.args.get('nextpage',"/login"))
else:
flash("Log in using new username and password")
return render_template("login.html",next=request.args.get('nextpage',"/login"))
@app.route("/logout")
def logout():
"""
"""
session.pop('user',None)
return redirect("/");
@app.route("/track")
def track():
"""
go to the map page showing users currently logged in - mostly javascript in track.js
"""
if 'user' not in session:
session['nextpage']=request.path
return redirect(url_for('login',nextpage=request.path))
return render_template("track.html",PAGENAME=request.path,user=session['user'])
@app.route("/stalk")
def stalk():
"""
does nothing right now
"""
if 'user' not in session:
session['nextpage']=request.path
return redirect(url_for('login',nextpage=request.path))
return render_template("placeholder.html",PAGENAME=request.path)
@app.route("/")
def index():
"""
Home page - doesn't do anything right now
"""
if 'user' not in session:
session['nextpage']=request.path
return redirect(url_for('login',nextpage=request.path))
return render_template("index.html")
################################################################################
#
# AJAX page routes
#
################################################################################
@app.route("/getCurrents")
def getCurrents():
"""
return a list of the current people on the system
fields include: name, timestamp, geo
geo includes: type (point), coordinates (lat,lng)
"""
return db.getCurrents()
@app.route("/updateCurrent")
def updateCurrent():
"""
modify database so it stores the current users current location
Must be logged in (hence the 'user' if up top
"""
if 'user' not in session:
session['nextpage']=request.path
return redirect(url_for('login',nextpage=request.path))
name=session['user']
lat = request.args.get('lat')
lng = request.args.get('long')
print lat,lng
loc=[lat,lng]
db.updateCurrent(name,loc)
return json.dumps(True)
################################################################################
#
# main
#
################################################################################
if __name__=="__main__":
app.debug=True
app.run(host="0.0.0.0",port=5000)