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