aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App/Controller/Auth.pm
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2012-06-15 12:23:54 +0100
committerStruan Donald <struan@exo.org.uk>2012-06-15 12:23:54 +0100
commitcc1aa4a6676db38eabed168327941c6aa93b4654 (patch)
treea7848a02a53b88e89450de4fd187e7939fb61e80 /perllib/FixMyStreet/App/Controller/Auth.pm
parent3a25a77b31e955ae6db9f7bd22120ef421aa5d92 (diff)
parentd0c522739862671cc0ffa5cc1611d3772fe732bd (diff)
Merge branch 'phonegap'
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Auth.pm')
-rw-r--r--perllib/FixMyStreet/App/Controller/Auth.pm49
1 files changed, 49 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Auth.pm b/perllib/FixMyStreet/App/Controller/Auth.pm
index c67de692a..3dc25dedf 100644
--- a/perllib/FixMyStreet/App/Controller/Auth.pm
+++ b/perllib/FixMyStreet/App/Controller/Auth.pm
@@ -7,6 +7,7 @@ BEGIN { extends 'Catalyst::Controller'; }
use Email::Valid;
use Net::Domain::TLD;
use mySociety::AuthToken;
+use JSON;
=head1 NAME
@@ -250,6 +251,54 @@ sub sign_out : Local {
$c->logout();
}
+sub ajax_sign_in : Path('ajax/sign_in') {
+ my ( $self, $c ) = @_;
+
+ my $return = {};
+ if ( $c->forward( 'sign_in' ) ) {
+ $return->{name} = $c->user->name;
+ } else {
+ $return->{error} = 1;
+ }
+
+ my $body = JSON->new->utf8(1)->encode( $return );
+ $c->res->content_type('application/json; charset=utf-8');
+ $c->res->body($body);
+
+ return 1;
+}
+
+sub ajax_sign_out : Path('ajax/sign_out') {
+ my ( $self, $c ) = @_;
+
+ $c->logout();
+
+ my $body = JSON->new->utf8(1)->encode( { signed_out => 1 } );
+ $c->res->content_type('application/json; charset=utf-8');
+ $c->res->body($body);
+
+ return 1;
+}
+
+sub ajax_check_auth : Path('ajax/check_auth') {
+ my ( $self, $c ) = @_;
+
+ my $code = 401;
+ my $data = { not_authorized => 1 };
+
+ if ( $c->user ) {
+ $data = { name => $c->user->name };
+ $code = 200;
+ }
+
+ my $body = JSON->new->utf8(1)->encode( $data );
+ $c->res->content_type('application/json; charset=utf-8');
+ $c->res->code($code);
+ $c->res->body($body);
+
+ return 1;
+}
+
=head2 check_auth
Utility page - returns a simple message 'OK' and a 200 response if the user is