File Coverage

blib/lib/RapidApp/Role/AuthController.pm
Criterion Covered Total %
statement 9 16 56.2
branch 0 4 0.0
condition 0 3 0.0
subroutine 3 4 75.0
pod 0 1 0.0
total 12 28 42.8


line stmt bran cond sub pod time code
1             package RapidApp::Role::AuthController;
2 4     4   2653 use strict;
  4         10  
  4         118  
3 4     4   18 use warnings;
  4         11  
  4         124  
4              
5             =pod
6              
7             =head1 DESCRIPTION
8              
9             New role designed to enforce RapidApp authenticated sessions in
10             normal Controllers (i.e. not RapidApp 'Modules')
11              
12             This is an alternative to 'AuthRequire' which is specific to Modules
13             and will be depricated along with Modules in the future
14              
15             =cut
16              
17 4     4   21 use Moose::Role;
  4         6  
  4         34  
18              
19             requires '_app';
20              
21             # TODO: is this bad? Doesn't seem immediately possible with: sub begin :Private {...}
22             before '_BEGIN' => sub {
23             my ( $self, $c ) = @_;
24             $self->enforce_rapidapp_session($c);
25             };
26              
27             sub enforce_rapidapp_session {
28 0     0 0   my ( $self, $c ) = @_;
29            
30             # ignored if session plugin isn't loaded:
31 0 0         return unless $c->can('session_is_valid');
32            
33 0 0 0       unless ($c->session_is_valid and $c->user_exists) {
34 0           $c->res->header('X-RapidApp-Authenticated' => 0);
35 0           $c->res->header( 'Content-Type' => 'text/plain' );
36 0           $c->res->body('No session');
37 0           $c->detach;
38             }
39             }
40              
41             1;