]> iEval git - gruntmaster-page.git/commitdiff
Add a fake login link
authorMarius Gavrilescu <marius@ieval.ro>
Tue, 20 Jan 2015 12:12:19 +0000 (14:12 +0200)
committerMarius Gavrilescu <marius@ieval.ro>
Tue, 20 Jan 2015 12:12:19 +0000 (14:12 +0200)
MANIFEST
js/90-tracker.js
js/95-login.js [new file with mode: 0644]
lib/Plack/App/Gruntmaster.pm
tmpl/skel.en

index 14f50e6ac7d10ec664b3d0bc4ca91afdd78cf161..d6b3f0027842077c207fc4aa545d43701e9a76c8 100644 (file)
--- 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
index 8e7a4433f8965affad02929e49cc431296d13fa4..aac598e6bf571d547b8925aaee3474d08ac0e9da 100644 (file)
@@ -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 (file)
index 0000000..a4e2d82
--- /dev/null
@@ -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('<span id="login">Probably logged in as ' + username + '</span>');
+       });
+})();
index a809e4669863bc3d77bf4b17cfec39fd9680650e..8aab08c2c7e261f50418d9f5454d44fb25baa1a6 100644 (file)
@@ -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} },
index 3024251090bbb5fa8573c84b358a60142e73e6d3..6bf59540900189482f7e6d4942d51f73d6cabfd6 100644 (file)
@@ -37,6 +37,8 @@
 
 <div id="content">Content goes here</div>
 
+<a href="/login" id="login" class="hidden">Log in</a>
+
 <div id="tracker" class="hidden">
 <h1>Track user</h1>
 <div id="tracker_form">
This page took 0.035355 seconds and 4 git commands to generate.