新增token鉴权
parent
6c2a9823af
commit
df82f59297
|
@ -1,9 +1,11 @@
|
||||||
from flask import *
|
from flask import *
|
||||||
|
|
||||||
from Login import check_username_availability, verify_user, add_user, get_expiry_date, change_password, WarningMessage
|
from Login import check_username_availability, verify_user, add_user, get_expiry_date, change_password, WarningMessage
|
||||||
|
|
||||||
# 初始化蓝图
|
# 初始化蓝图
|
||||||
accountService = Blueprint("accountService", __name__)
|
accountService = Blueprint("accountService", __name__)
|
||||||
|
|
||||||
|
|
||||||
### Sign-up, login, logout ###
|
### Sign-up, login, logout ###
|
||||||
@accountService.route("/signup", methods=['GET', 'POST'])
|
@accountService.route("/signup", methods=['GET', 'POST'])
|
||||||
def signup():
|
def signup():
|
||||||
|
@ -34,6 +36,7 @@ def signup():
|
||||||
session['logged_in'] = True
|
session['logged_in'] = True
|
||||||
session[username] = username
|
session[username] = username
|
||||||
session['username'] = username
|
session['username'] = username
|
||||||
|
session['token'] = "70620F32A9DC965FCCF0447B674AA161"
|
||||||
session['expiry_date'] = get_expiry_date(username)
|
session['expiry_date'] = get_expiry_date(username)
|
||||||
session['articleID'] = None
|
session['articleID'] = None
|
||||||
return render_template('signup_success.html', username=username)
|
return render_template('signup_success.html', username=username)
|
||||||
|
@ -68,6 +71,7 @@ def login():
|
||||||
session['logged_in'] = True
|
session['logged_in'] = True
|
||||||
session[username] = username
|
session[username] = username
|
||||||
session['username'] = username
|
session['username'] = username
|
||||||
|
session['token'] = "70620F32A9DC965FCCF0447B674AA161"
|
||||||
user_expiry_date = get_expiry_date(username)
|
user_expiry_date = get_expiry_date(username)
|
||||||
session['expiry_date'] = user_expiry_date
|
session['expiry_date'] = user_expiry_date
|
||||||
session['existing_articles'] = None
|
session['existing_articles'] = None
|
||||||
|
@ -84,6 +88,7 @@ def logout():
|
||||||
'''
|
'''
|
||||||
# 将session标记为登出状态
|
# 将session标记为登出状态
|
||||||
session['logged_in'] = False
|
session['logged_in'] = False
|
||||||
|
session["token"] = None
|
||||||
return redirect(url_for('mainpage'))
|
return redirect(url_for('mainpage'))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from flask import Blueprint
|
from flask import Blueprint, session
|
||||||
|
|
||||||
import pickle_idea2
|
import pickle_idea2
|
||||||
|
|
||||||
|
@ -24,7 +24,9 @@ def helper(res, result):
|
||||||
|
|
||||||
@api_blue.route('/json/<username>', methods=['GET'])
|
@api_blue.route('/json/<username>', methods=['GET'])
|
||||||
def api_bp(username):
|
def api_bp(username):
|
||||||
# 获取session里的用户名
|
# 获取session里的用户名,必须携带token
|
||||||
|
token = session.get("token")
|
||||||
|
if token == "70620F32A9DC965FCCF0447B674AA161":
|
||||||
result = []
|
result = []
|
||||||
user_freq_record = path_prefix + 'static/frequency/' + 'frequency_%s.pickle' % (username)
|
user_freq_record = path_prefix + 'static/frequency/' + 'frequency_%s.pickle' % (username)
|
||||||
s = pickle_idea2.load_record(user_freq_record)
|
s = pickle_idea2.load_record(user_freq_record)
|
||||||
|
@ -36,3 +38,6 @@ def api_bp(username):
|
||||||
results[word] = len(s[word])
|
results[word] = len(s[word])
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
else:
|
||||||
|
print("无效的token")
|
||||||
|
|
Loading…
Reference in New Issue