From: Marius Gavrilescu Date: Tue, 20 Jan 2015 12:12:19 +0000 (+0200) Subject: Add a fake login link X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=462db4aa165159efd9aa859ef8a36654c731e9c4;p=plack-app-gruntmaster.git Add a fake login link --- diff --git a/MANIFEST b/MANIFEST index 14f50e6..d6b3f00 100644 --- a/MANIFEST +++ b/MANIFEST @@ -19,6 +19,7 @@ js/90-divine-format.js js/90-form.js js/90-themes.js js/90-nav.js +js/95-login.js lib/Plack/App/Gruntmaster.pm lib/Plack/App/Gruntmaster/HTML.pm log.conf diff --git a/js/90-tracker.js b/js/90-tracker.js index 8e7a443..aac598e 100644 --- a/js/90-tracker.js +++ b/js/90-tracker.js @@ -84,6 +84,7 @@ }; xhr.send(); } + window.start_tracking = start_tracking; function stop_tracking(){ clean_tracker(); diff --git a/js/95-login.js b/js/95-login.js new file mode 100644 index 0000000..a4e2d82 --- /dev/null +++ b/js/95-login.js @@ -0,0 +1,22 @@ +(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) { + sessionStorage.setItem('login_username', username); + document.cookie = "username=; expires=Thu, 01-Jan-1970 00:00:01 GMT"; + start_tracking(username); + } + username = sessionStorage.getItem('login_username'); + if(username) + $('#login').replaceWith('Probably logged in as ' + username + ''); + }); +})(); diff --git a/lib/Plack/App/Gruntmaster.pm b/lib/Plack/App/Gruntmaster.pm index a809e46..8aab08c 100644 --- a/lib/Plack/App/Gruntmaster.pm +++ b/lib/Plack/App/Gruntmaster.pm @@ -148,6 +148,12 @@ sub dispatch_request{ }, 10 }, + sub (/login) { + forbid !remote_user; + + [204, ['Set-Cookie' => "username=".remote_user->id], []] + }, + sub (/ct/:contest/log/st) { redirect "/st/$_{contest}" }, sub (/us/) { response us => 'Users', {us => db->user_list} }, diff --git a/tmpl/skel.en b/tmpl/skel.en index 3024251..6bf5954 100644 --- a/tmpl/skel.en +++ b/tmpl/skel.en @@ -37,6 +37,8 @@
Content goes here
+ +