mirror of
https://github.com/spiral-project/ihatemoney.git
synced 2025-04-29 01:42:37 +02:00
Homepage created and project authentication refactored
This commit is contained in:
parent
c7f9df9859
commit
8dd2091f31
4 changed files with 71 additions and 28 deletions
|
@ -21,6 +21,7 @@ class ProjectForm(Form):
|
||||||
|
|
||||||
|
|
||||||
class AuthenticationForm(Form):
|
class AuthenticationForm(Form):
|
||||||
|
id = TextField("Project identifier", validators=[Required()])
|
||||||
password = TextField("Password", validators=[Required()])
|
password = TextField("Password", validators=[Required()])
|
||||||
submit = SubmitField("Get in")
|
submit = SubmitField("Get in")
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{% extends "layout.html" %}
|
{% extends "layout.html" %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h2>Login to "{{ project.name }}"</h2>
|
<h2>Authentication</h2>
|
||||||
|
|
||||||
{% for errors in form.errors.values() %}
|
{% for errors in form.errors.values() %}
|
||||||
<p class=error>{{ ", ".join(errors) }}</p>
|
<p class=error>{{ ", ".join(errors) }}</p>
|
||||||
|
@ -8,7 +8,9 @@
|
||||||
|
|
||||||
<form action="" method="POST" accept-charset="utf-8">
|
<form action="" method="POST" accept-charset="utf-8">
|
||||||
{{ form.hidden_tag() }}
|
{{ form.hidden_tag() }}
|
||||||
Password: <input type="password" name="password" value="">
|
|
||||||
|
<p>{{ form.id.label }}<br /> {{ form.id }}</p>
|
||||||
|
<p>{{ form.password.label }}<br /> {{ form.password }}</p>
|
||||||
<p>{{ form.submit }}</p>
|
<p>{{ form.submit }}</p>
|
||||||
</form>
|
</form>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
28
budget/templates/home.html
Normal file
28
budget/templates/home.html
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
{% extends "layout.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h2>Welcome on the budget manager</h2>
|
||||||
|
|
||||||
|
<form action="{{ url_for('authenticate') }}" method="post" accept-charset="utf-8">
|
||||||
|
<h3>Log to an existing project...</h3>
|
||||||
|
|
||||||
|
{{ auth_form.hidden_tag() }}
|
||||||
|
|
||||||
|
<p>{{ auth_form.id.label }}<br /> {{ auth_form.id }}</p>
|
||||||
|
<p>{{ auth_form.password.label }}<br /> {{ auth_form.password }}</p>
|
||||||
|
<p>{{ auth_form.submit }}</p>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<form action="{{ url_for('create_project') }}" method="post" class="container span-24 add-bill">
|
||||||
|
<h3>...or create a new project</h3>
|
||||||
|
|
||||||
|
{{ project_form.hidden_tag() }}
|
||||||
|
|
||||||
|
<p>{{ project_form.name.label }}<br /> {{ project_form.name }}</p>
|
||||||
|
<p>{{ project_form.id.label }}<br /> {{ project_form.id }}</p>
|
||||||
|
<p>{{ project_form.password.label }}<br /> {{ project_form.password }}</p>
|
||||||
|
<p>{{ project_form.contact_email.label }}<br /> {{ project_form.contact_email }}</p>
|
||||||
|
<p>{{ project_form.submit }}</p>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{% endblock %}
|
|
@ -8,34 +8,40 @@ from utils import get_billform_for, requires_auth
|
||||||
# create the application, initialize stuff
|
# create the application, initialize stuff
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
@app.route("/<string:project_id>/authenticate", methods=["GET", "POST"])
|
|
||||||
def authenticate(project_id, redirect_url=None):
|
|
||||||
redirect_url = redirect_url or url_for("list_bills", project_id=project_id)
|
|
||||||
project = Project.query.get(project_id)
|
|
||||||
if not project:
|
|
||||||
return redirect(url_for("create_project", project_id=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 create the form and process it
|
|
||||||
form = AuthenticationForm()
|
|
||||||
if request.method == "POST":
|
|
||||||
if form.validate():
|
|
||||||
if not form.password.data == project.password:
|
|
||||||
form.errors['password'] = ["The password is not the right one"]
|
|
||||||
else:
|
|
||||||
session[project_id] = form.password.data
|
|
||||||
session.update()
|
|
||||||
return redirect(redirect_url)
|
|
||||||
|
|
||||||
return render_template("authenticate.html", form=form, project=project)
|
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def home():
|
def home():
|
||||||
# FIXME create a real homepage
|
project_form = ProjectForm()
|
||||||
return "this is the homepage"
|
auth_form = AuthenticationForm()
|
||||||
|
return render_template("home.html", project_form=project_form, auth_form=auth_form)
|
||||||
|
|
||||||
|
@app.route("/authenticate", methods=["GET", "POST"])
|
||||||
|
def authenticate(redirect_url=None):
|
||||||
|
form = AuthenticationForm()
|
||||||
|
|
||||||
|
if form.id.validate():
|
||||||
|
|
||||||
|
project_id = form.id.data
|
||||||
|
|
||||||
|
redirect_url = redirect_url or url_for("list_bills", project_id=project_id)
|
||||||
|
project = Project.query.get(project_id)
|
||||||
|
if not project:
|
||||||
|
return redirect(url_for("create_project", project_id=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 form.validate():
|
||||||
|
if not form.password.data == project.password:
|
||||||
|
form.errors['password'] = ["The password is not the right one"]
|
||||||
|
else:
|
||||||
|
session[project_id] = form.password.data
|
||||||
|
session.update()
|
||||||
|
return redirect(redirect_url)
|
||||||
|
|
||||||
|
return render_template("authenticate.html", form=form)
|
||||||
|
|
||||||
@app.route("/create", methods=["GET", "POST"])
|
@app.route("/create", methods=["GET", "POST"])
|
||||||
def create_project():
|
def create_project():
|
||||||
|
@ -59,6 +65,12 @@ def create_project():
|
||||||
|
|
||||||
return render_template("create_project.html", form=form)
|
return render_template("create_project.html", form=form)
|
||||||
|
|
||||||
|
@app.route("/quit")
|
||||||
|
def quit():
|
||||||
|
# delete the session
|
||||||
|
session = None
|
||||||
|
return redirect( url_for("home") )
|
||||||
|
|
||||||
@app.route("/<string:project_id>/invite")
|
@app.route("/<string:project_id>/invite")
|
||||||
@requires_auth
|
@requires_auth
|
||||||
def invite(project):
|
def invite(project):
|
||||||
|
|
Loading…
Reference in a new issue