forked from mrlan/EnglishPal
新增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,15 +24,20 @@ 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
|
||||||
result = []
|
token = session.get("token")
|
||||||
user_freq_record = path_prefix + 'static/frequency/' + 'frequency_%s.pickle' % (username)
|
if token == "70620F32A9DC965FCCF0447B674AA161":
|
||||||
s = pickle_idea2.load_record(user_freq_record)
|
result = []
|
||||||
wordlist = helper(s, result)
|
user_freq_record = path_prefix + 'static/frequency/' + 'frequency_%s.pickle' % (username)
|
||||||
print(json.dumps(s))
|
s = pickle_idea2.load_record(user_freq_record)
|
||||||
results = {}
|
wordlist = helper(s, result)
|
||||||
|
print(json.dumps(s))
|
||||||
|
results = {}
|
||||||
|
|
||||||
for word in wordlist:
|
for word in wordlist:
|
||||||
results[word] = len(s[word])
|
results[word] = len(s[word])
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
else:
|
||||||
|
print("无效的token")
|
||||||
|
|
Loading…
Reference in New Issue