From 50451914f283217312f639d9d5d080422acd3a30 Mon Sep 17 00:00:00 2001 From: Bernd Schoolmann Date: Sat, 11 May 2024 04:26:21 +0200 Subject: [PATCH] Present error on failed login --- gui/goldwarden_ui_main.py | 0 gui/src/gui/login.py | 31 +++++++++++++++++++++++++++++-- gui/src/services/goldwarden.py | 15 ++++++++++----- 3 files changed, 39 insertions(+), 7 deletions(-) mode change 100644 => 100755 gui/goldwarden_ui_main.py diff --git a/gui/goldwarden_ui_main.py b/gui/goldwarden_ui_main.py old mode 100644 new mode 100755 diff --git a/gui/src/gui/login.py b/gui/src/gui/login.py index 0a8179b..2104a82 100644 --- a/gui/src/gui/login.py +++ b/gui/src/gui/login.py @@ -50,12 +50,39 @@ def on_login(self): client_id = self.client_id_row.get_text() client_secret = self.client_secret_row.get_text() server = self.server_row.get_text() - goldwarden.set_url(server) + try: + goldwarden.set_server(server) + except: + print("set server failed") + dialog = Adw.MessageDialog.new(self.window, + "Failed to set server", + "The server you entered is invalid, please try again.", + ) + dialog.add_response("ok", "Dismiss") + dialog.present() + return if client_id != "": goldwarden.set_client_id(client_id) if client_secret != "": goldwarden.set_client_secret(client_secret) - goldwarden.login_with_password(email, "") + try: + goldwarden.login_with_password(email, "") + except Exception as e: + if "errorbadpassword" in str(e): + dialog = Adw.MessageDialog.new(self.window, "Bad Password", "The username or password you entered is incorrect.") + dialog.add_response("ok", "Dismiss") + dialog.present() + return + if "errorcaptcha" in str(e): + dialog = Adw.MessageDialog.new(self.window, "Unusual traffic error", "Traffic is unusual, please set up api client id and client secret.") + dialog.add_response("ok", "Dismiss") + dialog.present() + return + if "errortotp" in str(e): + dialog = Adw.MessageDialog.new(self.window, "TOTP Invalid", "The TOTP code you entered is invalid.") + dialog.add_response("ok", "Dismiss") + dialog.present() + return self.window.close() if __name__ == "__main__": diff --git a/gui/src/services/goldwarden.py b/gui/src/services/goldwarden.py index d691c17..dcfeeb5 100644 --- a/gui/src/services/goldwarden.py +++ b/gui/src/services/goldwarden.py @@ -70,8 +70,10 @@ def set_notification_url(url): def set_vault_url(url): send_authenticated_command(f"config set-vault-url {url}") -def set_url(url): - send_authenticated_command(f"config set-url {url}") +def set_server(url): + result = send_authenticated_command(f"config set-server {url}") + if result.strip() != "Done": + raise Exception("Failed to set server") def get_environment(): result = send_authenticated_command(f"config get-environment") @@ -88,9 +90,12 @@ def set_client_secret(client_secret): def login_with_password(email, password): result = send_authenticated_command(f"vault login --email {email}") - if not "Logged in" in result: - return "badpass" - return "ok" + if "Login failed" in result and "username or password" in result.lower(): + raise Exception("errorbadpassword") + if "Login failed" in result and ("error code 7" in result.lower() or "error code 6" in result.lower()): + raise Exception("errorcaptcha") + if "Login failed" in result and "two-factor" in result.lower(): + raise Exception("errortotp") def login_passwordless(email): send_authenticated_command(f"vault login --email {email} --passwordless")