1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/ihatemoney_ynh.git synced 2024-09-03 19:26:15 +02:00

Do not redirect users to the creation form when they are trying to log in.

Fixes #9
This commit is contained in:
Alexis Metaireau 2011-08-09 17:29:44 +02:00
parent 0e5bab13af
commit 4b08af56f8
2 changed files with 12 additions and 4 deletions

View file

@ -6,6 +6,11 @@
<p class=error>{{ ", ".join(errors) }}</p>
{% endfor %}
{% if create_project %}
<p class="info">The project you are trying to access do not exist, do you want
to <a href="{{ url_for("create_project", project_id=create_project) }}">create it</a>?
</p>
{% endif %}
<form action="" method="POST" accept-charset="utf-8">
{{ form.hidden_tag() }}

View file

@ -28,16 +28,18 @@ def authenticate(redirect_url=None):
redirect_url = redirect_url or url_for("list_bills", project_id=project_id)
project = Project.query.get(project_id)
create_project = False # We don't want to create the project by default
if not project:
flash("This project doesn't exist (yet). You can create it by filling this form")
return redirect(url_for("create_project", project_id=project_id))
# But if the user try to connect to an unexisting project, we will
# propose him a link to the creation form.
create_project = project_id
# if credentials are already in session, redirect
if project_id in session and project.password == session[project_id]:
return redirect(redirect_url)
# else process the form
if request.method == "POST":
if project and request.method == "POST":
if form.validate():
if not form.password.data == project.password:
form.errors['password'] = ["The password is not the right one"]
@ -51,7 +53,8 @@ def authenticate(redirect_url=None):
session.update()
return redirect(redirect_url)
return render_template("authenticate.html", form=form)
return render_template("authenticate.html", form=form,
create_project=create_project)
@app.route("/create", methods=["GET", "POST"])
def create_project():