Webserver: autologin added, check if session has been closed frequently
This commit is contained in:
1 parent
f27aae0ae2
commit
f7cb09f47a
2 files changed
+72
-7
No files matched your search
@@ -90,7 +90,7 @@
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#login" data-transition="slidefade">
|
||||
<a id="mainPageLogoutLink" href="#" data-transition="slidefade">
|
||||
<img src="img/logout.png">
|
||||
<h2>Logout</h2>
|
||||
<p>Closes the session</p>
|
||||
|
||||
@@ -10,6 +10,7 @@ $(document).ready(function () {
|
||||
initKeyboardPageHandler();
|
||||
initMainPageHandler();
|
||||
initLoginPageHandler();
|
||||
initHeartbeat();
|
||||
});
|
||||
|
||||
function replaceTransitionHandler() {
|
||||
@@ -355,13 +356,44 @@ function initPageLoadHandler() {
|
||||
});
|
||||
|
||||
//pageLoadHandler for login
|
||||
$(document).on('pagebeforeshow', '#login', function () {
|
||||
ownProfileId = -1;
|
||||
profileIdRequest = -1;
|
||||
songIdRequest = -1
|
||||
sessionId = "";
|
||||
$(document).on('pagebeforeshow', '#login', pagebeforeshowLogin);
|
||||
|
||||
}
|
||||
|
||||
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() {
|
||||
@@ -388,6 +420,9 @@ function initLoginPageHandler() {
|
||||
url: "login?username=" + username + "&password=" + password
|
||||
}).done(function (result) {
|
||||
sessionId = result;
|
||||
if (window.localStorage) {
|
||||
window.localStorage.setItem("VocaluxeSessionKey", sessionId);
|
||||
}
|
||||
$.ajax({
|
||||
url: "getOwnProfileId",
|
||||
headers: { "session": sessionId }
|
||||
@@ -413,6 +448,9 @@ function initLoginPageHandler() {
|
||||
profileIdRequest = -1;
|
||||
$.mobile.changePage("#displayProfile", { transition: "slidefade" });
|
||||
});
|
||||
|
||||
//Fire pageLoadHandler for login
|
||||
pagebeforeshowLogin();
|
||||
}
|
||||
|
||||
function initMainPageHandler() {
|
||||
@@ -484,7 +522,9 @@ function initMainPageHandler() {
|
||||
$('#capture').click();
|
||||
});
|
||||
|
||||
|
||||
$('#mainPageLogoutLink').click(function () {
|
||||
logout();
|
||||
});
|
||||
}
|
||||
|
||||
function initKeyboardPageHandler() {
|
||||
@@ -593,3 +633,28 @@ function addImage(img, base64Image, 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