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 1/2] 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 %} +
+ {{ forms.authenticate_admin(form) }} +
+{% else %}
{{ forms.authenticate(form) }}
+{% 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`{NGDf?ccwHL9yX6)$ydOpF^#<54Dq9n2NulLj4dGkzv;!iHz zqaoC1^%OO5fJ9Jx8Y(G6sP;14&3C#CweVjVY&QOdimYEq0whsbg7mSasEOA*Yf%f> zglyWjVhDG-=e?LiJ%Ku+>sW$!P?1UEp~jnwip=Y%ao$BD;9D&Pg>nNHVjS6&9YQWU z!%d&v_pbdODzuM~{Ip?I(y5c`AylLaQIRY~MPvagA|Il1pdK^y{kKz4NcN&SUP1E4 z{y^>I8R{1;Oaf>JGf@M*h4Ziy6}dLl!uO#1^&pph$4v|Q85zn3P#b=VLFTt)db0@| zhk7s>HBbpEREtqNTa7yNYUEvOKqXhZt9QHS-{O4QZ(tiH@onn8?Wm1)qK>2+eSJ2) z6g<3*8t^eHIns%%LN(jD0&h^?giG*M65(^)f))52d1Ph0JO`^Vj2)<*pFthXRn*4% z^NGKbYmf%*{2A)^Aiyg0VlgV&)*$(0n^9-qj>_gQQK9Wc?dWUNI2TY8^kF&vf@PS` zZnVG;Q1i4F5PyaC2o0s!i(1eC5(ImK%IZ{RE5;lgIeTX%Y5{9e3#djdpdR%(#$0d3x8&36=)GpCCvXu?aViGD<#)qT_oAEE}z@jABz&yKHah&FngYg$@9ZfdSe%ozP? z%G8?ww0Y4MudylS#WqH~=IDlvF|VmHk~oky7)X9)&fLyzS?4Fkyt>H97!hye-Dpd! hxh58gHz!`pemhvOGU7Eb!2k5=>A(dVbBf=mu=tD+@)mVxVMQ9>n zS|XX$7Y%J8rIz#}k-bQtG%6|59F>(xzVxZzUvFqU&;2{+JokOhbzSG&+jh%9Pv5aI zgI_NG9`~K#`(*amn-7 zGh5lsRCW>j68Qrf*YIJ!!F9}*O!rhKn#bI?nB%#G?cdcL z$ILr}31l{NCgxVor%zef=b9UqF_|rAGJS+u;8`Z4mzdMNg_(FqHNJ;AjGt8Fzi_?x z@-HUv)h4@v+nCB8<{ZVl0Hf2u{^^ZvKOoVTTF%e znF@Z$RN^30p#f&^|7HSdGDKZPlkqC1GV3UovauT9$&2s*K8-~96_e>PX0LyxPr2ZdL)B=t z^gEf~=dqi2aTV8AxdYZ}PJTpoaV&_rgAB> z=g(JeU;@~}1hAb6U Date: Thu, 4 May 2017 18:10:15 +0200 Subject: [PATCH 2/2] Introduce PUBLIC_PROJECT_CREATION setting When set to False (True by default), this setting will deactivate the demo project and ask for ADMIN_PASS for project creation Closes #108 --- budget/default_settings.py | 2 ++ budget/templates/home.html | 6 ++++++ budget/web.py | 21 +++++++++++++++++---- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/budget/default_settings.py b/budget/default_settings.py index 3f377099..63878477 100644 --- a/budget/default_settings.py +++ b/budget/default_settings.py @@ -10,3 +10,5 @@ SECRET_KEY = "tralala" MAIL_DEFAULT_SENDER = ("Budget manager", "budget@notmyidea.org") ADMIN_PASS = "" + +PUBLIC_PROJECT_CREATION = True diff --git a/budget/templates/home.html b/budget/templates/home.html index 399343a5..7caa6af5 100644 --- a/budget/templates/home.html +++ b/budget/templates/home.html @@ -5,7 +5,9 @@