Fix admin ratelimit
This commit is contained in:
parent
3ed09f159d
commit
884a31dfdb
1 changed files with 6 additions and 4 deletions
|
@ -10,11 +10,14 @@ import hashlib
|
|||
import json
|
||||
from datetime import datetime
|
||||
|
||||
def is_admin():
|
||||
return 'admin_authenticated' in session and session['admin_authenticated']
|
||||
|
||||
# Admin authentication middleware
|
||||
def admin_required(f):
|
||||
@wraps(f)
|
||||
def decorated_function(*args, **kwargs):
|
||||
if 'admin_authenticated' not in session or not session['admin_authenticated']:
|
||||
if not is_admin():
|
||||
return redirect(url_for('admin_login', next=request.url))
|
||||
return f(*args, **kwargs)
|
||||
return decorated_function
|
||||
|
@ -136,10 +139,9 @@ def admin_login():
|
|||
return render_template('admin_login.html')
|
||||
|
||||
@app.route('/admin', methods=['POST'])
|
||||
@limiter.limit("1 per minute")
|
||||
@limiter.limit("1 per minute", deduct_when=lambda response: not is_admin())
|
||||
@limiter.limit("10 per hour")
|
||||
def admin_login_post():
|
||||
error = None
|
||||
username = request.form.get('username')
|
||||
password = request.form.get('password')
|
||||
|
||||
|
@ -157,7 +159,7 @@ def admin_login_post():
|
|||
return redirect(next_page)
|
||||
return redirect(url_for('admin_dashboard'))
|
||||
else:
|
||||
flash('Invalid username or password', 'error')
|
||||
flash('Invalid username or password. Try again in 1 minute.', 'error')
|
||||
|
||||
return redirect(url_for('admin_login'))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue