From 5eafb87dcb66444a197f18e647160b174916aad8 Mon Sep 17 00:00:00 2001 From: Steven Guikal Date: Thu, 23 Dec 2021 03:19:00 -0500 Subject: [PATCH] Add auth check command for ergo IRC server --- auth/views.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/auth/views.py b/auth/views.py index 506e87d..5b9db99 100644 --- a/auth/views.py +++ b/auth/views.py @@ -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)) -- 2.38.5