Present error on failed login

This commit is contained in:
Bernd Schoolmann 2024-05-11 04:26:21 +02:00
parent f869e9afff
commit 50451914f2
No known key found for this signature in database
3 changed files with 39 additions and 7 deletions

0
gui/goldwarden_ui_main.py Normal file → Executable file
View File

View File

@ -50,12 +50,39 @@ class GoldwardenLoginApp(Adw.Application):
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__":

View File

@ -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")