]> iEval git - plack-app-gruntmaster.git/commitdiff
Remove login dependency on cookies & referer
authorMarius Gavrilescu <marius@ieval.ro>
Mon, 16 Mar 2015 10:04:24 +0000 (12:04 +0200)
committerMarius Gavrilescu <marius@ieval.ro>
Mon, 16 Mar 2015 10:04:24 +0000 (12:04 +0200)
js/95-login.js
lib/Plack/App/Gruntmaster.pm
tmpl/skel.en

index 81e4533f0b3df969599c0724b399108153a955ca..60ede9d841f25513cbae78eb5ee1daf5b5e5ee36 100644 (file)
@@ -2,20 +2,22 @@
        'use strict';
 
        $( document ).ready(function(){
-               $('#login').detach().prependTo($('#sidebar'));
+               $('#login').detach().prependTo($('#sidebar')).on('click', function(e) {
+                       var xhr = new XMLHttpRequest();
+                       xhr.open('GET', '/login');
+                       xhr.onload = function () {
+                               if(this.status != 200)
+                                       return;
+                               var username = this.responseText;
+                               sessionStorage.setItem('login_username', username);
+                               start_tracking(username);
+                               $('#login').html('Probably logged in as ' + username);
+                       }
+                       xhr.send();
+                       return false;
+               });
 
-               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');
+               var username = sessionStorage.getItem('login_username');
                if(username)
                        $('#login').html('Probably logged in as ' + username);
        });
index 0666fad804a3329bf41ddade92c129b954c6a7ab..7a3dc348b065037ae139a111b2494945a85eb747 100644 (file)
@@ -140,9 +140,7 @@ sub dispatch_request{
 
                sub (/login) {
                        forbid !remote_user;
-
-                       my $return = $env->{HTTP_REFERER} // '/';
-                       [303, ['Set-Cookie' => "username=".remote_user->id, Location => $return], []]
+                       [200, ['Content-Type' => 'text/plain; charset=UTF-8', 'Cache-Control' => 'private, max-age=300', Vary => 'Authorization'], [$env->{REMOTE_USER}]]
                },
 
                sub (/ct/:contest/log/st) { redirect "/st/$_{contest}" },
index b713e0e2ec927d4e0eedc70abd530935fb43a382..39b4ddae50435374e95c80aea92ae7e187a0b776 100644 (file)
@@ -31,7 +31,7 @@
 
 <div id="content">Content goes here</div>
 
-<div id="login" class="reqjs"><a href="/login">Log in</a></div>
+<div id="login" class="reqjs"><a href="#">Log in</a></div>
 
 <div id="theme-selector" class="reqjs">
 Themes:
This page took 0.022502 seconds and 4 git commands to generate.