Fix channellist page to use session login

This commit is contained in:
calzoneman 2013-04-26 12:47:26 -05:00
parent 6eaa97ccb8
commit d1b06413ee
1 changed files with 48 additions and 1 deletions

View File

@ -45,15 +45,38 @@
<script src="assets/js/jquery.js" type="text/javascript"></script> <script src="assets/js/jquery.js" type="text/javascript"></script>
<script src="assets/js/iourl.js" type="text/javascript"></script> <script src="assets/js/iourl.js" type="text/javascript"></script>
<script type="text/javascript"> <script type="text/javascript">
var session = readCookie("sync_session") || "";
var uname = readCookie("sync_uname") || "";
if(uname && session) {
$.getJSON(IO_URL+"/api/json/login?name="+uname+"&session="+session+"&callback=?", function(data) {
if(data.success) {
$(".loginform").remove();
setCookie("sync_uname", uname, 7);
setCookie("sync_session", session, 7);
}
});
}
var q = ""; var q = "";
var p = "";
$("#login").click(function() { $("#login").click(function() {
uname = $("#name").val();
q = "name=" + $("#name").val() + "&pw=" + $("#pw").val(); q = "name=" + $("#name").val() + "&pw=" + $("#pw").val();
$.getJSON(IO_URL+"/api/json/login?"+q+"&callback=?", function(data) {
if(data.success) {
$(".loginform").remove();
session = data.session;
createCookie("sync_uname", uname, 7);
createCookie("sync_session", session, 7);
p = "name=" + uname + "&session=" + session;
}
});
refresh(); refresh();
setInterval(refresh, 5000); setInterval(refresh, 5000);
}); });
function refresh() { function refresh() {
$.getJSON(IO_URL+"/api/json/listloaded?"+q+"&callback=?", function(data) { $.getJSON(IO_URL+"/api/json/listloaded?"+p+"&callback=?", function(data) {
var host = document.location + ""; var host = document.location + "";
host = host.substring(0, host.indexOf("/widget.html")); host = host.substring(0, host.indexOf("/widget.html"));
if(data.error) { if(data.error) {
@ -84,6 +107,30 @@
} }
}); });
} }
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(";");
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==" ") c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function eraseCookie(name) {
createCookie(name,"",-1);
}
</script> </script>
</body> </body>
</html> </html>