Made SQL and timezones work

This commit is contained in:
Aaron Lee 2021-12-12 13:16:43 +00:00
parent 22ef472527
commit 2adbd4b4dc
3 changed files with 5 additions and 5 deletions

2
app.py
View file

@ -145,4 +145,4 @@ admin.add_link(MenuLink(name='Back to Home 返回一般管理', category='', url
admin.add_link(MenuLink(name='Logout 登出', category='', url='/logout')) admin.add_link(MenuLink(name='Logout 登出', category='', url='/logout'))
if __name__ == '__main__': if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=80) app.run(debug=True, host='0.0.0.0', port=5000)

1
db.sql
View file

@ -76,7 +76,6 @@ CREATE TABLE homerooms (
*/ */
); );
DELETE FROM submission WHERE grade=9;
CREATE TABLE submission ( CREATE TABLE submission (
id INT NOT NULL AUTO_INCREMENT, id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY (id), PRIMARY KEY (id),

View file

@ -190,7 +190,7 @@ def chgPassword():
<hr> <hr>
<small>This email was sent automatically. Please do not reply.<br> <small>This email was sent automatically. Please do not reply.<br>
這個郵件是自動發送的請不要回覆</small> 這個郵件是自動發送的請不要回覆</small>
""" % (str(datetime.now(tz)), request.form['new_username'], str(datetime.now(tz)), request.form['new_username'])) """ % (datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S"), request.form['new_username'], datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S"), request.form['new_username']))
flash( flash(
'修改密碼成功,請重新登入<br>Password changed successfully. Please login again.') '修改密碼成功,請重新登入<br>Password changed successfully. Please login again.')
return redirect('/') return redirect('/')
@ -284,9 +284,10 @@ def resetPassword():
""", (request.args.get('resetCode'),)) """, (request.args.get('resetCode'),))
user = cursor.fetchone() user = cursor.fetchone()
cursor.close() cursor.close()
dtnow = datetime.now(tz).replace(tzinfo=None)
if user == None: if user == None:
raise Exception('無此重置密碼代碼<br>Invalid reset password code') raise Exception('無此重置密碼代碼<br>Invalid reset password code')
if (datetime.now(tz) - datetime.strptime(user[2], '%Y-%m-%d %H:%M:%S')).seconds > 3600: if (dtnow - datetime.strptime(user[2], '%Y-%m-%d %H:%M:%S')).seconds > 3600:
cursor.execute("DELETE FROM forgot WHERE resetID = %s", (user[0],)) cursor.execute("DELETE FROM forgot WHERE resetID = %s", (user[0],))
db.commit() db.commit()
cursor.close() cursor.close()