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

Last change on this file since 42 was 42, checked in by nanardon, 14 years ago
  • add dump/load distrib config using Yaml
  • separate DB connection for session
File size: 1.9 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
51=head2 index
52
53The root page (/)
54
55=cut
56
57sub index :Path :Args(0) {
58    my ( $self, $c ) = @_;
59
60    # Hello World
61}
62
63=head2 default
64
65Standard 404 error page
66
67=cut
68
69sub default :Path {
70    my ( $self, $c ) = @_;
71    $c->response->body( 'Page not found' );
72    $c->response->status(404);
73}
74
75=head2 end
76
77Attempt to render a view, if needed.
78
79=cut
80
81sub _end : ActionClass('RenderView') {}
82
83sub  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
95Olivier Thauvin
96
97=head1 LICENSE
98
99This library is free software. You can redistribute it and/or modify
100it under the same terms as Perl itself.
101
102=cut
103
104__PACKAGE__->meta->make_immutable;
105
1061;
Note: See TracBrowser for help on using the repository browser.