From 2adbd4b4dc002e6406c3aa0a305c84559e5862af Mon Sep 17 00:00:00 2001 From: Aaron Lee Date: Sun, 12 Dec 2021 13:16:43 +0000 Subject: [PATCH] Made SQL and timezones work --- app.py | 2 +- db.sql | 3 +-- login.py | 5 +++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app.py b/app.py index 724f993..8349ebd 100644 --- a/app.py +++ b/app.py @@ -145,4 +145,4 @@ admin.add_link(MenuLink(name='Back to Home 返回一般管理', category='', url admin.add_link(MenuLink(name='Logout 登出', category='', url='/logout')) 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) diff --git a/db.sql b/db.sql index fae6e55..1ca23a6 100644 --- a/db.sql +++ b/db.sql @@ -76,7 +76,6 @@ CREATE TABLE homerooms ( */ ); -DELETE FROM submission WHERE grade=9; CREATE TABLE submission ( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (id), @@ -149,4 +148,4 @@ CREATE TABLE forgot ( resetID VARCHAR(11), email TEXT, reqTime VARCHAR(20) -); \ No newline at end of file +); diff --git a/login.py b/login.py index b72c6d2..1553454 100644 --- a/login.py +++ b/login.py @@ -190,7 +190,7 @@ def chgPassword():
This email was sent automatically. Please do not reply.
這個郵件是自動發送的,請不要回覆。
- """ % (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( '修改密碼成功,請重新登入
Password changed successfully. Please login again.') return redirect('/') @@ -284,9 +284,10 @@ def resetPassword(): """, (request.args.get('resetCode'),)) user = cursor.fetchone() cursor.close() + dtnow = datetime.now(tz).replace(tzinfo=None) if user == None: raise Exception('無此重置密碼代碼
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],)) db.commit() cursor.close()