[1] | 1 | package Sophie::Controller::Root; |
---|
| 2 | use Moose; |
---|
| 3 | use namespace::autoclean; |
---|
| 4 | |
---|
| 5 | BEGIN { extends 'Catalyst::Controller' } |
---|
| 6 | |
---|
| 7 | # |
---|
| 8 | # Sets the actions in this controller to be registered with no prefix |
---|
| 9 | # so they function identically to actions created in MyApp.pm |
---|
| 10 | # |
---|
| 11 | __PACKAGE__->config(namespace => ''); |
---|
| 12 | |
---|
| 13 | =head1 NAME |
---|
| 14 | |
---|
| 15 | Sophie::Controller::Root - Root Controller for Sophie |
---|
| 16 | |
---|
| 17 | =head1 DESCRIPTION |
---|
| 18 | |
---|
| 19 | [enter your description here] |
---|
| 20 | |
---|
| 21 | =head1 METHODS |
---|
| 22 | |
---|
[3] | 23 | =cut |
---|
| 24 | |
---|
| 25 | sub begin : Private { |
---|
| 26 | my ( $self, $c ) = @_; |
---|
| 27 | |
---|
[54] | 28 | if ($c->req->path =~ m:[^/]+\/+$:) { |
---|
[17] | 29 | my $path = $c->req->path; |
---|
| 30 | $path =~ s:/*$::; |
---|
| 31 | $c->res->redirect($c->uri_for("/$path")); |
---|
| 32 | return; |
---|
| 33 | } |
---|
| 34 | |
---|
[54] | 35 | if (!$c->stash->{sitepath}) { |
---|
[50] | 36 | my @path; |
---|
[54] | 37 | my @reqpath = split('/', $c->req->path); |
---|
[50] | 38 | foreach (@reqpath) { |
---|
| 39 | push(@path, $_); |
---|
[54] | 40 | push(@{ $c->stash->{sitepath} }, { path => $c->uri_for('/', @path), |
---|
| 41 | name => $_ || '*' }); |
---|
[50] | 42 | } |
---|
| 43 | } |
---|
| 44 | |
---|
[16] | 45 | if (($c->req->query_keywords || '') =~ /([^\w]|^)json([^\w]|$)/ || |
---|
| 46 | exists($c->req->params ->{json})) { |
---|
[3] | 47 | $c->stash->{current_view} = 'Json'; |
---|
| 48 | } |
---|
[16] | 49 | if (($c->req->query_keywords || '') =~ /([^\w]|^)ajax([^\w]|$)/ || |
---|
| 50 | exists($c->req->params ->{ajax})) { |
---|
| 51 | $c->stash->{current_view} = 'Ajax'; |
---|
| 52 | } |
---|
[4] | 53 | |
---|
| 54 | if ($c->action =~ m/^admin\//) { |
---|
[65] | 55 | if (!($c->user_exists && $c->check_user_roles($c->user, 'Admin'))) { |
---|
[4] | 56 | $c->res->redirect($c->uri_for('/login')); |
---|
| 57 | } |
---|
| 58 | } |
---|
[3] | 59 | } |
---|
| 60 | |
---|
[1] | 61 | =head2 index |
---|
| 62 | |
---|
| 63 | The root page (/) |
---|
| 64 | |
---|
| 65 | =cut |
---|
| 66 | |
---|
| 67 | sub index :Path :Args(0) { |
---|
| 68 | my ( $self, $c ) = @_; |
---|
| 69 | |
---|
| 70 | # Hello World |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | =head2 default |
---|
| 74 | |
---|
| 75 | Standard 404 error page |
---|
| 76 | |
---|
| 77 | =cut |
---|
| 78 | |
---|
| 79 | sub default :Path { |
---|
| 80 | my ( $self, $c ) = @_; |
---|
| 81 | $c->response->body( 'Page not found' ); |
---|
| 82 | $c->response->status(404); |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | =head2 end |
---|
| 86 | |
---|
| 87 | Attempt to render a view, if needed. |
---|
| 88 | |
---|
| 89 | =cut |
---|
| 90 | |
---|
[2] | 91 | sub _end : ActionClass('RenderView') {} |
---|
[1] | 92 | |
---|
[2] | 93 | sub end : Private { |
---|
| 94 | my ( $self, $c ) = @_; |
---|
[3] | 95 | if (!$c->req->xmlrpc->method) { |
---|
[2] | 96 | $c->forward('_end'); |
---|
[3] | 97 | } elsif (!$c->stash->{current_view}) { |
---|
[2] | 98 | } |
---|
[17] | 99 | $c->stash->{data} = $c->stash->{xmlrpc}; |
---|
[42] | 100 | $c->model('Base')->storage->dbh->rollback; |
---|
[2] | 101 | } |
---|
| 102 | |
---|
[1] | 103 | =head1 AUTHOR |
---|
| 104 | |
---|
| 105 | Olivier Thauvin |
---|
| 106 | |
---|
| 107 | =head1 LICENSE |
---|
| 108 | |
---|
| 109 | This library is free software. You can redistribute it and/or modify |
---|
| 110 | it under the same terms as Perl itself. |
---|
| 111 | |
---|
| 112 | =cut |
---|
| 113 | |
---|
| 114 | __PACKAGE__->meta->make_immutable; |
---|
| 115 | |
---|
| 116 | 1; |
---|