Webserver: autologin added, check if session has been closed frequently
This commit is contained in:
1 parent
f27aae0ae2
commit
f7cb09f47a
2 files changed
+73
-8
No files matched your search
@@ -90,7 +90,7 @@
|
|||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<a href="#login" data-transition="slidefade">
|
<a id="mainPageLogoutLink" href="#" data-transition="slidefade">
|
||||||
<img src="img/logout.png">
|
<img src="img/logout.png">
|
||||||
<h2>Logout</h2>
|
<h2>Logout</h2>
|
||||||
<p>Closes the session</p>
|
<p>Closes the session</p>
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ $(document).ready(function () {
|
|||||||
initKeyboardPageHandler();
|
initKeyboardPageHandler();
|
||||||
initMainPageHandler();
|
initMainPageHandler();
|
||||||
initLoginPageHandler();
|
initLoginPageHandler();
|
||||||
|
initHeartbeat();
|
||||||
});
|
});
|
||||||
|
|
||||||
function replaceTransitionHandler() {
|
function replaceTransitionHandler() {
|
||||||
@@ -355,15 +356,46 @@ function initPageLoadHandler() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
//pageLoadHandler for login
|
//pageLoadHandler for login
|
||||||
$(document).on('pagebeforeshow', '#login', function () {
|
$(document).on('pagebeforeshow', '#login', pagebeforeshowLogin);
|
||||||
ownProfileId = -1;
|
|
||||||
profileIdRequest = -1;
|
|
||||||
songIdRequest = -1
|
|
||||||
sessionId = "";
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function pagebeforeshowLogin() {
|
||||||
|
if (window.localStorage) {
|
||||||
|
var value = window.localStorage.getItem("VocaluxeSessionKey");
|
||||||
|
if (value != null && value != "") {
|
||||||
|
sessionId = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sessionId != "") {
|
||||||
|
if (ownProfileId != -1) {
|
||||||
|
$.mobile.changePage("#main", { transition: "slidefade" });
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$('#content').wrap('<div class="overlay" />');
|
||||||
|
$.mobile.loading('show', {
|
||||||
|
text: 'Login...',
|
||||||
|
textVisible: true
|
||||||
|
});
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: "getOwnProfileId",
|
||||||
|
headers: { "session": sessionId }
|
||||||
|
}).done(function (result) {
|
||||||
|
ownProfileId = result;
|
||||||
|
|
||||||
|
$.mobile.loading('hide');
|
||||||
|
$('#content').unwrap();
|
||||||
|
$.mobile.changePage("#main", { transition: "slidefade" });
|
||||||
|
}).fail(function (result) {
|
||||||
|
$.mobile.loading('hide');
|
||||||
|
$('#content').unwrap();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function initLoginPageHandler() {
|
function initLoginPageHandler() {
|
||||||
var keyPressed = function (e) {
|
var keyPressed = function (e) {
|
||||||
if (e.which == 13) {
|
if (e.which == 13) {
|
||||||
@@ -388,6 +420,9 @@ function initLoginPageHandler() {
|
|||||||
url: "login?username=" + username + "&password=" + password
|
url: "login?username=" + username + "&password=" + password
|
||||||
}).done(function (result) {
|
}).done(function (result) {
|
||||||
sessionId = result;
|
sessionId = result;
|
||||||
|
if (window.localStorage) {
|
||||||
|
window.localStorage.setItem("VocaluxeSessionKey", sessionId);
|
||||||
|
}
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "getOwnProfileId",
|
url: "getOwnProfileId",
|
||||||
headers: { "session": sessionId }
|
headers: { "session": sessionId }
|
||||||
@@ -413,6 +448,9 @@ function initLoginPageHandler() {
|
|||||||
profileIdRequest = -1;
|
profileIdRequest = -1;
|
||||||
$.mobile.changePage("#displayProfile", { transition: "slidefade" });
|
$.mobile.changePage("#displayProfile", { transition: "slidefade" });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//Fire pageLoadHandler for login
|
||||||
|
pagebeforeshowLogin();
|
||||||
}
|
}
|
||||||
|
|
||||||
function initMainPageHandler() {
|
function initMainPageHandler() {
|
||||||
@@ -484,7 +522,9 @@ function initMainPageHandler() {
|
|||||||
$('#capture').click();
|
$('#capture').click();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#mainPageLogoutLink').click(function () {
|
||||||
|
logout();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function initKeyboardPageHandler() {
|
function initKeyboardPageHandler() {
|
||||||
@@ -593,3 +633,28 @@ function addImage(img, base64Image, defaultImg) {
|
|||||||
$(img).prop("src", defaultImg);
|
$(img).prop("src", defaultImg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function logout() {
|
||||||
|
ownProfileId = -1;
|
||||||
|
profileIdRequest = -1;
|
||||||
|
songIdRequest = -1
|
||||||
|
sessionId = "";
|
||||||
|
$.mobile.changePage("#login", { transition: "slidefade" });
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkSession() {
|
||||||
|
$.ajax({
|
||||||
|
url: "getOwnProfileId",
|
||||||
|
headers: { "session": sessionId }
|
||||||
|
}).done(function (result) {
|
||||||
|
if (result == -1) {
|
||||||
|
logout();
|
||||||
|
}
|
||||||
|
}).fail(function (result) {
|
||||||
|
logout();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function initHeartbeat() {
|
||||||
|
setInterval(checkSession, 20000);
|
||||||
|
}
|
||||||
Reference in new issue
Block a user