diff --git a/client/js/socket-events/auth.js b/client/js/socket-events/auth.js index 80fd0e18..ef9f4d5c 100644 --- a/client/js/socket-events/auth.js +++ b/client/js/socket-events/auth.js @@ -6,6 +6,8 @@ const storage = require("../localStorage"); const utils = require("../utils"); const templates = require("../../views"); +const login = $("#sign-in").html(templates.windows.sign_in()); + socket.on("auth", function(data) { // If we reconnected and serverHash differs, that means the server restarted // And we will reload the page to grab the latest version @@ -21,10 +23,24 @@ socket.on("auth", function(data) { let token; const user = storage.get("user"); - const login = $("#sign-in") - .html(templates.windows.sign_in()) - .find(".btn") - .prop("disabled", false); + login.find(".btn").prop("disabled", false); + + login.find("form").on("submit", function() { + const form = $(this); + + form.find(".btn").attr("disabled", true); + + const values = {}; + $.each(form.serializeArray(), function(i, obj) { + values[obj.name] = obj.value; + }); + + storage.set("user", values.user); + + socket.emit("auth", values); + + return false; + }); if (!data.success) { if (login.length === 0) { diff --git a/client/js/socket-events/configuration.js b/client/js/socket-events/configuration.js index 901170ca..eae98644 100644 --- a/client/js/socket-events/configuration.js +++ b/client/js/socket-events/configuration.js @@ -24,10 +24,9 @@ socket.on("configuration", function(data) { options.initialize(); webpush.initialize(); - // TODO: #sign-in needs to be handled in auth.js otherwise its broken - const forms = $("#sign-in, #connect, #change-password"); + const forms = $("#connect form, #change-password form"); - forms.on("submit", "form", function() { + forms.on("submit", function() { const form = $(this); const event = form.data("event"); @@ -40,34 +39,30 @@ socket.on("configuration", function(data) { } }); - if (values.user) { - storage.set("user", values.user); - } - socket.emit(event, values); return false; }); - forms.on("focusin", ".nick", function() { - // Need to set the first "lastvalue", so it can be used in the below function - const nick = $(this); - nick.data("lastvalue", nick.val()); - }); + $(".nick") + .on("focusin", function() { + // Need to set the first "lastvalue", so it can be used in the below function + const nick = $(this); + nick.data("lastvalue", nick.val()); + }) + .on("input", function() { + const nick = $(this).val(); + const usernameInput = forms.find(".username"); - forms.on("input", ".nick", function() { - const nick = $(this).val(); - const usernameInput = forms.find(".username"); + // Because this gets called /after/ it has already changed, we need use the previous value + const lastValue = $(this).data("lastvalue"); - // Because this gets called /after/ it has already changed, we need use the previous value - const lastValue = $(this).data("lastvalue"); + // They were the same before the change, so update the username field + if (usernameInput.val() === lastValue) { + usernameInput.val(nick); + } - // They were the same before the change, so update the username field - if (usernameInput.val() === lastValue) { - usernameInput.val(nick); - } - - // Store the "previous" value, for next time - $(this).data("lastvalue", nick); - }); + // Store the "previous" value, for next time + $(this).data("lastvalue", nick); + }); }); diff --git a/client/views/windows/sign_in.tpl b/client/views/windows/sign_in.tpl index cdd5cf22..2f0e2e5a 100644 --- a/client/views/windows/sign_in.tpl +++ b/client/views/windows/sign_in.tpl @@ -1,4 +1,4 @@ -