-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathroutes.py
More file actions
146 lines (120 loc) · 4.8 KB
/
routes.py
File metadata and controls
146 lines (120 loc) · 4.8 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
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
138
139
from flask import Flask, request, render_template, session, redirect, url_for
from flask_sqlalchemy import SQLAlchemy
from random_key import *
from flask_login import LoginManager, UserMixin, login_user, logout_user, current_user
from datetime import datetime
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///databases/main.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['SECRET_KEY'] = 'Meme'
db = SQLAlchemy(app)
from models import Societies, Events, Users
## Flask-Login configs ##
login_manager = LoginManager()
login_manager.init_app(app)
login_manager.login_view='/'
@login_manager.user_loader
def load_user(user_id):
return Societies.query.get(int(user_id))
#########################
@app.route('/', methods = ['GET', 'POST'])
@app.route('/index', methods=['GET', 'POST'])
def index():
return render_template('index.html')
'''
@app.route('/profile/<user>', methods = ['GET']
if:
return render_template('profSoc.html')
else:
return render_template('profInd.html')
'''
@app.route('/soclogin', methods=['GET','POST'])
def soclogin():
if request.method == "POST":
username_check = request.form.get('username')
print (username_check)
password_check = request.form.get('password')
# query based on username
society = Societies.query.filter_by(username = username_check).first()
if (password_check == society.password):
login_user(society)
#"Logged in, welcome back " + str(society.name)
return redirect('socdash')
return render_template('soclogin.html')
@app.route('/stulogin', methods=['GET','POST'])
def stulogin():
if request.method == "POST":
zid_check = request.form.get('zid')
print (zid_check)
password_check = request.form.get('password')
# query based on username
user = Users.query.filter_by(zid = zid_check).first()
if (password_check == user.password):
login_user(user)
return redirect('index')
return render_template('stulogin.html')
@app.route('/sturegister', methods=['GET','POST'] )
def sturegister():
if request.method == "POST":
new_user = Users(zid = request.form.get('zid'),
name = request.form.get('name'),
arc = request.form.get('arc'),
password = request.form.get('password'))
db.session.add(new_user)
db.session.commit()
### TODO: REDIRECT TO LOGIN DASHBOARD
return "Thanks for registering, " + str(new_user.name)
return render_template('sturegister.html')
@app.route('/socregister', methods = ['GET', 'POST'])
def socregister():
if request.method == "POST":
new_soc = Societies(name = request.form.get('name'),
username = request.form.get('username'),
password = request.form.get('password'))
db.session.add(new_soc)
db.session.commit()
### TODO: REDIRECT TO LOGIN DASHBOARD
return "Thanks for registering, " + str(new_soc.name)
return render_template('socregister.html')
@app.route('/event/<int:event_id>', methods = ['GET', 'POST'])
def event(event_id):
event = Events.query.filter_by(id = event_id).one()
# handles POST method (play button to generate 6 digit code)
if request.method == "POST":
pushing_code = Events(secret_code = verify_key())
db.session.add(pushing_code)
db.session.commit()
# returns event specific page
return render_template('event.html', event = event)
@app.route('/create', methods = ['GET','POST'])
def create():
if request.method == "POST":
new_event = Events(name = request.form.get('name'),
location = request.form.get('location'),
#date = request.form.get('date'),
secret_code = "000000",
society = current_user.name)
db.session.add(new_event)
db.session.commit()
return render_template('newevent.html')
@app.route('/socdash', methods=['GET','POST'])
def socdash():
# query events based on society that's logged in
#curr_soc_events = Events.query.filter_by(name = "MEME SOC").all()
curr_soc_events = Events.query.order_by(Events.name.desc()).all()
return render_template('socdash.html', events=curr_soc_events, society = current_user.name)
@app.route('/studash', methods=['GET', 'POST'])
def studash():
# get input
if request.method == "POST":
user_input = request.form.get('input')
query = Events.query.filter_by(secret_code=str(user_input)).first()
# check if it matches
if query:
return "Thanks for registering!"
else:
return redirect('studash')
@app.route('/logout')
def logout():
logout_user
return redirect('/index')