aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App/Controller/Auth.pm
diff options
context:
space:
mode:
authorDave Whiteland <dave@mysociety.org>2012-06-25 14:33:57 +0100
committerDave Whiteland <dave@mysociety.org>2012-06-25 14:33:57 +0100
commitf9fe02f91ac72ea2954ee68a5f32d96a237fcd67 (patch)
treef91d63ab3d6b9cd3555587090a541c870ecd3363 /perllib/FixMyStreet/App/Controller/Auth.pm
parent67da8efc720d2d0bd22bd9fe8655b7e983b35bb4 (diff)
parent45b3040884d7089e7d8c6f4acccd657b91c92a04 (diff)
Merge branch 'master' into fmb-read-only
Conflicts: .gitignore bin/make_css perllib/FixMyStreet/Cobrand/FixMyStreet.pm
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