diff --git a/routes/_hkfcD_motm.py b/routes/_hkfcD_motm.py
index e77f265..d1895e0 100644
--- a/routes/_hkfcD_motm.py
+++ b/routes/_hkfcD_motm.py
@@ -235,9 +235,80 @@ def hkfcD_vote_thanks():
if _motm and _dotd and request.method == 'POST':
prev_identity = request.cookies.get('sessionID')
user_agent = request.headers.get('User-Agent')
- warn(prev_identity)
+ warn("Previous identity found: "+prev_identity)
if prev_identity:
vote_query = "SELECT dotd_" + _matchDate + " FROM motmSessions WHERE sessionID='" + prev_identity + "'"
+ vote_check = sql_read(vote_query)
+ if not vote_check:
+ warn('Cookie exists but no record in DB - check: '+prev_identity)
+ return render_template('_hkfcDSmithersFail.html', sessionID=prev_identity)
+ else:
+ vote_valid = vote_check[0]['dotd_' + _matchDate ]
+ if vote_valid:
+ warn("Naughty, naughty, you've already voted!")
+ return render_template('_hkfcDVoteFraud.html', sessionID=prev_identity)
+ else:
+ sql = "INSERT INTO _hkfc_d_motm (playerNumber, playerName, motmTotal, motm_" + _matchDate + ") SELECT playerNumber, playerNickname, '1', '1' FROM _HKFC_players WHERE playerNumber='" + _motm + "' ON DUPLICATE KEY UPDATE motmTotal = motmTotal + 1, motm_" + _matchDate + " = motm_" + _matchDate + " + 1"
+ sql2 = "INSERT INTO _hkfc_d_motm (playerNumber, playerName, dotdTotal, dotd_" + _matchDate + ") SELECT playerNumber, playerNickname, '1', '1' FROM _HKFC_players WHERE playerNumber='" + _dotd + "' ON DUPLICATE KEY UPDATE dotdTotal = dotdTotal + 1, dotd_" + _matchDate + " = dotd_" + _matchDate + " + 1"
+ sql4 = "UPDATE motmSessions SET motm_" + _matchDate + "=" + _motm + " WHERE sessionID='" + prev_identity + "'"
+ sql5 = "UPDATE motmSessions SET dotd_" + _matchDate + "=" + _dotd + " WHERE sessionID='" + prev_identity + "'"
+ sql_write(sql4)
+ sql_write(sql5)
+ if _comments == "":
+ print("No comment")
+ elif _comments == "Optional comments added here":
+ print("No comment")
+ else:
+ ### The matchDate has been replaced with the matchNumber - this should be corrected at some point (via a fixture table lookup)
+ sql3 = "INSERT INTO _motmComments (_matchDate, opposition, comment) VALUES ('" + _matchDate + "', '" + _oppo + "', '" + _fixed_comments + "')"
+ sql_write(sql3)
+ sql_write(sql)
+ sql_write(sql2)
+ resp = make_response(render_template('_hkfcDVoteThanks.html'))
+ expire_date = datetime.now()
+ expire_date = expire_date + timedelta(days=90)
+
+ resp.set_cookie('sessionID', prev_identity, expires=expire_date)
+ return resp
+ else:
+ identity = randomUrlSuffix(8)
+ id_commit = "INSERT INTO motmSessions (sessionID) VALUES ('" + identity + "')"
+ ua_commit = "INSERT INTO motmSessions (userAgent) VALUES ('" + user_agent + "')"
+ sql_write(id_commit)
+ sql = "INSERT INTO _hkfc_d_motm (playerNumber, playerName, motmTotal, motm_" + _matchDate + ") SELECT playerNumber, playerNickname, '1', '1' FROM _HKFC_players WHERE playerNumber='" + _motm + "' ON DUPLICATE KEY UPDATE motmTotal = motmTotal + 1, motm_" + _matchDate + " = motm_" + _matchDate + " + 1"
+ sql2 = "INSERT INTO _hkfc_d_motm (playerNumber, playerName, dotdTotal, dotd_" + _matchDate + ") SELECT playerNumber, playerNickname, '1', '1' FROM _HKFC_players WHERE playerNumber='" + _dotd + "' ON DUPLICATE KEY UPDATE dotdTotal = dotdTotal + 1, dotd_" + _matchDate + " = dotd_" + _matchDate + " + 1"
+ if _comments == "":
+ print("No comment")
+ elif _comments == "Optional comments added here":
+ print("No comment")
+ else:
+ ### The matchDate has been replaced with the matchNumber - this should be corrected at some point (via a fixture table lookup)
+ sql3 = "INSERT INTO _motmComments (_matchDate, opposition, comment) VALUES ('" + _matchDate + "', '" + _oppo + "', '" + _fixed_comments + "')"
+ #sql_write(sql3)
+ #sql_write(sql)
+ #sql_write(sql2)
+ resp = make_response(render_template('_hkfcDVoteThanks.html'))
+ expire_date = datetime.now()
+ expire_date = expire_date + timedelta(days=90)
+
+ resp.set_cookie('sessionID', identity, expires=expire_date)
+ return resp
+ else:
+ return 'Ouch ... something went wrong here'
+ except Exception as e:
+ print(e)
+ finally:
+ print('Votes cast - thanks')
+
+@routes.route('/hkfc-d/vote-chicken', methods=[i'GET', 'POST'])
+def hkfcD_vote_chicken():
+ try:
+ prev_identity = request.cookies.get('sessionID')
+ user_agent = request.headers.get('User-Agent')
+ nextFixture = "SELECT nextFixture FROM hkfcDAdminSettings"
+ _matchDate = sql_read_static(nextFixture)
+ if prev_identity:
+ vote_query = "SELECT dotd_" + _matchDate + " FROM motmSessions WHERE sessionID='" + prev_identity + "'"
vote_check = sql_read(vote_query)
if not vote_check:
warn('Cookie exists but no record in DB - check: '+prev_identity)
@@ -298,7 +369,6 @@ def hkfcD_vote_thanks():
print(e)
finally:
print('Votes cast')
-
@routes.route('/hkfc-d/vote-results')
def hkfcD_vote_results():
_matchDate = str(mySettings('fixture'))
diff --git a/templates/_hkfcDMotmVote.html b/templates/_hkfcDMotmVote.html
index d703685..649f7b6 100644
--- a/templates/_hkfcDMotmVote.html
+++ b/templates/_hkfcDMotmVote.html
@@ -74,6 +74,7 @@
+ Chicken
Cancel