line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MojoMojo::Controller::Root; |
2
|
|
|
|
|
|
|
|
3
|
35
|
|
|
35
|
|
17962
|
use parent 'Catalyst::Controller'; |
|
35
|
|
|
|
|
93
|
|
|
35
|
|
|
|
|
370
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
__PACKAGE__->config->{namespace} = ''; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
MojoMojo::Controller::Root - Controller to run before all others |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 ACTIONS |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head2 begin (builtin) |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
TODO |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=cut |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub begin : Private { |
20
|
194
|
|
|
194
|
|
350692
|
my ( $self, $c ) = @_; |
21
|
194
|
50
|
66
|
|
|
1183
|
if($c->sessionid && $c->session->{lang}) { |
22
|
0
|
|
|
|
|
0
|
$c->languages([$c->session->{lang}]); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
else { |
25
|
194
|
50
|
|
|
|
443433
|
$c->languages([$c->pref('default_lang')]) if $c->pref('default_lang'); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
# $c->stash->{path} is set by MojoMojo::prepare_path, which overrides the built-in Catalyst method |
28
|
194
|
50
|
|
|
|
99248
|
if ( $c->stash->{path} ) { |
29
|
|
|
|
|
|
|
my ( $path_pages, $proto_pages ) = |
30
|
194
|
|
|
|
|
15697
|
$c->model('DBIC::Page')->path_pages( $c->stash->{path} ); |
31
|
194
|
|
|
|
|
8271
|
@{ $c->stash }{qw/ path_pages proto_pages /} = ( $path_pages, $proto_pages ); |
|
194
|
|
|
|
|
3779
|
|
32
|
194
|
|
|
|
|
15975
|
$c->stash->{page} = $path_pages->[ @$path_pages - 1 ]; |
33
|
194
|
100
|
66
|
|
|
12659
|
$c->stash->{user} = $c->user->obj() if $c->user_exists && $c->user; |
34
|
|
|
|
|
|
|
} |
35
|
35
|
|
|
35
|
|
7810
|
} |
|
35
|
|
|
|
|
86
|
|
|
35
|
|
|
|
|
209
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head2 default (global) |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Default action - display the error page (message.tt), for example when a |
40
|
|
|
|
|
|
|
nonexistent action was requested (like C</parent_page/child_page.fireworks>). |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=cut |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub default : Path { |
45
|
1
|
|
|
1
|
1
|
1054
|
my ( $self, $c ) = @_; |
46
|
1
|
|
|
|
|
5
|
$c->res->status(404); |
47
|
|
|
|
|
|
|
$c->stash->{message} = $c->loc( |
48
|
|
|
|
|
|
|
'The requested URL was not found: x', |
49
|
1
|
|
|
|
|
139
|
'<span class="error_detail">' . $c->stash->{pre_hacked_uri} . '</span>' |
50
|
|
|
|
|
|
|
); |
51
|
1
|
|
|
|
|
909
|
$c->stash->{template} = 'message.tt'; |
52
|
35
|
|
|
35
|
|
438194
|
} |
|
35
|
|
|
|
|
97
|
|
|
35
|
|
|
|
|
196
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head2 set_lang |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
(Re)set language of current session. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=cut |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub set_lang :Global { |
61
|
0
|
|
|
0
|
1
|
0
|
my ($self,$c) = @_; |
62
|
0
|
|
|
|
|
0
|
$c->session->{lang}=$c->req->params->{lang}; |
63
|
0
|
|
|
|
|
0
|
$c->res->redirect( $c->uri_for( $c->stash->{path} ) ); |
64
|
35
|
|
|
35
|
|
33652
|
} |
|
35
|
|
|
|
|
107
|
|
|
35
|
|
|
|
|
170
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head2 render |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Finally, use ActionClass RenderView to render the content. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=cut |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub render : ActionClass('RenderView') { |
73
|
194
|
|
|
194
|
1
|
103944
|
my ($self) = shift; |
74
|
194
|
|
|
|
|
615
|
my ($c) = @_; |
75
|
194
|
|
50
|
|
|
825
|
$c->stash->{path} ||= '/'; |
76
|
35
|
|
|
35
|
|
32086
|
} |
|
35
|
|
|
|
|
90
|
|
|
35
|
|
|
|
|
152
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head2 end (builtin) |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
At the end of any request, forward to view unless there is a template |
81
|
|
|
|
|
|
|
or response, then render the template. If param 'die' is passed, |
82
|
|
|
|
|
|
|
show a debug screen. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=cut |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub end : Private { |
87
|
194
|
|
|
194
|
1
|
293995
|
my ( $self, $c ) = @_; |
88
|
|
|
|
|
|
|
|
89
|
194
|
|
|
|
|
1088
|
my $theme=$c->pref('theme'); |
90
|
|
|
|
|
|
|
# if theme doesn't exist |
91
|
194
|
50
|
|
|
|
39269
|
if ( ! -d $c->path_to('root','static','themes',$theme)) { |
92
|
0
|
|
|
|
|
0
|
$theme='default'; |
93
|
0
|
|
|
|
|
0
|
$c->pref('theme',$theme); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
$c->stash->{additional_template_paths} = |
96
|
194
|
|
|
|
|
58621
|
[ $c->path_to('root','themes',$theme) ]; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
$c->req->uri->path( $c->stash->{pre_hacked_uri}->path ) |
99
|
194
|
50
|
|
|
|
85376
|
if ref $c->stash->{pre_hacked_uri}; |
100
|
194
|
|
|
|
|
43212
|
$c->forward('render'); |
101
|
35
|
|
|
35
|
|
33821
|
} |
|
35
|
|
|
|
|
100
|
|
|
35
|
|
|
|
|
161
|
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head2 auto |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Runs for all requests, checks if user is in need of validation, and |
106
|
|
|
|
|
|
|
intercepts the request if so. Also, if the requested page doesn't exist, |
107
|
|
|
|
|
|
|
prevents any other actions from running, and detaches straight to |
108
|
|
|
|
|
|
|
L<MojoMojo::Controller::Page/suggest>. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=cut |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub auto : Private { |
113
|
194
|
|
|
194
|
1
|
936092
|
my ( $self, $c ) = @_; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# Prevent most actions from running on non-existent pages. This fixes issues #36 and #80. |
116
|
|
|
|
|
|
|
# 'render' should be allowed so that jsrpc/render can be used to preview newly created pages while the first version is being typed in |
117
|
194
|
|
|
|
|
914
|
my $proto_pages = $c->stash->{proto_pages}; |
118
|
194
|
100
|
|
|
|
15850
|
return 1 if $c->action->class =~ m/^MojoMojo::Extensions::/; |
119
|
182
|
50
|
66
|
|
|
7269
|
return $c->res->body('Page does not exist.') |
|
|
|
66
|
|
|
|
|
120
|
|
|
|
|
|
|
if ($proto_pages && @$proto_pages && $c->action->name eq 'inline'); |
121
|
182
|
100
|
66
|
|
|
1880
|
$c->detach('MojoMojo::Controller::Page', 'suggest') |
|
|
|
100
|
|
|
|
|
122
|
|
|
|
|
|
|
if ($proto_pages && @$proto_pages && $c->action->name !~ /^(edit|render|login|logout|register|recover_pass)$/); |
123
|
|
|
|
|
|
|
|
124
|
181
|
50
|
|
|
|
1238
|
if ( $c->pref('enforce_login') ) { |
125
|
|
|
|
|
|
|
# allow a few actions |
126
|
0
|
0
|
|
|
|
0
|
if ( grep $c->action->name eq $_, qw/login logout recover_pass register/ ) { |
127
|
0
|
|
|
|
|
0
|
return 1; |
128
|
|
|
|
|
|
|
} |
129
|
0
|
0
|
|
|
|
0
|
if ( !$c->user_exists ) { |
130
|
|
|
|
|
|
|
$c->res->redirect( |
131
|
|
|
|
|
|
|
$c->uri_for( |
132
|
0
|
|
|
|
|
0
|
$c->stash->{path} . '.login' # send them to the login for this page |
133
|
|
|
|
|
|
|
) |
134
|
|
|
|
|
|
|
); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
181
|
100
|
|
|
|
35328
|
return 1 unless $c->stash->{user}; |
139
|
51
|
50
|
|
|
|
3631
|
return 1 if $c->stash->{user}->active != -1; |
140
|
0
|
0
|
|
|
|
0
|
return 1 if $c->req->action eq 'logout'; |
141
|
0
|
|
|
|
|
0
|
$c->stash->{template} = 'user/validate.tt'; |
142
|
0
|
|
|
|
|
0
|
return 0; |
143
|
35
|
|
|
35
|
|
38849
|
} |
|
35
|
|
|
|
|
94
|
|
|
35
|
|
|
|
|
168
|
|
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head2 exit |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
A way to exit from MojoMojo. Useful when testing leaks. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=cut |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub exit : Local { |
152
|
0
|
|
|
0
|
1
|
|
my ($self, $c) = @_; |
153
|
0
|
0
|
|
|
|
|
if ($ENV{MOJOMOJO_EXIT_OK}) { |
154
|
0
|
|
|
|
|
|
exit(0); |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
else { |
157
|
|
|
|
|
|
|
# $c->stash( template => 'error.tt' ); |
158
|
0
|
|
|
|
|
|
$c->res->status (403); # forbidden |
159
|
0
|
|
|
|
|
|
$c->res->body('EXIT NOT OK'); |
160
|
0
|
|
|
|
|
|
$c->detach(); |
161
|
|
|
|
|
|
|
} |
162
|
35
|
|
|
35
|
|
32813
|
} |
|
35
|
|
|
|
|
93
|
|
|
35
|
|
|
|
|
186
|
|
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 AUTHOR |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Marcus Ramberg <mramberg@cpan.org> |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head1 LICENSE |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
This library is free software. You can redistribute it and/or modify |
172
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=cut |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
1; |