diff options
author | Dave Arter <davea@mysociety.org> | 2017-08-31 13:46:39 +0100 |
---|---|---|
committer | Dave Arter <davea@mysociety.org> | 2017-08-31 13:46:39 +0100 |
commit | 330ffab561593370f06ea23871749ca3e6bfb3db (patch) | |
tree | cdf5dd9cbf45945eb90558c7da924635543e7ff4 /perllib/FixMyStreet/App/Controller/Root.pm | |
parent | 07d3568a02b5efb4286bccd9f869c8e1605928b5 (diff) | |
parent | 455ce61c10fa885c04148b4d095acefbf07a4b33 (diff) |
Merge branch 'issues/commercial/840-groundcontrol'
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Root.pm')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Root.pm | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Root.pm b/perllib/FixMyStreet/App/Controller/Root.pm index 64d7fa6ae..7f70623ae 100644 --- a/perllib/FixMyStreet/App/Controller/Root.pm +++ b/perllib/FixMyStreet/App/Controller/Root.pm @@ -16,6 +16,18 @@ FixMyStreet::App::Controller::Root - Root Controller for FixMyStreet::App =head1 METHODS +=head2 begin + +Any pre-flight checking for all requests + +=cut +sub begin : Private { + my ( $self, $c ) = @_; + + $c->forward( 'check_login_required' ); +} + + =head2 auto Set up general things for this instance @@ -130,6 +142,27 @@ sub page_error : Private { $c->response->status($code); } +sub check_login_required : Private { + my ($self, $c) = @_; + + return if $c->user_exists || !FixMyStreet->config('LOGIN_REQUIRED'); + + # Whitelisted URL patterns are allowed without login + my $whitelist = qr{ + ^auth(/|$) + | ^js/translation_strings\.(.*?)\.js + | ^[PACQM]/ # various tokens that log the user in + }x; + return if $c->request->path =~ $whitelist; + + # Blacklisted URLs immediately 404 + # This is primarily to work around a Safari bug where the appcache + # URL is requested in an infinite loop if it returns a 302 redirect. + $c->detach('/page_error_404_not_found', []) if $c->request->path =~ /^offline/; + + $c->detach( '/auth/redirect' ); +} + =head2 end Attempt to render a view, if needed. |