MojoMojo
view release on metacpan or search on metacpan
lib/MojoMojo/Controller/Root.pm view on Meta::CPAN
or response, then render the template. If param 'die' is passed,
show a debug screen.
=cut
sub end : Private {
my ( $self, $c ) = @_;
my $theme=$c->pref('theme');
# if theme doesn't exist
if ( ! -d $c->path_to('root','static','themes',$theme)) {
$theme='default';
$c->pref('theme',$theme);
}
$c->stash->{additional_template_paths} =
[ $c->path_to('root','themes',$theme) ];
$c->req->uri->path( $c->stash->{pre_hacked_uri}->path )
if ref $c->stash->{pre_hacked_uri};
$c->forward('render');
}
=head2 auto
Runs for all requests, checks if user is in need of validation, and
intercepts the request if so. Also, if the requested page doesn't exist,
prevents any other actions from running, and detaches straight to
L<MojoMojo::Controller::Page/suggest>.
=cut
sub auto : Private {
my ( $self, $c ) = @_;
# Prevent most actions from running on non-existent pages. This fixes issues #36 and #80.
# 'render' should be allowed so that jsrpc/render can be used to preview newly created pages while the first version is being typed in
my $proto_pages = $c->stash->{proto_pages};
return 1 if $c->action->class =~ m/^MojoMojo::Extensions::/;
return $c->res->body('Page does not exist.')
if ($proto_pages && @$proto_pages && $c->action->name eq 'inline');
$c->detach('MojoMojo::Controller::Page', 'suggest')
if ($proto_pages && @$proto_pages && $c->action->name !~ /^(edit|render|login|logout|register|recover_pass)$/);
if ( $c->pref('enforce_login') ) {
# allow a few actions
if ( grep $c->action->name eq $_, qw/login logout recover_pass register/ ) {
return 1;
}
if ( !$c->user_exists ) {
$c->res->redirect(
$c->uri_for(
$c->stash->{path} . '.login' # send them to the login for this page
)
);
}
}
return 1 unless $c->stash->{user};
return 1 if $c->stash->{user}->active != -1;
return 1 if $c->req->action eq 'logout';
$c->stash->{template} = 'user/validate.tt';
return 0;
}
=head2 exit
A way to exit from MojoMojo. Useful when testing leaks.
=cut
sub exit : Local {
my ($self, $c) = @_;
if ($ENV{MOJOMOJO_EXIT_OK}) {
exit(0);
}
else {
# $c->stash( template => 'error.tt' );
$c->res->status (403); # forbidden
$c->res->body('EXIT NOT OK');
$c->detach();
}
}
=head1 AUTHOR
Marcus Ramberg <mramberg@cpan.org>
=head1 LICENSE
This library is free software. You can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
1;
( run in 1.181 second using v1.01-cache-2.11-cpan-39bf76dae61 )