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 { sub logout_POST {
my ($self, $c) = @_; my ($self, $c) = @_;
$c->flash->{flashMsg} = "You are no longer signed in." if $c->user_exists();
$c->logout; $c->logout;
if ($c->request->looks_like_browser) { $self->status_no_content($c);
$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);
} }
@ -107,16 +98,7 @@ sub persona_login :Path('/persona-login') Args(0) {
$c->set_authenticated($user); $c->set_authenticated($user);
$c->stash->{json}->{result} = "ok"; $c->stash->{json}->{result} = "ok";
$c->flash->{successMsg} = "You are now signed in as <tt>" . encode_entities($email) . "</tt>"; $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;
} }

View file

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

View file

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