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 | |
---|
23 | =cut |
---|
24 | |
---|
25 | sub begin : Private { |
---|
26 | my ( $self, $c ) = @_; |
---|
27 | |
---|
28 | if ($c->req->path =~ m:[^/]+\/$:) { |
---|
29 | my $path = $c->req->path; |
---|
30 | $path =~ s:/*$::; |
---|
31 | $c->res->redirect($c->uri_for("/$path")); |
---|
32 | return; |
---|
33 | } |
---|
34 | |
---|
35 | if (($c->req->query_keywords || '') =~ /([^\w]|^)json([^\w]|$)/ || |
---|
36 | exists($c->req->params ->{json})) { |
---|
37 | $c->stash->{current_view} = 'Json'; |
---|
38 | } |
---|
39 | if (($c->req->query_keywords || '') =~ /([^\w]|^)ajax([^\w]|$)/ || |
---|
40 | exists($c->req->params ->{ajax})) { |
---|
41 | $c->stash->{current_view} = 'Ajax'; |
---|
42 | } |
---|
43 | |
---|
44 | if ($c->action =~ m/^admin\//) { |
---|
45 | if (!$c->user_exists) { |
---|
46 | $c->res->redirect($c->uri_for('/login')); |
---|
47 | } |
---|
48 | } |
---|
49 | } |
---|
50 | |
---|
51 | =head2 index |
---|
52 | |
---|
53 | The root page (/) |
---|
54 | |
---|
55 | =cut |
---|
56 | |
---|
57 | sub index :Path :Args(0) { |
---|
58 | my ( $self, $c ) = @_; |
---|
59 | |
---|
60 | # Hello World |
---|
61 | } |
---|
62 | |
---|
63 | =head2 default |
---|
64 | |
---|
65 | Standard 404 error page |
---|
66 | |
---|
67 | =cut |
---|
68 | |
---|
69 | sub default :Path { |
---|
70 | my ( $self, $c ) = @_; |
---|
71 | $c->response->body( 'Page not found' ); |
---|
72 | $c->response->status(404); |
---|
73 | } |
---|
74 | |
---|
75 | =head2 end |
---|
76 | |
---|
77 | Attempt to render a view, if needed. |
---|
78 | |
---|
79 | =cut |
---|
80 | |
---|
81 | sub _end : ActionClass('RenderView') {} |
---|
82 | |
---|
83 | sub end : Private { |
---|
84 | my ( $self, $c ) = @_; |
---|
85 | if (!$c->req->xmlrpc->method) { |
---|
86 | $c->forward('_end'); |
---|
87 | } elsif (!$c->stash->{current_view}) { |
---|
88 | } |
---|
89 | $c->stash->{data} = $c->stash->{xmlrpc}; |
---|
90 | $c->model('Base')->storage->dbh->rollback; |
---|
91 | } |
---|
92 | |
---|
93 | =head1 AUTHOR |
---|
94 | |
---|
95 | Olivier Thauvin |
---|
96 | |
---|
97 | =head1 LICENSE |
---|
98 | |
---|
99 | This library is free software. You can redistribute it and/or modify |
---|
100 | it under the same terms as Perl itself. |
---|
101 | |
---|
102 | =cut |
---|
103 | |
---|
104 | __PACKAGE__->meta->make_immutable; |
---|
105 | |
---|
106 | 1; |
---|