From d6beb7a0405c40d222b4467f9c3abf1511645229 Mon Sep 17 00:00:00 2001 From: Jonathan Ervine Date: Fri, 20 Nov 2020 14:58:31 +0800 Subject: [PATCH] Adding cookie id - removing motm vote SQL' --- routes/_hkfcD_motm.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/routes/_hkfcD_motm.py b/routes/_hkfcD_motm.py index b4bba3e..25e4e46 100644 --- a/routes/_hkfcD_motm.py +++ b/routes/_hkfcD_motm.py @@ -19,6 +19,9 @@ basic_auth = BasicAuth(app) @routes.route('/hkfc-d/motm/') def hkfcD_motm_vote(randomUrlSuffix): + identity = randomUrlSuffix(8) + id_commit = "INSERT INTO motmSessions (sessionID) VALUES (identity))" + sql_write(id_commit) sql = "SELECT playerNumber, playerForenames, playerSurname, playerNickname FROM _hkfcD_matchSquad ORDER BY RAND()" sql2 = "SELECT nextClub, nextTeam, nextDate, oppoLogo, hkfcLogo, currMotM, currDotD, nextFixture FROM hkfcDAdminSettings" rows = sql_read(sql) @@ -53,7 +56,9 @@ def hkfcD_motm_vote(randomUrlSuffix): randomSuff = urlSuff[0]['motmUrlSuffix'] print(randomSuff) if randomSuff == randomUrlSuffix: - return render_template('_hkfcDMotmVote.html', data=rows, comment=comment, formatDate=formatDate, matchNumber=nextFixture, oppo=oppo, hkfcLogo=hkfcLogo, oppoLogo=oppoLogo, dotdURL=dotdURL, motmURL=motmURL, form=form) + resp = render_template('_hkfcDMotmVote.html', data=rows, comment=comment, formatDate=formatDate, matchNumber=nextFixture, oppo=oppo, hkfcLogo=hkfcLogo, oppoLogo=oppoLogo, dotdURL=dotdURL, motmURL=motmURL, form=form) + resp.setcookie('sessionID', id_commit) + return resp else: return render_template('_error.html') @@ -236,6 +241,9 @@ def hkfcD_vote_thanks(): _oppo = request.form['oppo'] if _motm and _dotd and request.method == 'POST': + identity = randomUrlSuffix(8) + id_commit = "INSERT INTO motmSessions (sessionID) VALUES (identity))" + 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 == "": @@ -245,10 +253,12 @@ def hkfcD_vote_thanks(): 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) - return render_template('_hkfcDVoteThanks.html') + #sql_write(sql3) + #sql_write(sql) + #sql_write(sql2) + resp = render_template('_hkfcDVoteThanks.html') + resp.setcookie('sessionID', commit_id) + return resp else: return 'Ouch ... something went wrong here' except Exception as e: