source: trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Root.pm @ 1791

Last change on this file since 1791 was 1791, checked in by nanardon, 8 years ago

Allow recursive masse data fetching

  • Property svn:keywords set to Id Rev
File size: 3.0 KB
Line 
1package LATMOS::Accounts::Web::Controller::Root;
2
3use strict;
4use warnings;
5use base 'Catalyst::Controller';
6no utf8;
7use POSIX;
8use DateTime;
9use Date::Calc;
10use Date::Parse;
11
12#
13# Sets the actions in this controller to be registered with no prefix
14# so they function identically to actions created in MyApp.pm
15#
16__PACKAGE__->config->{namespace} = '';
17
18=head1 NAME
19
20LATMOS::Accounts::Web::Controller::Root - Root Controller for LATMOS::Accounts::Web
21
22=head1 DESCRIPTION
23
24[enter your description here]
25
26=head1 METHODS
27
28=cut
29
30sub component_disabled : Private {
31    my ( $self, $c ) = @_;
32    $c->res->status(403);
33}
34
35sub auto : Private {
36    my ( $self, $c ) = @_;
37
38    my ($locale) = split(',', $c->req->header('Accept-Language') || '');
39    $locale ||= '';
40    $locale =~ s/(\s\s)/$1/;
41    if (my $plocale = ($c->req->param('locale')|| $c->session->{'locale'})) {
42        $c->session->{'locale'} = $locale = $plocale;
43    }
44    POSIX::setlocale(POSIX::LC_ALL, $locale);
45    $c->languages($locale ? [ $locale ] : '');
46}
47
48sub begin : Private {
49    my ( $self, $c ) = @_;
50
51    if ($c->user_exists) {
52        # Set login user:
53        $c->model('Accounts')->db->{_user} = $c->user->{username};
54        return 1;
55    } else {
56        # No need to login for About section
57        $c->detach('needlogin');
58        return;
59    }
60}
61
62=head2 default
63
64=cut
65
66sub default : Private {
67    my ( $self, $c ) = @_;
68
69    $c->res->status(404); 
70}
71
72sub index : Private {
73    my ( $self, $c ) = @_;
74
75    if ($c->user) {
76        $c->res->redirect(
77            $c->uri_for('/users', $c->user->{username})
78        )
79    }
80}
81
82sub needlogin : Private {
83    my ( $self, $c ) = @_;
84
85    $c->session->{redirurl} ||= $c->req->uri;
86    $c->session->{redirparam} ||= $c->req->params;
87
88    my $sslid = $c->config->{ssl}->{SSL_ID} || 'HTTP_SSL_CLIENT_S_DN_EMAIL';
89    $c->stash->{sslid} = $ENV{$sslid};
90
91    $c->stash->{template} = 'login/index.tt';
92    return 0;
93}
94
95sub no_object : Local {
96    my ($self, $c) = @_;
97    $c->stash->{template} = 'no_object.tt';
98}
99
100sub obj_to_uri : Private {
101    my ($self, $c, $ref) = @_;
102    my $uri_part = {
103        user => 'users',
104        group => 'groups',
105        nethost => 'nethosts',
106        netzone => 'netzones',
107        site => 'sites',
108        aliases => 'aliases',
109        service => 'services',
110    }->{$ref} || $ref;
111}
112
113sub obj_to_label : Private {
114    my ($self, $c, $ref) = @_;
115    my $uri_part = {
116        user => 'Utilisateurs',
117        group => 'Groupes',
118        nethost => 'HÃŽtes réseaux',
119        netzone => 'Zones réseau',
120        site => 'Sites',
121        aliases => 'Alias',
122        service => 'Services',
123    }->{$ref} || $ref;
124}
125
126=head2 end
127
128Attempt to render a view, if needed.
129
130=cut
131
132sub end : ActionClass('RenderView') {
133    my ($self, $c) = @_;
134    $c->forward($c->view('TT')) unless($c->res->body);
135    $c->model('Accounts')->db->rollback;
136    $c->model('Accounts')->call_batch_sync;
137}
138
139=head1 AUTHOR
140
141Thauvin Olivier
142
143=head1 LICENSE
144
145This library is free software, you can redistribute it and/or modify
146it under the same terms as Perl itself.
147
148=cut
149
1501;
Note: See TracBrowser for help on using the repository browser.