1 | package LATMOS::Accounts::Web::Controller::Root; |
---|
2 | |
---|
3 | use strict; |
---|
4 | use warnings; |
---|
5 | use base 'Catalyst::Controller'; |
---|
6 | no utf8; |
---|
7 | use 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 | |
---|
17 | LATMOS::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 | |
---|
27 | sub component_disabled : Private { |
---|
28 | my ( $self, $c ) = @_; |
---|
29 | $c->res->status(403); |
---|
30 | } |
---|
31 | |
---|
32 | sub 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 | |
---|
45 | sub 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 | |
---|
63 | sub default : Private { |
---|
64 | my ( $self, $c ) = @_; |
---|
65 | $c->res->redirect($c->uri_for('/users', $c->user->{username})) if($c->user); |
---|
66 | } |
---|
67 | |
---|
68 | sub 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 | |
---|
80 | sub no_object : Local { |
---|
81 | my ($self, $c) = @_; |
---|
82 | $c->stash->{template} = 'no_object.tt'; |
---|
83 | } |
---|
84 | |
---|
85 | sub 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 | |
---|
98 | sub 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 | |
---|
113 | Attempt to render a view, if needed. |
---|
114 | |
---|
115 | =cut |
---|
116 | |
---|
117 | sub 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 | |
---|
126 | Thauvin Olivier |
---|
127 | |
---|
128 | =head1 LICENSE |
---|
129 | |
---|
130 | This library is free software, you can redistribute it and/or modify |
---|
131 | it under the same terms as Perl itself. |
---|
132 | |
---|
133 | =cut |
---|
134 | |
---|
135 | 1; |
---|