forked from miketissenbaum/connectedspaces
-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
137 lines (117 loc) · 3.52 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
import os
import logins
from datetime import datetime
from flask import render_template, flash
from flask import Flask, request, jsonify, session, redirect, url_for
from flask.ext.mongokit import MongoKit, Document
import requests
app = Flask(__name__)
app.config['MONGODB_HOST'] = MONGO_IP[:-6]
app.config['MONGODB_DATABASE'] = "cspace"
# app.config['MONGODB_PORT'] = 27017
app.config['MONGODB_USERNAME'] = MONGO_USER
app.config['MONGODB_PASSWORD'] = MONGO_PASS
app.secret_key = logins.secret_key
app.config['SESSION_TYPE'] = 'filesystem'
checkCheck = False
isMember = False
isIn = False
member_name = ""
member_ID = ""
location = "Room 150"
class Members(Document):
__collection__ = 'members'
structure = {
'name': unicode,
'currentActivity': unicode,
'MemberID': unicode,
'ZipCode': unicode,
'created_at': datetime,
}
required_fields = ['name']
default_values = {'created_at': datetime.utcnow}
use_dot_notation = True
class Activities(Document):
__collection__ = 'activities'
structure = {
'name': unicode,
'currentActivity': unicode,
'MemberID': unicode,
'location': unicode,
'loggedIn': datetime,
}
default_values = {'loggedIn': datetime.utcnow}
use_dot_notation = True
db = MongoKit(app)
db.register([Members])
db.register([Activities])
@app.route('/getSignIn', methods=['GET','POST'])
def getSignIn():
global checkCheck
global member_name
global member_ID
global isIn
print isIn
if(checkCheck == True):
print "Sending confirmation for check in";
list = {'newCheckin': checkCheck, 'isMember' : isMember,'member_ID' : member_ID, 'name' : member_name, 'isIn' : isIn}
checkCheck = False
return jsonify(list)
@app.route('/', methods=['GET', 'POST'])
@app.route('/index', methods=['GET', 'POST'])
def check_in():
if request.method == 'POST':
# global location
global member_ID
global checkCheck
global isMember
global isIn
checkCheck = True
member_ID = request.form['cardID']
print member_ID
if db.Members.find_one({'MemberID': {"$eq": member_ID}}) > 0:
isMember = True
if db.Activities.find_one({'MemberID': {"$eq": member_ID}}) > 0:
print "logged in"
isIn = True
signout = db.Activities.find({'MemberID': {"$eq": member_ID}})
for so in signout:
so.delete()
else:
print "not found"
print "existing member"
flash('Account already exists for ' +member_name +' memberID: ' +member_ID)
else:
print "new member"
return render_template('index.html')
@app.route('/signup', methods=["GET", "POST"])
def sign_up():
if request.method == 'POST':
global member_name
global member_ID
member = db.Members()
member_name = request.form['name']
member.name = member_name
member.ZipCode = request.form['ZipCode']
member.MemberID = member_ID.decode('utf-8')
member.save()
flash('Account created for ' +member_name +' memberID: ' +member_ID)
return redirect(url_for('activity'))
return render_template('signup.html')
@app.route('/select_activity', methods=["GET", "POST"])
def activity():
if request.method == 'POST':
global member_name
global member_ID
global location
activity = db.Activities()
activity.currentActivity = request.form['activity'].decode('utf-8')
activity.name = member_name.decode('utf-8')
activity.MemberID = member_ID.decode('utf-8')
activity.location = location.decode('utf-8')
activity.save()
flash('Activity saved for ' +activity.name +" with activity " +activity.currentActivity +" at "+location)
return redirect(url_for('check_in'))
return render_template('select_activity.html')
if __name__ == "__main__":
app.run(debug=True)