| 1 | package Bracket::Controller::Root; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use parent 'Catalyst::Controller'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use Perl6::Junction qw/ any /; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use DateTime; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # Sets the actions in this controller to be registered with no prefix | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # so they function identically to actions created in MyApp.pm | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 4 | __PACKAGE__->config->{namespace} = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | Bracket::Controller::Root - Root Controller for Bracket | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | Handle Security. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | =head2 auto | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | Make sure we're logged in when we should be. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 6 | ▶ | sub auto : Private { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
auto: called CC=9 SCAR=36.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 6 | my ($self, $c) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 6 | my @open_actions = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | $c->controller('Auth')->action_for('register'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | $c->controller('Auth')->action_for('login'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | $c->controller('Auth')->action_for('email_reset_password_link'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | $c->controller('Auth')->action_for('reset_password'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | # Allow unauthenticated users to reach the open actions like 'login'. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 6 | ▶ | if ($c->action eq any(@open_actions)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 5 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | # If a user doesn't exist, force login | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | ▶ | if (!$c->user_exists) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | # Redirect the user to the login page | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 1 | $c->response->redirect($c->uri_for($c->controller('Auth')->action_for('login'))); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | # Return 0 to cancel 'post-auto' processing and prevent use of application | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | # Stash in home page link if we're not on home page. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
$c->action ne $c->controller("Player")->action_for("home") or $c->action eq $c->controller("Player")->action_for("home") and ($c->req->args->[0] and $c->req->args->[0] != $c->user->id)
$c->action eq $c->controller("Player")->action_for("home") and ($c->req->args->[0] and $c->req->args->[0] != $c->user->id)
$c->req->args->[0] and $c->req->args->[0] != $c->user->id
MC/DC0%0/4
$c->action ne $c->controller("Player")->action_for("home") or $c->action eq $c->controller("Player")->action_for("home") and ($c->req->args->[0] and $c->req->args->[0] != $c->user->id)
$c->action ne $c->controller("Player")->action_for("home")
$c->action eq $c->controller("Player")->action_for("home")
$c->req->args->[0]
$c->req->args->[0] != $c->user->id
Truth table0%0/5
A or B and C and D
A= $c->action ne $c->controller("Player")->action_for("home")B= $c->action eq $c->controller("Player")->action_for("home")C= $c->req->args->[0]D= $c->req->args->[0] != $c->user->id
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | ($c->action ne $c->controller('Player')->action_for('home')) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | || ( ($c->action eq $c->controller('Player')->action_for('home')) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | && ($c->req->args->[0] && ($c->req->args->[0]) != $c->user->id)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | $c->stash->{show_home} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | # See if player is an admin to get admin only links (e.g. Perfect Player access) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | my @user_roles = $c->user->roles; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | if ('admin' eq any(@user_roles)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | $c->stash->{is_admin} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | # Set cutoff state | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | my $cutoff_time = $self->edit_cutoff_time($c); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | $c->stash->{is_game_time} = (DateTime->now(time_zone => $cutoff_time->time_zone) > $cutoff_time); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | # Note if we have a normal user in game time (used to hide edit links) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | $c->stash->{is_normal_user_in_game_time} = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | (!$c->stash->{is_admin} && $c->stash->{is_game_time}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
!$c->stash->{'is_admin'} && $c->stash->{'is_game_time'}
MC/DC0%0/2
!$c->stash->{'is_admin'} && $c->stash->{'is_game_time'}
!$c->stash->{'is_admin'}
$c->stash->{'is_game_time'}
Truth table0%0/3
not(A) && B
A= !$c->stash->{'is_admin'}B= $c->stash->{'is_game_time'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | # User found, so return 1 to continue with processing after this 'auto' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 4 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | =head2 index | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | Handle root index by redirecting to home when logged in. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | sub index : Path : Args(0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
index: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | my ($self, $c) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | # Clear the user's state | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | # Send the user to the starting point | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | $c->go($c->controller('Player')->action_for('home'), [ $c->user->id ]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 4 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | =head2 default | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | sub default : Private { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | my ($self, $c) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | # $c->response->body( $c->welcome_message ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | $c->go('/error_404'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 4 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | sub error_404 : Path('error_404') : Args(0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
error_404: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | my ($self, $c) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | $c->res->status(404); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | $c->stash->{template} = 'page_not_found.tt'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 4 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | =head2 end | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | Attempt to render a view, if needed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 6 | ▶ | sub end : ActionClass('RenderView') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
end: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 4 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | # This needs to be edited in future years to reflect the start date/time. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | # TODO: Put into conf | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | sub edit_cutoff_time { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
edit_cutoff_time: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | my ($self, $c) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | my $cutoff = $c->config->{edit_cutoff_time}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | return DateTime->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | year => $cutoff->{year}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | month => $cutoff->{month}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | day => $cutoff->{day}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | hour => $cutoff->{hour}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | minute => $cutoff->{minute}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | second => $cutoff->{second}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | time_zone => $cutoff->{time_zone}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | root | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | =head1 LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | This library is free software, you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||