diff --git a/main.py b/main.py index 2a0c78d..dc86ec0 100644 --- a/main.py +++ b/main.py @@ -9,6 +9,7 @@ from email.mime.text import MIMEText import datetime import json from playhouse.shortcuts import model_to_dict +from functools import wraps app = Flask(__name__) @@ -76,6 +77,19 @@ if os.environ.get('SEED_TEST_USERS_DISABLED') != '1': ensure_test_users() +# Admin-only decorator must be defined before routes that use it +def admin_required(f): + @wraps(f) + def decorated_function(*args, **kwargs): + if not current_user.is_authenticated: + return redirect(url_for('login')) + if not getattr(current_user, 'is_admin', False): + flash('Недостаточно прав', 'danger') + return redirect(url_for('dashboard')) + return f(*args, **kwargs) + return decorated_function + + @app.route('/admin/users', methods=['GET', 'POST']) @admin_required def manage_users(): diff --git a/templates/layout.html b/templates/layout.html index c793e4b..48413d6 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -1,59 +1,57 @@ - - {{ title or "Опросник" }} - - - - - + + {{ title or "Опросник" }} + + + + + - - - +
+ {% block content %}{% endblock %} + {% with messages = get_flashed_messages(with_categories=true) %} + {% if messages %} +
+ {% for category, message in messages %} +
{{ message }}
+ {% endfor %} +
+ {% endif %} + {% endwith %} +
+ +