From a5856a3b0565f6e1791273290fdebb0dc6b5cfcd Mon Sep 17 00:00:00 2001 From: 0livd <0livd@users.noreply.github.com> Date: Thu, 4 May 2017 17:55:40 +0200 Subject: [PATCH] Add a @require_admin decorator It can be used to protect specific endpoints with ADMIN_PASS (a password that is stored unencrypted in the settings) The decorator has no effect if ADMIN_PASS is an empty string (default value) --- budget/default_settings.py | 2 + budget/forms.py | 5 +++ budget/templates/authenticate.html | 6 +++ budget/templates/forms.html | 10 +++++ .../translations/fr/LC_MESSAGES/messages.mo | Bin 8040 -> 8226 bytes .../translations/fr/LC_MESSAGES/messages.po | 8 ++++ budget/web.py | 35 +++++++++++++++++- 7 files changed, 64 insertions(+), 2 deletions(-) diff --git a/budget/default_settings.py b/budget/default_settings.py index 5ee6de80..3f377099 100644 --- a/budget/default_settings.py +++ b/budget/default_settings.py @@ -8,3 +8,5 @@ SQLALCHEMY_TRACK_MODIFICATIONS = False SECRET_KEY = "tralala" MAIL_DEFAULT_SENDER = ("Budget manager", "budget@notmyidea.org") + +ADMIN_PASS = "" diff --git a/budget/forms.py b/budget/forms.py index f4464751..f7fca9a8 100644 --- a/budget/forms.py +++ b/budget/forms.py @@ -83,6 +83,11 @@ class AuthenticationForm(FlaskForm): submit = SubmitField(_("Get in")) +class AdminAuthenticationForm(FlaskForm): + admin_pass = PasswordField(_("Admin password"), validators=[Required()]) + submit = SubmitField(_("Get in")) + + class PasswordReminder(FlaskForm): id = StringField(_("Project identifier"), validators=[Required()]) submit = SubmitField(_("Send me the code by email")) diff --git a/budget/templates/authenticate.html b/budget/templates/authenticate.html index 98914d09..d6fa3236 100644 --- a/budget/templates/authenticate.html +++ b/budget/templates/authenticate.html @@ -7,7 +7,13 @@ to") }} {{ _("create it") }}{{ _("?") }}
{% endif %} +{% if admin %} + +{% else %} +{% endif %} {% endblock %} diff --git a/budget/templates/forms.html b/budget/templates/forms.html index 01e54867..b56a59c6 100644 --- a/budget/templates/forms.html +++ b/budget/templates/forms.html @@ -45,6 +45,16 @@ {% endmacro %} +{% macro authenticate_admin(form) %} + + {% include "display_errors.html" %} + + {{ form.hidden_tag() }} + {{ input(form.admin_pass) }} + {{ submit(form.submit) }} + +{% endmacro %} + {% macro create_project(form, home=False) %} {% include "display_errors.html" %} diff --git a/budget/translations/fr/LC_MESSAGES/messages.mo b/budget/translations/fr/LC_MESSAGES/messages.mo index 1794c62c0829ef2d705a2b38c02038c453eede41..c824b18aeafe0f26a114e334bc629711589a1e0d 100644 GIT binary patch delta 2109 zcmZ|Pe@K;A9LMo*dgtwjsre(9*SV)(*R0I2ZLJutTvAc4tu@Lv1jTFJh8lXW+ZyXh z$Z(8NVOG#D%8