Merge pull request #215 from quexten/feature/error-dialogs-on-login

Present error on failed login
This commit is contained in:
Bernd Schoolmann 2024-05-11 04:29:19 +02:00 committed by GitHub
commit 742ceddf15
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 45 additions and 10 deletions

View File

@ -47,15 +47,45 @@ class GoldwardenLoginApp(Adw.Application):
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__":

View File

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