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,18 +58,9 @@ 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);
$self->status_no_content($c);
}
@ -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,39 +102,49 @@
</div>
<script src="https://login.persona.org/include.js"></script>
<script>
navigator.id.watch({
loggedInUser: [% c.user_exists ? '"' _ HTML.escape(c.user.username) _ '"' : "null" %],
onlogin: function(assertion) {
$.post("[% c.uri_for('/persona-login') %]", { assertion: assertion })
.done(function(data) {
if (data.error)
bootbox.alert("Login failed: " + data.error);
else
window.location.reload();
})
.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!"); });
}
});
$("#persona-signin").click(function() {
navigator.id.request();
});
$("#persona-signout").click(function() {
navigator.id.logout();
});
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>
navigator.id.watch({
loggedInUser: [% c.user_exists ? '"' _ HTML.escape(c.user.username) _ '"' : "null" %],
onlogin: function(assertion) {
$.post("[% c.uri_for('/persona-login') %]", { assertion: assertion })
.done(function(data) {
if (data.error)
bootbox.alert("Login failed: " + data.error);
else
window.location.reload();
})
.fail(function() { bootbox.alert("Server request failed!"); });
},
onlogout: doLogout
});
$("#persona-signin").click(function() {
navigator.id.request();
});
$("#persona-signout").click(function() {
navigator.id.logout();
});
</script>
[% END %]
</body>
</html>

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 %]