1 | package LATMOS::Accounts::Web::Controller; |
---|
2 | |
---|
3 | use strict; |
---|
4 | use warnings; |
---|
5 | use base 'Catalyst::Controller'; |
---|
6 | |
---|
7 | =head1 NAME |
---|
8 | |
---|
9 | LATMOS::Accounts::Web::Controller - Base class Controller for LATMOS::Accounts::Web |
---|
10 | |
---|
11 | =head1 DESCRIPTION |
---|
12 | |
---|
13 | [enter your description here] |
---|
14 | |
---|
15 | =head1 METHODS |
---|
16 | |
---|
17 | =cut |
---|
18 | |
---|
19 | =head2 default |
---|
20 | |
---|
21 | =cut |
---|
22 | |
---|
23 | sub begin : Private { |
---|
24 | my ( $self, $c ) = @_; |
---|
25 | |
---|
26 | if (!$c->user_exists) { |
---|
27 | if ($c->req->path ne 'login') { |
---|
28 | $c->forward('/login'); |
---|
29 | } |
---|
30 | } else { |
---|
31 | $c->model('Accounts')->db->connect($c->user->{username}, |
---|
32 | $c->user->{password}); |
---|
33 | } |
---|
34 | |
---|
35 | my $menu = ''; |
---|
36 | my @menus = ( |
---|
37 | [ 'users' => 'Utilisateurs' ], |
---|
38 | ($c->model('Accounts')->db->check_acl('user', '@CREATE', 'w') |
---|
39 | ? [ 'create/user' => 'Nouvel Util.' ] |
---|
40 | : ()), |
---|
41 | [ 'groups' => 'Groupes' ], |
---|
42 | ($c->model('Accounts')->db->check_acl('group', '@CREATE', 'w') |
---|
43 | ? [ 'create/group' => 'Nouveau Groupe' ] |
---|
44 | : ()), |
---|
45 | [ 'sites' => 'Sites' ], |
---|
46 | [ 'aliases' => 'Alias Mail' ], |
---|
47 | ); |
---|
48 | foreach(@menus) { |
---|
49 | $menu .= sprintf( |
---|
50 | q{<a href="%s"><span%s>%s</span></a>}, |
---|
51 | $c->uri_for('/' . $_->[0]), |
---|
52 | ($c->req->path =~ m:^$_->[0]: ? ' id="actif"' : ''), |
---|
53 | $_->[1], |
---|
54 | ); |
---|
55 | |
---|
56 | } |
---|
57 | $c->stash->{mainmenu} = $menu; |
---|
58 | } |
---|
59 | |
---|
60 | =head2 end |
---|
61 | |
---|
62 | Attempt to render a view, if needed. |
---|
63 | |
---|
64 | =cut |
---|
65 | |
---|
66 | sub end : ActionClass('RenderView') { |
---|
67 | my ($self, $c) = @_; |
---|
68 | $c->forward($c->view('TT')); |
---|
69 | $c->model('Accounts')->db->rollback; |
---|
70 | $c->model('Accounts')->call_batch_sync; |
---|
71 | } |
---|
72 | |
---|
73 | =head1 AUTHOR |
---|
74 | |
---|
75 | Thauvin Olivier |
---|
76 | |
---|
77 | =head1 LICENSE |
---|
78 | |
---|
79 | This library is free software, you can redistribute it and/or modify |
---|
80 | it under the same terms as Perl itself. |
---|
81 | |
---|
82 | =cut |
---|
83 | |
---|
84 | 1; |
---|