Fix sign in

This commit is contained in:
Pavel Djundik 2017-11-11 20:33:21 +02:00
parent 8d88779918
commit 90861effb4
3 changed files with 41 additions and 30 deletions

View file

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

View file

@ -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);
});
});

View file

@ -1,4 +1,4 @@
<form class="container" method="post" action="" data-event="auth">
<form class="container" method="post" action="">
<div class="row">
<div class="col-xs-12">
<h1 class="title">Sign in to The Lounge</h1>