X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=js%2F95-login.js;h=6036aef912343ba1049dc0795ca6ba8b845b25c0;hb=7baee29b2642aabb77a24745dc8be86440c30a4f;hp=a4e2d8296fef6951f4545609c89973ae3e305586;hpb=462db4aa165159efd9aa859ef8a36654c731e9c4;p=plack-app-gruntmaster.git diff --git a/js/95-login.js b/js/95-login.js index a4e2d82..6036aef 100644 --- a/js/95-login.js +++ b/js/95-login.js @@ -1,22 +1,24 @@ -(function(){ - 'use strict'; - - $( document ).ready(function(){ - $('#login').detach().prependTo($('#sidebar')).removeClass('hidden'); - - document.cookie = "cookietest=1"; - var cookie = document.cookie.indexOf("cookietest=") != -1; - document.cookie = "cookietest=1; expires=Thu, 01-Jan-1970 00:00:01 GMT"; - - if(!cookie) return; - var username = document.cookie.replace(/(?:(?:^|.*;\s*)username\s*\=\s*([^;]*).*$)|^.*$/, "$1"); - if(username) { +$(function(){ + const sidebar = q('#sidebar'); + const login = document.createElement('div'); + login.innerHTML = 'Log in'; + sidebar.insertBefore(login, sidebar.firstChild); + $('#login').on('click', e => { + const xhr = new XMLHttpRequest(); + xhr.open('GET', '/login'); + xhr.onload = () => { + if(xhr.status != 200) + return; + const username = xhr.responseText; sessionStorage.setItem('login_username', username); - document.cookie = "username=; expires=Thu, 01-Jan-1970 00:00:01 GMT"; start_tracking(username); + login.innerHTML = 'Probably logged in as ' + username; } - username = sessionStorage.getItem('login_username'); - if(username) - $('#login').replaceWith('Probably logged in as ' + username + ''); + xhr.send(); + return false; }); -})(); + + const username = sessionStorage.getItem('login_username'); + if(username) + login.innerHTML = 'Probably logged in as ' + username; +});