[104] | 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 | |
---|
[583] | 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 | |
---|
[214] | 35 | my $menu = ''; |
---|
| 36 | my @menus = ( |
---|
| 37 | [ 'users' => 'Utilisateurs' ], |
---|
[513] | 38 | ($c->model('Accounts')->db->check_acl('user', '@CREATE', 'w') |
---|
[556] | 39 | ? [ 'create/user' => 'Créer un Utilisateur' ] |
---|
[513] | 40 | : ()), |
---|
[214] | 41 | [ 'groups' => 'Groupes' ], |
---|
[513] | 42 | ($c->model('Accounts')->db->check_acl('group', '@CREATE', 'w') |
---|
[556] | 43 | ? [ 'create/group' => 'Créer un Groupe' ] |
---|
[513] | 44 | : ()), |
---|
[214] | 45 | [ 'sites' => 'Sites' ], |
---|
[516] | 46 | [ 'aliases' => 'Alias Mail' ], |
---|
[214] | 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; |
---|
[104] | 58 | } |
---|
| 59 | |
---|
| 60 | =head2 end |
---|
| 61 | |
---|
| 62 | Attempt to render a view, if needed. |
---|
| 63 | |
---|
| 64 | =cut |
---|
| 65 | |
---|
[160] | 66 | sub end : ActionClass('RenderView') { |
---|
| 67 | my ($self, $c) = @_; |
---|
[272] | 68 | $c->forward($c->view('TT')); |
---|
[160] | 69 | $c->model('Accounts')->db->rollback; |
---|
[583] | 70 | $c->model('Accounts')->call_batch_sync; |
---|
[160] | 71 | } |
---|
[104] | 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; |
---|