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

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

Fix access to remote/ url

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