~fluix/tilde

5eafb87dcb66444a197f18e647160b174916aad8 — Steven Guikal 2 years ago 28a8f09
Add auth check command for ergo IRC server
1 files changed, 22 insertions(+), 0 deletions(-)

M auth/views.py
M auth/views.py => auth/views.py +22 -0
@@ 2,6 2,8 @@
#
# SPDX-License-Identifier: AGPL-3.0-only

import json

from flask import (
    Blueprint,
    current_app,


@@ 46,6 48,7 @@ def login():
            form.username.errors.append("Username or password is incorrect.")
            return render_template("login.html", form=form)

        # TODO: Move these on to the Enum itself
        status_errors = {
            Status.PENDING: "User is pending verification.",
            Status.DELETED: "User is deleted.",


@@ 83,3 86,22 @@ def register():
        flash("Account registration sent in. Please await a reply.")
        return redirect(url_for("flatpages.index"))
    return render_template("register.html", form=form)


@auth.cli.command("ergo")
def ergo():
    data = json.loads(input())
    status_errors = {
        Status.PENDING: "User is pending verification.",
        Status.DELETED: "User is deleted.",
        Status.BANNED: "User is banned.",
    }
    out = {"success": True}

    user = User.query.filter_by(username=data.get("accountName", "")).first()
    if not user or not user.check_password(data.get("passphrase")):
        out = {"success": False, "error": "Username or password is incorrect."}
    elif status_error := status_errors.get(user.status):
        out = {"success": False, "error": status_error}

    print(json.dumps(out))