'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);
});
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}" },
<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: