Explorar o código

LoginServer: Add a label for login fail messages

javabird25 %!s(int64=3) %!d(string=hai) anos
pai
achega
9246ad96b3

+ 9 - 0
Userland/Services/LoginServer/LoginWindow.cpp

@@ -36,4 +36,13 @@ LoginWindow::LoginWindow(GUI::Window* parent)
             on_submit();
     };
     m_log_in_button->set_default(true);
+
+    m_fail_message = *widget.find_descendant_of_type_named<GUI::Label>("fail_message");
+    m_username->on_change = [&] {
+        m_fail_message->set_text("");
+    };
+    m_password->on_change = [&] {
+        if (!m_password->text().is_empty())
+            m_fail_message->set_text("");
+    };
 }

+ 5 - 0
Userland/Services/LoginServer/LoginWindow.gml

@@ -25,6 +25,11 @@
         @GUI::Widget {
             layout: @GUI::HorizontalBoxLayout {}
 
+            @GUI::Label {
+                name: "fail_message"
+                text_alignment: "CenterLeft"
+            }
+
             @GUI::Widget {}
 
             @GUI::Button {

+ 4 - 0
Userland/Services/LoginServer/LoginWindow.h

@@ -6,6 +6,7 @@
 
 #include <LibGUI/Button.h>
 #include <LibGUI/ImageWidget.h>
+#include <LibGUI/Label.h>
 #include <LibGUI/TextBox.h>
 #include <LibGUI/Window.h>
 
@@ -25,11 +26,14 @@ public:
     String password() const { return m_password->text(); }
     void set_password(StringView password) { m_password->set_text(password); }
 
+    void set_fail_message(StringView message) { m_fail_message->set_text(message); }
+
 private:
     LoginWindow(GUI::Window* parent = nullptr);
 
     RefPtr<GUI::ImageWidget> m_banner;
     RefPtr<GUI::TextBox> m_username;
     RefPtr<GUI::PasswordBox> m_password;
+    RefPtr<GUI::Label> m_fail_message;
     RefPtr<GUI::Button> m_log_in_button;
 };

+ 3 - 0
Userland/Services/LoginServer/main.cpp

@@ -8,6 +8,7 @@
 #include <LibCore/ArgsParser.h>
 #include <LibCore/System.h>
 #include <LibGUI/Application.h>
+#include <LibGUI/MessageBox.h>
 #include <LibMain/Main.h>
 #include <Services/LoginServer/LoginWindow.h>
 #include <errno.h>
@@ -73,11 +74,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
 
         auto account = Core::Account::from_name(username.characters());
         if (account.is_error()) {
+            window->set_fail_message(String::formatted("Can't log in: {}.", account.error()));
             dbgln("failed graphical login for user {}: {}", username, account.error());
             return;
         }
 
         if (!account.value().authenticate(password)) {
+            window->set_fail_message("Can't log in: invalid password.");
             dbgln("failed graphical login for user {}: invalid password", username);
             return;
         }