diff --git a/app.py b/app.py index 37f87f5..d796a19 100644 --- a/app.py +++ b/app.py @@ -8,6 +8,7 @@ import ipfshttpclient from datetime import date, datetime from functools import wraps import hashlib +import random import os from config import C @@ -45,7 +46,7 @@ def login_required(f): @wraps(f) def df(*args, **kwargs): username = session.get('username') - if not username or (not C.allow_guest_upload and username.startswith('guest(')): + if not username or (not C.allow_guest_upload and username.startswith('guest~')): return redirect(url_for('login')) return f(*args, **kwargs, username=username) return df @@ -61,7 +62,16 @@ def guest_login(): @app.route('/pastExam/login/guest/verify', methods=['POST']) @limiter.limit("10 / hour") def guest_login_send(): - return 'ok' + for name, ques, hint, ans in C.verify: + if request.form.get(name) != ans: + return '错误!', 401 + + if 'uid' not in session: + session['uid'] = random.randint(0, 100000) + + session['username'] = 'guest~%s' % session['uid'] + session.permanent = True + return {'r':0} @app.route('/pastExam/') @login_required diff --git a/templates/guest-login.html b/templates/guest-login.html index 9448637..689a907 100644 --- a/templates/guest-login.html +++ b/templates/guest-login.html @@ -28,7 +28,7 @@
-
+ {% for v in vs %}
@@ -41,5 +41,21 @@
+ + diff --git a/templates/list.html b/templates/list.html index 2873aa9..93d038d 100644 --- a/templates/list.html +++ b/templates/list.html @@ -165,13 +165,32 @@ .popover-body ul li { margin-bottom: 8px; } + + .user-info:not(:hover) .username{ + display: none; + }
-

华清大学
 课程攻略
 共享计划

+

华清大学
 课程攻略
  共享计划

+
+ +
@@ -299,10 +318,10 @@
{{p.notes}}
@{{'匿名用户' if p.anon else p.author}} | {{p.create_date}} - + + 下载({{p.down_num}})
@@ -338,7 +357,7 @@
- + @@ -357,7 +376,7 @@ $(`#like-${toot} svg`).toggleClass("like liked"); }, error: (xhr, status, error) => { - alert(error + ': ' + xhr.responseText); + alert(error); } }); } @@ -375,7 +394,6 @@
  • 如有特殊署名或授权需求,请体现在文件名或附带上传LICENSE,请确保授权方式与本平台的运作方式兼容,推荐使用CC-BY-SA许可协议。默认情况下上传内容的版权与上传前一致,属于上传者/原作者/公有领域等。请务必确保上传行为不会侵犯其他人的合法权益。
  • ` }); - $("#anon").bootstrapSwitch({onColor: 'danger'}); })