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
This commit is contained in:
0livd 2017-05-04 18:10:15 +02:00
parent a5856a3b05
commit c8d5ae4015
3 changed files with 25 additions and 4 deletions

View file

@ -10,3 +10,5 @@ SECRET_KEY = "tralala"
MAIL_DEFAULT_SENDER = ("Budget manager", "budget@notmyidea.org")
ADMIN_PASS = ""
PUBLIC_PROJECT_CREATION = True

View file

@ -5,7 +5,9 @@
<header id="header" class="row">
<div class="col-5 offset-md-2">
<h2>{{ _("Manage your shared <br>expenses, easily") }}</h2>
{% if public_project_creation %}
<a href="{{ url_for(".demo") }}" class="tryout btn">{{ _("Try out the demo") }}</a>
{% endif %}
</div>
<div class="col-4">
<p class="additional-content">{{ _("You're sharing a house?") }}<br /> {{ _("Going on holidays with friends?") }}<br /> {{ _("Simply sharing money with others?") }} <br /><strong>{{ _("We can help!") }}</strong></p>
@ -26,6 +28,7 @@
</form>
</div>
<div class="col-3 offset-md-1">
{% if public_project_creation %}
<form id="creation-form" class="form-horizontal" action="{{ url_for(".create_project") }}" method="post">
<fieldset class="form-group">
<legend>...{{ _("or create a new one") }}</legend>
@ -35,6 +38,9 @@
<button class="btn" type="submit">{{ _("let's get started") }}</button>
</div>
</form>
{% else %}
<a href="{{ url_for(".create_project") }}">...{{ _("or create a new one") }}</a>
{% endif %}
</main>
</div>
{% endblock %}

View file

@ -150,13 +150,20 @@ def authenticate(project_id=None):
@main.route("/")
def home():
project_form = ProjectForm()
auth_form = AuthenticationForm()
public_project_creation = current_app.config['PUBLIC_PROJECT_CREATION']
if public_project_creation:
project_form = ProjectForm()
return render_template("home.html", project_form=project_form,
public_project_creation=public_project_creation,
auth_form=auth_form, session=session)
# If public_project_creation is False we don't need to pass a project form to home
return render_template("home.html", public_project_creation=public_project_creation,
auth_form=auth_form, session=session)
@main.route("/create", methods=["GET", "POST"])
@require_admin
def create_project():
form = ProjectForm()
if request.method == "GET" and 'project_id' in request.values:
@ -290,8 +297,14 @@ def demo():
Create a demo project if it doesnt exists yet (or has been deleted)
"""
public_project_creation = current_app.config['PUBLIC_PROJECT_CREATION']
project = Project.query.get("demo")
if not project:
# Demo project is not automatically created if public project creation is disabled
if not project and not public_project_creation:
raise Redirect303(url_for(".create_project",
project_id='demo'))
if not project and public_project_creation:
project = Project(id="demo", name=u"demonstration", password="demo",
contact_email="demo@notmyidea.org")
db.session.add(project)