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

Last change on this file since 50 was 50, checked in by nanardon, 14 years ago
  • add view of rpms over distrib

add path inside website

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