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 %} +
Donors will not be given a choice of project unless you have at least 2.