Skip to content

Commit

Permalink
Merge pull request #215 from quexten/feature/error-dialogs-on-login
Browse files Browse the repository at this point in the history
Present error on failed login
  • Loading branch information
quexten authored May 11, 2024
2 parents b8b0dd9 + 26d12fd commit 742cedd
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 10 deletions.
42 changes: 36 additions & 6 deletions gui/src/gui/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,45 @@ def key_press(self, event, keyval, keycode, state):

def on_login(self):
email = self.email_row.get_text()
client_id = self.client_id_row.get_text()
client_secret = self.client_secret_row.get_text()
client_id = self.client_id_row.get_text().strip()
client_secret = self.client_secret_row.get_text().strip()
server = self.server_row.get_text()
print("setting server to", server, "with result", goldwarden.set_server(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 != "":
print("set client id result", goldwarden.set_client_id(client_id.strip()))
goldwarden.set_client_id(client_id)
if client_secret != "":
print("set client secret result", goldwarden.set_client_secret(client_secret.strip()))
goldwarden.login_with_password(email, "")
goldwarden.set_client_secret(client_secret)

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__":
Expand Down
13 changes: 9 additions & 4 deletions gui/src/services/goldwarden.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ def set_vault_url(url):
send_authenticated_command(f"config set-vault-url {url}")

def set_server(url):
send_authenticated_command(f"config 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")
Expand All @@ -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")
Expand Down

0 comments on commit 742cedd

Please sign in to comment.