Fix legacy login

This commit is contained in:
Eelco Dolstra 2013-07-09 13:55:44 +02:00
parent 9aa44fa944
commit 1db9381473
3 changed files with 45 additions and 56 deletions

View file

@ -58,19 +58,10 @@ sub logout :Local :Args(0) :ActionClass('REST::ForBrowsers') { }
sub logout_POST {
my ($self, $c) = @_;
$c->flash->{flashMsg} = "You are no longer signed in." if $c->user_exists();
$c->logout;
if ($c->request->looks_like_browser) {
$c->response->redirect($c->request->referer || $c->uri_for('/'));
} else {
$self->status_no_content($c);
}
}
sub logout_GET {
# Probably a better way to do this
my ($self, $c) = @_;
logout_POST($self, $c);
}
sub persona_login :Path('/persona-login') Args(0) {
@ -107,16 +98,7 @@ sub persona_login :Path('/persona-login') Args(0) {
$c->set_authenticated($user);
$c->stash->{json}->{result} = "ok";
$c->flash->{successMsg} = "You are now signed in as <tt>" . encode_entities($email) . "</tt>";
}
sub persona_logout :Path('/persona-logout') Args(0) {
my ($self, $c) = @_;
$c->stash->{json} = {};
requirePost($c);
$c->flash->{flashMsg} = "You are no longer signed in." if $c->user_exists();
$c->logout;
$c->flash->{successMsg} = "You are now signed in as <tt>" . encode_entities($email) . "</tt>.";
}

View file

@ -102,6 +102,21 @@
</div>
<script>
function doLogout() {
$.post("[% c.uri_for('/logout') %]")
.done(function(data) {
window.location.reload();
})
.fail(function() { bootbox.alert("Server request failed!"); });
}
</script>
[% IF c.user_exists && c.user.password != '!' %]
<script>
$("#persona-signout").click(doLogout);
</script>
[% ELSE %]
<script src="https://login.persona.org/include.js"></script>
<script>
@ -117,13 +132,7 @@
})
.fail(function() { bootbox.alert("Server request failed!"); });
},
onlogout: function() {
$.post("[% c.uri_for('/persona-logout') %]")
.done(function(data) {
window.location.reload();
})
.fail(function() { bootbox.alert("Server request failed!"); });
}
onlogout: doLogout
});
$("#persona-signin").click(function() {
@ -134,6 +143,7 @@
navigator.id.logout();
});
</script>
[% END %]
</body>

View file

@ -2,9 +2,8 @@
[% PROCESS common.tt %]
[% IF c.user_exists %]
<p class="btn-info btn-large">
You are already logged in as <tt>[% c.user.username %]</tt>.
You can <a href="[% c.uri_for('/logout') %]">logout</a> here.
<p class="alert alert-info">
You are already signed in as <tt>[% HTML.escape(c.user.username) %]</tt>.
</p>
[% ELSE %]
@ -13,7 +12,6 @@ You can <a href="[% c.uri_for('/logout') %]">logout</a> here.
c.uri_for('/register') %]">register</a> first.</p>
-->
<!--
<form class="form-horizontal" method="post" action="[% c.uri_for('/login') %]">
<fieldset>
@ -37,7 +35,6 @@ c.uri_for('/register') %]">register</a> first.</p>
</fieldset>
</form>
-->
[% END %]