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

Last change on this file since 1977 was 1977, checked in by nanardon, 7 years ago

Fix ssl auth and redirect issue introduce by previous fix

  • Property svn:keywords set to Id Rev
File size: 3.3 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    my $path = $c->req->path || '';
86
87    if ($path !~ /^(login|static)/) {
88        $c->session->{redirurl} = $c->req->uri;
89        $c->session->{redirparam} = $c->req->params;
90    }
91
92    my $sslenv = $c->config->{ssl}->{SSL_ID} || 'HTTP_SSL_CLIENT_S_DN_EMAIL';
93    my $sslid = $ENV{$sslenv};
94    for ($sslid) {
95        $_ or last;
96
97        /^NULL$/ and last;
98
99        my @id = $c->model('Accounts')->db->search_objects('user', "mail~$sslid");
100
101        scalar(@id) == 1 or last;
102
103        $c->stash->{sslid} = $sslid;
104    }
105
106    $c->stash->{template} = 'login/index.tt';
107    return 0;
108}
109
110sub no_object : Local {
111    my ($self, $c) = @_;
112    $c->stash->{template} = 'no_object.tt';
113}
114
115sub obj_to_uri : Private {
116    my ($self, $c, $ref) = @_;
117    my $uri_part = {
118        user => 'users',
119        group => 'groups',
120        nethost => 'nethosts',
121        netzone => 'netzones',
122        site => 'sites',
123        aliases => 'aliases',
124        service => 'services',
125    }->{$ref} || $ref;
126}
127
128sub obj_to_label : Private {
129    my ($self, $c, $ref) = @_;
130    my $uri_part = {
131        user => 'Utilisateurs',
132        group => 'Groupes',
133        nethost => 'HÃŽtes réseaux',
134        netzone => 'Zones réseau',
135        site => 'Sites',
136        aliases => 'Alias',
137        service => 'Services',
138    }->{$ref} || $ref;
139}
140
141=head2 end
142
143Attempt to render a view, if needed.
144
145=cut
146
147sub end : ActionClass('RenderView') {
148    my ($self, $c) = @_;
149    $c->forward($c->view('TT')) unless($c->res->body);
150    $c->model('Accounts')->db->rollback;
151    $c->model('Accounts')->call_batch_sync;
152}
153
154=head1 AUTHOR
155
156Thauvin Olivier
157
158=head1 LICENSE
159
160This library is free software, you can redistribute it and/or modify
161it under the same terms as Perl itself.
162
163=cut
164
1651;
Note: See TracBrowser for help on using the repository browser.