$(function(){ try { var auth_code = localStorage.getItem("digista_webar"); } catch (e) { auth_code = $.cookie("digista_webar"); } if (!auth_code) { create(); } else { auth(auth_code); } }); function create() { $.getJSON('/webar/Auth/create', function(data){ var authed = false; if ('RESULT' in data) { if (data.RESULT == 'SUCCESS') { localStorage.setItem("digista_webar", data.code); $.cookie("digista_webar", data.code); authed = true; location.reload(); } } if (authed == false) { setTimeout(function(){ create(); }, 500); } }); } function auth(code) { $.getJSON('/webar/Auth/check/?K=' + encodeURIComponent(code), function(data){ var authed = false; if ('RESULT' in data) { if (data.RESULT == 'SUCCESS') { authed = true; if ('regen' in data) { create(); } } } if (authed == false) { setTimeout(function(){ auth(code); }, 500); } else { location.reload(); } }); }