Fix sign in
This commit is contained in:
parent
8d88779918
commit
90861effb4
@ -6,6 +6,8 @@ const storage = require("../localStorage");
|
|||||||
const utils = require("../utils");
|
const utils = require("../utils");
|
||||||
const templates = require("../../views");
|
const templates = require("../../views");
|
||||||
|
|
||||||
|
const login = $("#sign-in").html(templates.windows.sign_in());
|
||||||
|
|
||||||
socket.on("auth", function(data) {
|
socket.on("auth", function(data) {
|
||||||
// If we reconnected and serverHash differs, that means the server restarted
|
// If we reconnected and serverHash differs, that means the server restarted
|
||||||
// And we will reload the page to grab the latest version
|
// And we will reload the page to grab the latest version
|
||||||
@ -21,10 +23,24 @@ socket.on("auth", function(data) {
|
|||||||
let token;
|
let token;
|
||||||
const user = storage.get("user");
|
const user = storage.get("user");
|
||||||
|
|
||||||
const login = $("#sign-in")
|
login.find(".btn").prop("disabled", false);
|
||||||
.html(templates.windows.sign_in())
|
|
||||||
.find(".btn")
|
login.find("form").on("submit", function() {
|
||||||
.prop("disabled", false);
|
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 (!data.success) {
|
||||||
if (login.length === 0) {
|
if (login.length === 0) {
|
||||||
|
@ -24,10 +24,9 @@ socket.on("configuration", function(data) {
|
|||||||
options.initialize();
|
options.initialize();
|
||||||
webpush.initialize();
|
webpush.initialize();
|
||||||
|
|
||||||
// TODO: #sign-in needs to be handled in auth.js otherwise its broken
|
const forms = $("#connect form, #change-password form");
|
||||||
const forms = $("#sign-in, #connect, #change-password");
|
|
||||||
|
|
||||||
forms.on("submit", "form", function() {
|
forms.on("submit", function() {
|
||||||
const form = $(this);
|
const form = $(this);
|
||||||
const event = form.data("event");
|
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);
|
socket.emit(event, values);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
forms.on("focusin", ".nick", function() {
|
$(".nick")
|
||||||
// Need to set the first "lastvalue", so it can be used in the below function
|
.on("focusin", function() {
|
||||||
const nick = $(this);
|
// Need to set the first "lastvalue", so it can be used in the below function
|
||||||
nick.data("lastvalue", nick.val());
|
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() {
|
// Because this gets called /after/ it has already changed, we need use the previous value
|
||||||
const nick = $(this).val();
|
const lastValue = $(this).data("lastvalue");
|
||||||
const usernameInput = forms.find(".username");
|
|
||||||
|
|
||||||
// Because this gets called /after/ it has already changed, we need use the previous value
|
// They were the same before the change, so update the username field
|
||||||
const lastValue = $(this).data("lastvalue");
|
if (usernameInput.val() === lastValue) {
|
||||||
|
usernameInput.val(nick);
|
||||||
|
}
|
||||||
|
|
||||||
// They were the same before the change, so update the username field
|
// Store the "previous" value, for next time
|
||||||
if (usernameInput.val() === lastValue) {
|
$(this).data("lastvalue", nick);
|
||||||
usernameInput.val(nick);
|
});
|
||||||
}
|
|
||||||
|
|
||||||
// Store the "previous" value, for next time
|
|
||||||
$(this).data("lastvalue", nick);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<form class="container" method="post" action="" data-event="auth">
|
<form class="container" method="post" action="">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xs-12">
|
<div class="col-xs-12">
|
||||||
<h1 class="title">Sign in to The Lounge</h1>
|
<h1 class="title">Sign in to The Lounge</h1>
|
||||||
|
Loading…
Reference in New Issue
Block a user