2017-05-18 20:08:54 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const $ = require("jquery");
|
|
|
|
const socket = require("../socket");
|
|
|
|
const storage = require("../localStorage");
|
|
|
|
|
|
|
|
socket.on("auth", function(data) {
|
|
|
|
const login = $("#sign-in");
|
|
|
|
let token;
|
2017-06-21 07:58:29 +00:00
|
|
|
const user = storage.get("user");
|
2017-05-18 20:08:54 +00:00
|
|
|
|
|
|
|
login.find(".btn").prop("disabled", false);
|
|
|
|
|
|
|
|
if (!data.success) {
|
|
|
|
storage.remove("token");
|
|
|
|
|
|
|
|
const error = login.find(".error");
|
|
|
|
error.show().closest("form").one("submit", function() {
|
|
|
|
error.hide();
|
|
|
|
});
|
2017-06-21 07:58:29 +00:00
|
|
|
} else if (user) {
|
2017-05-18 20:08:54 +00:00
|
|
|
token = storage.get("token");
|
|
|
|
if (token) {
|
|
|
|
$("#loading-page-message").text("Authorizing…");
|
2017-06-21 07:58:29 +00:00
|
|
|
socket.emit("auth", {user: user, token: token});
|
2017-05-18 20:08:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-21 07:58:29 +00:00
|
|
|
if (user) {
|
|
|
|
login.find("input[name='user']").val(user);
|
2017-05-18 20:08:54 +00:00
|
|
|
}
|
2017-06-21 07:58:29 +00:00
|
|
|
|
2017-05-18 20:08:54 +00:00
|
|
|
if (token) {
|
|
|
|
return;
|
|
|
|
}
|
2017-06-21 07:58:29 +00:00
|
|
|
|
2017-09-12 12:52:16 +00:00
|
|
|
$("#footer")
|
|
|
|
.find(".sign-in")
|
2017-05-18 20:08:54 +00:00
|
|
|
.trigger("click", {
|
|
|
|
pushState: false,
|
2017-09-12 12:52:16 +00:00
|
|
|
});
|
2017-05-18 20:08:54 +00:00
|
|
|
});
|