diff options
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Auth.pm')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Auth.pm | 49 |
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 |