first commit
[slists.git] / lib / Slists / Controller / Root.pm
bloba97b01e77f835f60b775192ae9a75175e779f1d6
1 package Slists::Controller::Root;
2 use Moose;
3 use namespace::autoclean;
5 BEGIN { extends 'Catalyst::Controller' }
8 # Sets the actions in this controller to be registered with no prefix
9 # so they function identically to actions created in MyApp.pm
11 __PACKAGE__->config(namespace => '');
13 =head1 NAME
15 Slists::Controller::Root - Root Controller for Slists
17 =head1 DESCRIPTION
19 [enter your description here]
21 =head1 METHODS
23 =head2 auto
25 Check if there is a user and, if not, forward to login page
27 =cut
29 # Note that 'auto' runs after 'begin' but before your actions and that
30 # 'auto's "chain" (all from application path to most specific class are run)
31 # See the 'Actions' section of 'Catalyst::Manual::Intro' for more info.
32 sub auto :Private {
33 my ($self, $c) = @_;
35 # Allow unauthenticated users to reach the login page. This
36 # allows unauthenticated users to reach any action in the Login
37 # controller. To lock it down to a single action, we could use:
38 # if ($c->action eq $c->controller('Login')->action_for('index'))
39 # to only allow unauthenticated access to the 'index' action we
40 # added above.
41 if ($c->controller eq $c->controller('Login')) {
42 return 1;
45 # If a user doesn't exist, force login
46 if (!$c->user_exists) {
47 # Dump a log message to the development server debug output
48 $c->log->debug('***Root::auto User not found, forwarding to /login');
49 # Redirect the user to the login page
50 $c->response->redirect($c->uri_for('/login'));
51 # Return 0 to cancel 'post-auto' processing and prevent use of application
52 return 0;
55 # User found, so return 1 to continue with processing after this 'auto'
56 return 1;
60 =head2 index
62 The root page (/)
64 =cut
66 sub index :Path :Args(0) {
67 my ( $self, $c ) = @_;
69 # Hello World
70 $c->response->body( $c->welcome_message );
73 =head2 default
75 Standard 404 error page
77 =cut
79 sub default :Path {
80 my ( $self, $c ) = @_;
81 $c->response->body( 'Page not found' );
82 $c->response->status(404);
85 =head2 end
87 Attempt to render a view, if needed.
89 =cut
91 sub end : ActionClass('RenderView') {}
93 =head1 AUTHOR
95 user,,,,
97 =head1 LICENSE
99 This library is free software. You can redistribute it and/or modify
100 it under the same terms as Perl itself.
102 =cut
104 __PACKAGE__->meta->make_immutable;