moving SQL statements to top of defs
This commit is contained in:
parent
0628289681
commit
0ad23e9be4
28
main.py
28
main.py
@ -23,48 +23,36 @@ app.register_blueprint(routes)
|
|||||||
@app.route('/hkfc-d/vote-chart', methods=['GET', 'POST'])
|
@app.route('/hkfc-d/vote-chart', methods=['GET', 'POST'])
|
||||||
def hkfc_d_vote_chart():
|
def hkfc_d_vote_chart():
|
||||||
form = LoginForm()
|
form = LoginForm()
|
||||||
print('Here we are')
|
user_lookup = "SELECT username FROM hockeyUsers WHERE (username= '" + form.username.data + "')"
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
sql = "SELECT username FROM hockeyUsers WHERE (username= '" + form.username.data + "')"
|
rows = sql_read(user_lookup)
|
||||||
print(sql)
|
|
||||||
rows = sql_read(sql)
|
|
||||||
print(rows)
|
|
||||||
return redirect(url_for('/hkfc-d/voting'))
|
return redirect(url_for('/hkfc-d/voting'))
|
||||||
# return '<h1>Something went wrong there</h1>'
|
else:
|
||||||
|
return render_template('hkfc-d/login-vote.html', form=form)
|
||||||
return render_template('hkfc-d/login-vote.html', form=form)
|
|
||||||
|
|
||||||
@app.route('/login', methods=['GET', 'POST'])
|
@app.route('/login', methods=['GET', 'POST'])
|
||||||
def login():
|
def login():
|
||||||
form = LoginForm()
|
form = LoginForm()
|
||||||
print('Here we are')
|
user_lookup = "SELECT username FROM hockeyUsers WHERE (username= '" + form.username.data + "')"
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
sql = "SELECT username FROM hockeyUsers WHERE (username= '" + form.username.data + "')"
|
rows = sql_write(user_lookup)
|
||||||
print(sql)
|
|
||||||
rows = sql_write(sql)
|
|
||||||
print(rows)
|
|
||||||
print(rows[0])
|
|
||||||
return redirect(url_for('/hkfc-d/voting'))
|
return redirect(url_for('/hkfc-d/voting'))
|
||||||
else:
|
else:
|
||||||
return 'Something went wrong'
|
return 'Something went wrong'
|
||||||
# return '<h1>Something went wrong there</h1>'
|
|
||||||
return render_template('login.html', form=form)
|
return render_template('login.html', form=form)
|
||||||
|
|
||||||
@app.route('/register', methods=['GET', 'POST'])
|
@app.route('/register', methods=['GET', 'POST'])
|
||||||
def register():
|
def register():
|
||||||
form = RegisterForm()
|
form = RegisterForm()
|
||||||
|
user_create = "INSERT INTO hockeyUsers (username, email, password) VALUES ('" + form.username.data + "', '" + form.email.data + "', '" + hashed_password + "')"
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
salt = uuid.uuid4().hex
|
salt = uuid.uuid4().hex
|
||||||
hashed_password = hashlib.sha512(form.password.data + salt).hexdigest()
|
hashed_password = hashlib.sha512(form.password.data + salt).hexdigest()
|
||||||
|
|
||||||
sql = "INSERT INTO hockeyUsers (username, email, password) VALUES ('" + form.username.data + "', '" + form.email.data + "', '" + hashed_password + "')"
|
|
||||||
print(sql)
|
|
||||||
db = write_cloudsql()
|
db = write_cloudsql()
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
cursor.execute(sql)
|
cursor.execute(user_create)
|
||||||
db.commit()
|
db.commit()
|
||||||
return '<h2>New user has been created!</h2>'
|
return '<h2>New user has been created!</h2>'
|
||||||
|
|
||||||
return render_template('register.html', form=form)
|
return render_template('register.html', form=form)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@ -18,9 +18,8 @@ basic_auth = BasicAuth(app)
|
|||||||
|
|
||||||
@routes.route('/convenor/clubList')
|
@routes.route('/convenor/clubList')
|
||||||
def convenorListClub():
|
def convenorListClub():
|
||||||
sql = "SELECT club, team, league from _clubTeams ORDER BY club, team"
|
clubTeam_lookup = "SELECT club, team, league from _clubTeams ORDER BY club, team"
|
||||||
rows = sql_read(sql)
|
rows = sql_read(clubTeam_lookup)
|
||||||
print(rows)
|
|
||||||
table = clubList(rows)
|
table = clubList(rows)
|
||||||
table.border = True
|
table.border = True
|
||||||
table.classes = ['table-striped', 'table-condensed', 'table-hover']
|
table.classes = ['table-striped', 'table-condensed', 'table-hover']
|
||||||
@ -34,22 +33,21 @@ def convenorAddClub():
|
|||||||
|
|
||||||
@routes.route('/convenor/clubAddResult', methods=['POST'])
|
@routes.route('/convenor/clubAddResult', methods=['POST'])
|
||||||
def convenorAddClubResult():
|
def convenorAddClubResult():
|
||||||
|
club_lookup = "SELECT club FROM _clubTeams WHERE club='" + _club + "' GROUP BY club"
|
||||||
|
club_create = "INSERT INTO _clubTeams (club, team) VALUES ('" + _club + "', 'A')"
|
||||||
try:
|
try:
|
||||||
_club = request.form['clubName']
|
_club = request.form['clubName']
|
||||||
# validate that this data has been entered
|
# validate that this data has been entered
|
||||||
if _club and request.method == 'POST':
|
if _club and request.method == 'POST':
|
||||||
sql = "SELECT club FROM _clubTeams WHERE club='" + _club + "' GROUP BY club"
|
clubExist = sql_read(club_lookup)
|
||||||
clubExist = sql_read(sql)
|
|
||||||
if clubExist:
|
if clubExist:
|
||||||
return 'Club already exists - try adding a team instead'
|
return 'Club already exists - try adding a team instead'
|
||||||
else:
|
else:
|
||||||
sql2 = "INSERT INTO _clubTeams (club, team) VALUES ('" + _club + "', 'A')"
|
sql_write(club_create)
|
||||||
sql_write(sql2)
|
|
||||||
return render_template('_convenorClubAddResults.html', data=_club)
|
return render_template('_convenorClubAddResults.html', data=_club)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
|
|
||||||
@routes.route('/convenor/teamAdd')
|
@routes.route('/convenor/teamAdd')
|
||||||
def convenorAddTeam():
|
def convenorAddTeam():
|
||||||
sql = "SELECT club FROM _clubTeams GROUP BY club ORDER BY club"
|
sql = "SELECT club FROM _clubTeams GROUP BY club ORDER BY club"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user