Added error checking

This commit is contained in:
Jonathan Ervine 2020-11-26 12:54:48 +08:00
parent 015f576429
commit 0fba68287e
2 changed files with 29 additions and 5 deletions

View File

@ -52,7 +52,6 @@ def hkfcD_motm_vote(randomUrlSuffix):
sql6 = "SELECT motmUrlSuffix FROM hockeyResults.hkfcDAdminSettings WHERE userid='admin'"
urlSuff = sql_read_static(sql6)
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)
else:
@ -235,11 +234,15 @@ 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)
if prev_identity:
vote_query = "SELECT dotd_" + _matchDate + " FROM motmSessions WHERE sessionID='" + prev_identity + "'"
vote_check = sql_read(vote_query)
vote_valid = vote_check[0]['dotd_" + _matchDate + "']
if not vote_check:
warn('Cookie exists but no record in DB - check: '+prev_identity)
return render_template('_hkfcDSmithersFail.html', sessionID=prev_identity)
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)
@ -264,11 +267,12 @@ def hkfcD_vote_thanks():
expire_date = datetime.now()
expire_date = expire_date + timedelta(days=90)
resp.set_cookie('sessionID', identity, expires=expire_date)
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"
@ -298,7 +302,6 @@ def hkfcD_vote_thanks():
@routes.route('/hkfc-d/vote-results')
def hkfcD_vote_results():
_matchDate = str(mySettings('fixture'))
print(_matchDate)
sql = "SELECT playerName, motm_" + _matchDate + ", dotd_" + _matchDate + " FROM _hkfc_d_motm WHERE (motm_" + _matchDate + " > '0') OR (dotd_" + _matchDate + " > '0')"
print(sql)
rows = sql_read(sql)
@ -367,7 +370,6 @@ def delPlayerFromSquad():
@routes.route('/hkfc-d/matchSquadReset')
def hkfcD_matchSquadReset():
_matchNumber = str(mySettings('fixture'))
print(_matchNumber)
sql1 = "RENAME TABLE _hkfcD_matchSquad TO _hkfcD_matchSquad_" + _matchNumber + ""
sql2 = "CREATE TABLE _hkfcD_matchSquad (playerNumber smallint UNIQUE, playerForenames varchar(50), playerSurname varchar(30), playerNickname varchar(30) NOT NULL, PRIMARY KEY (playerNumber))"
sql3 = "UPDATE hkfcDAdminSettings SET prevFixture='" + _matchNumber + "'"

View File

@ -0,0 +1,22 @@
<html>
<head>
<title>HKFC Men's D Team - MotM and DotD vote</title>
<link rel="stylesheet" media="screen" href ="/static/css/bootstrap.min.css">
<link rel="stylesheet" href="/static/css/bootstrap-theme.min.css">
<meta name="viewport" content = "width=device-width, initial-scale=1.0">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="/static/js/bootstrap.min.js"></script>
</head>
<h2>Something has gone wrong ...</h2>
<body>
It looks like something has gone wrong ...
<br>
Let Smithers know the following code:
{{ sessionID }}
<p>
<img src="https://storage.googleapis.com/hk-hockey-data/images/smithers-fail.gif"></img>
</p>
<a class="btn btn-primary" href="/dashboard" role="button">Home</a>
<a class="btn btn-info" href="/hkfc-d/comments" role="button">Comments</a>
</body>
</html>