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

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

Redirect / to user's page

  • 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}
93
94sub no_object : Local {
95    my ($self, $c) = @_;
96    $c->stash->{template} = 'no_object.tt';
97}
98
99sub obj_to_uri : Private {
100    my ($self, $c, $ref) = @_;
101    my $uri_part = {
102        user => 'users',
103        group => 'groups',
104        nethost => 'nethosts',
105        netzone => 'netzones',
106        site => 'sites',
107        aliases => 'aliases',
108        service => 'services',
109    }->{$ref} || $ref;
110}
111
112sub obj_to_label : Private {
113    my ($self, $c, $ref) = @_;
114    my $uri_part = {
115        user => 'Utilisateurs',
116        group => 'Groupes',
117        nethost => 'HÃŽtes réseaux',
118        netzone => 'Zones réseau',
119        site => 'Sites',
120        aliases => 'Alias',
121        service => 'Services',
122    }->{$ref} || $ref;
123}
124
125=head2 end
126
127Attempt to render a view, if needed.
128
129=cut
130
131sub end : ActionClass('RenderView') {
132    my ($self, $c) = @_;
133    $c->forward($c->view('TT')) unless($c->res->body);
134    $c->model('Accounts')->db->rollback;
135    $c->model('Accounts')->call_batch_sync;
136}
137
138=head1 AUTHOR
139
140Thauvin Olivier
141
142=head1 LICENSE
143
144This library is free software, you can redistribute it and/or modify
145it under the same terms as Perl itself.
146
147=cut
148
1491;
Note: See TracBrowser for help on using the repository browser.