source: server/trunk/web/lib/Sophie/Controller/Root.pm @ 22

Last change on this file since 22 was 22, checked in by nanardon, 14 years ago
  • add initial distribution pages
File size: 2.0 KB
Line 
1package Sophie::Controller::Root;
2use Moose;
3use namespace::autoclean;
4
5BEGIN { 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
15Sophie::Controller::Root - Root Controller for Sophie
16
17=head1 DESCRIPTION
18
19[enter your description here]
20
21=head1 METHODS
22
23=cut
24
25sub 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
51sub toto : LocalPath  {
52    my ($self, $c) = @_;
53    $c->detach('index');
54}
55
56=head2 index
57
58The root page (/)
59
60=cut
61
62sub index :Path :Args(0) {
63    my ( $self, $c ) = @_;
64
65    # Hello World
66}
67
68=head2 default
69
70Standard 404 error page
71
72=cut
73
74sub default :Path {
75    my ( $self, $c ) = @_;
76    $c->response->body( 'Page not found' );
77    $c->response->status(404);
78}
79
80=head2 end
81
82Attempt to render a view, if needed.
83
84=cut
85
86sub _end : ActionClass('RenderView') {}
87
88sub  end : Private {
89    my ( $self, $c ) = @_;
90    if (!$c->req->xmlrpc->method) {
91        $c->forward('_end');
92    } elsif (!$c->stash->{current_view}) {
93    }
94    $c->stash->{data} = $c->stash->{xmlrpc};
95    $c->model('Base')->storage->dbh->rollback;
96}
97
98=head1 AUTHOR
99
100Olivier Thauvin
101
102=head1 LICENSE
103
104This library is free software. You can redistribute it and/or modify
105it under the same terms as Perl itself.
106
107=cut
108
109__PACKAGE__->meta->make_immutable;
110
1111;
Note: See TracBrowser for help on using the repository browser.