aboutsummaryrefslogtreecommitdiff
path: root/budget
diff options
context:
space:
mode:
Diffstat (limited to 'budget')
-rw-r--r--budget/forms.py1
-rw-r--r--budget/templates/authenticate.html6
-rw-r--r--budget/templates/home.html28
-rw-r--r--budget/web.py64
4 files changed, 71 insertions, 28 deletions
diff --git a/budget/forms.py b/budget/forms.py
index 0373da8..1e265ee 100644
--- a/budget/forms.py
+++ b/budget/forms.py
@@ -21,6 +21,7 @@ class ProjectForm(Form):
class AuthenticationForm(Form):
+ id = TextField("Project identifier", validators=[Required()])
password = TextField("Password", validators=[Required()])
submit = SubmitField("Get in")
diff --git a/budget/templates/authenticate.html b/budget/templates/authenticate.html
index c745e9f..8b57c67 100644
--- a/budget/templates/authenticate.html
+++ b/budget/templates/authenticate.html
@@ -1,6 +1,6 @@
{% extends "layout.html" %}
{% block content %}
-<h2>Login to "{{ project.name }}"</h2>
+<h2>Authentication</h2>
{% for errors in form.errors.values() %}
<p class=error>{{ ", ".join(errors) }}</p>
@@ -8,7 +8,9 @@
<form action="" method="POST" accept-charset="utf-8">
{{ 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>
</form>
{% endblock %}
diff --git a/budget/templates/home.html b/budget/templates/home.html
new file mode 100644
index 0000000..5fcdf90
--- /dev/null
+++ b/budget/templates/home.html
@@ -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 %}
diff --git a/budget/web.py b/budget/web.py
index 46226df..2147359 100644
--- a/budget/web.py
+++ b/budget/web.py
@@ -8,34 +8,40 @@ from utils import get_billform_for, requires_auth
# create the application, initialize stuff
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("/")
def home():
- # FIXME create a real homepage
- return "this is the homepage"
+ project_form = ProjectForm()
+ 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"])
def create_project():
@@ -59,6 +65,12 @@ def create_project():
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")
@requires_auth
def invite(project):