diff --git a/app.py b/app.py index 3027399..90077d4 100644 --- a/app.py +++ b/app.py @@ -54,17 +54,28 @@ def inbox(): 'time': c.time.replace(tzinfo=tzlocal()) } for c in Candidate.query.all() ] + + vs = [{ + 'name': name, + 'ques': ques, + 'hint': hint + } for name, ques, hint, ans in C.verify + ] - return render_template('inbox.html', cans=cans) + return render_template('inbox.html', cans=cans, vs=vs) @app.route('/ordinary/new', methods=['POST']) @limiter.limit("5 / hour; 1 / 2 second") def new_one(): content = request.form.get('text') - print(content) - if not content or len(content)>400: - abort(422) + url = request.form.get('url') + + for name, ques, hint, ans in C.verify: + if request.form.get(name) != ans: abort(401) + + if not content or len(content)>400: abort(422) + if url and not re.match('https://closed\.social/safeShare/\d([a-zA-Z]+)?', url): abort(422) if not Candidate.query.filter_by(content=content).first(): @@ -73,7 +84,7 @@ def new_one(): visibility='unlisted' ) - c = Candidate(content=content, toot=toot.id, time = datetime.now()) + c = Candidate(content=content, url=url, toot=toot.id, time = datetime.now()) db.session.add(c) db.session.commit() @@ -100,7 +111,6 @@ def get_replies(toot): lambda r: r['content'] == '删除' and r['url'].split('/@')[1] in C.admins, replies )) - print(d) if d: db.session.delete(c) db.session.commit() diff --git a/config.sample.py b/config.sample.py index d455be4..4941501 100644 --- a/config.sample.py +++ b/config.sample.py @@ -6,3 +6,7 @@ class C(object): bot_name = '@ordinary_bot' token = 'token' admins = [] + verify = [ + ('test1', '1+1=?', '2', '2'), + ('test2', '2+2=?', '5', '4') + ] diff --git a/templates/inbox.html b/templates/inbox.html index 0ad17b2..0478c30 100644 --- a/templates/inbox.html +++ b/templates/inbox.html @@ -3,24 +3,24 @@ - + - 华清特将报名 + 华清特奖报名