diff --git a/fosspay/blueprints/html.py b/fosspay/blueprints/html.py index 4037a7a..f0b4e8a 100644 --- a/fosspay/blueprints/html.py +++ b/fosspay/blueprints/html.py @@ -6,6 +6,7 @@ from fosspay.common import * from fosspay.config import _cfg, load_config import locale +import bcrypt encoding = locale.getdefaultlocale()[1] html = Blueprint('html', __name__, template_folder='../../templates') @@ -15,7 +16,8 @@ def index(): if User.query.count() == 0: load_config() return render_template("setup.html") - return render_template("index.html") + projects = sorted(Project.query.all(), key=lambda p: p.name) + return render_template("index.html", projects=projects) @html.route("/setup", methods=["POST"]) def setup(): @@ -37,12 +39,15 @@ def setup(): def admin(): first = request.args.get("first-run") is not None projects = Project.query.all() + unspecified = Donation.query.filter(Donation.project == None).all() return render_template("admin.html", - first=first, - projects=projects, - one_times=lambda p: sum([d.amount for d in p.donations if d.type == DonationType.one_time]), - recurring=lambda p: sum([d.amount for d in p.donations if d.type == DonationType.recurring]) - ) + first=first, + projects=projects, + one_times=lambda p: sum([d.amount for d in p.donations if d.type == DonationType.one_time]), + recurring=lambda p: sum([d.amount for d in p.donations if d.type == DonationType.recurring]), + unspecified_one_times=sum([d.amount for d in unspecified if d.type == DonationType.one_time]), + unspecified_recurring=sum([d.amount for d in unspecified if d.type == DonationType.recurring]) + ) @html.route("/create-project", methods=["POST"]) @adminrequired @@ -53,6 +58,22 @@ def create_project(): db.commit() return redirect("/admin") +@html.route("/login", methods=["GET", "POST"]) +def login(): + if request.method == "GET": + return render_template("login.html") + email = request.form.get("email") + password = request.form.get("password") + if not email or not password: + return render_template("login.html", errors=True) + user = User.query.filter(User.email == email).first() + if not user: + return render_template("login.html", errors=True) + if not bcrypt.hashpw(password.encode('UTF-8'), user.password.encode('UTF-8')) == user.password.encode('UTF-8'): + return render_template("login.html", errors=True) + login_user(user) + return redirect("/") + @html.route("/logout") @loginrequired def logout(): diff --git a/templates/admin.html b/templates/admin.html index 8627337..3f0a3fa 100644 --- a/templates/admin.html +++ b/templates/admin.html @@ -1,5 +1,8 @@ {% extends "layout.html" %} -{% block body %} +{% block title %} +Donation Admin +{% endblock %} +{% block container %} Log out

Fosspay Admin

{% if first %} @@ -50,11 +53,19 @@ Get Markdown {% endfor %} + + + (not specified) + ${{ unspecified_one_times }} + ${{ unspecified_recurring }} + + -
+

Add Project

+

Donors will not be given a choice of project unless you have at least 2.

diff --git a/templates/how-this-works.html b/templates/how-this-works.html new file mode 100644 index 0000000..d50a8ed --- /dev/null +++ b/templates/how-this-works.html @@ -0,0 +1,10 @@ +

+Donations accumulate until they reach enough to support a week of full +time work. Once they get to this amount, a week will be scheduled. The +amount of time each project receives is planned based on the amount of +donations received that specify that project in the drop-down. +

+

+If one project receives a million dollars and another project receives +one dollar, at least an hour will be spent on the second project. +

diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..45049b8 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,112 @@ +{% extends "layout.html" %} +{% block body %} +
+
+

Donate to {{ _cfg("your-name") }}

+

How does this work?

+
+
+ +
+

How much?

+
+
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+
+

How often?

+
+
+
+
+ +
+
+ +
+
+
+
+ {% if len(projects) > 1 %} +

What project?

+
+
+
+ +
+
+
+ {% endif %} +
+
+
+ +
+
+
+
+
+ +
+
+
+
+
+

+ + Been here before? Log in to view your donation + history, edit recurring donations, and so on. + +

+

+ + Powered by fosspay. + +

+
+ + +{% endblock %} diff --git a/templates/layout.html b/templates/layout.html index 2e64610..147e30f 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -5,10 +5,15 @@ Donate to {{_cfg("your-name")}} {% endblock %} + + + {% block body %}
- {% block body %}{% endblock %} + {% block container %} + {% endblock %}
+ {% endblock %} diff --git a/templates/login.html b/templates/login.html new file mode 100644 index 0000000..5dd20bd --- /dev/null +++ b/templates/login.html @@ -0,0 +1,20 @@ +{% extends "layout.html" %} +{% block container %} +

Log In

+{% if errors %} +
+

+ Username or password incorrect. +

+
+{% endif %} + +
+ +
+
+ +
+ + +{% endblock %}