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

Last change on this file since 1148 was 1148, checked in by nanardon, 12 years ago

allow to disable some features

  • 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';
6
7#
8# Sets the actions in this controller to be registered with no prefix
9# so they function identically to actions created in MyApp.pm
10#
11__PACKAGE__->config->{namespace} = '';
12
13=head1 NAME
14
15LATMOS::Accounts::Web::Controller::Root - Root Controller for LATMOS::Accounts::Web
16
17=head1 DESCRIPTION
18
19[enter your description here]
20
21=head1 METHODS
22
23=cut
24
25sub auth_required : Private {
26    my ( $self, $c ) = @_;
27    $c->res->status(401);
28    $c->res->content_type('text/plain');
29    $c->res->body('Authorization required.');
30    $c->res->headers->push_header(
31        'WWW-Authenticate' => 'Basic realm="Link::Accounts"'
32    );
33}
34
35sub component_disabled : Private {
36    my ( $self, $c ) = @_;
37    $c->res->status(403);
38}
39
40sub begin : Private {
41    my ( $self, $c ) = @_;
42
43    $c->log->debug($c->config->{ssl}->{HTTP_SSL_CLIENT_I_DN});
44    if ($c->user_exists) {
45        # Set login user:
46        $c->model('Accounts')->db->{_user} = $c->user->{username};
47    } else {
48        # No need to login for About section
49        if (!$c->authenticate({}, 'la')) {
50            $c->forward('auth_required');
51            return;
52        }
53    }
54}
55
56=head2 default
57
58=cut
59
60sub default : Private {
61    my ( $self, $c ) = @_;
62    $c->res->redirect($c->uri_for('/users', $c->user->{username})) if($c->user);
63}
64
65sub login : Local {
66    my ( $self, $c ) = @_;
67
68    $c->stash->{template} = 'login.tt';
69    if ($c->req->param('username')) {
70        if ($c->authenticate({
71                username => $c->req->param('username'),
72                password => $c->req->param('password')})) {
73            my $redirurl = $c->uri_for($c->req->param('loguri') ||  '/');
74            $c->res->redirect($redirurl || $c->uri_for('/'));
75        } else {
76            # invalid login...
77        }
78    }
79    my ($redirurl) = grep { $_ } (
80        $c->req->param('loguri'),
81        ($c->req->path ? '/' . $c->req->path : undef),
82        $c->uri_for('/'),
83    );
84    $c->stash->{redirurl} = $redirurl;
85}
86
87sub no_object : Local {
88    my ($self, $c) = @_;
89    $c->stash->{template} = 'no_object.tt';
90}
91
92sub obj_to_uri : Private {
93    my ($self, $c, $ref) = @_;
94    my $uri_part = {
95        user => 'users',
96        group => 'groups',
97        nethost => 'nethosts',
98        netzone => 'netzones',
99        site => 'sites',
100    }->{$ref} || $ref;
101}
102
103=head2 end
104
105Attempt to render a view, if needed.
106
107=cut
108
109sub end : ActionClass('RenderView') {
110    my ($self, $c) = @_;
111    $c->forward($c->view('TT')) unless($c->res->body);
112    $c->model('Accounts')->db->rollback;
113    $c->model('Accounts')->call_batch_sync;
114}
115
116=head1 AUTHOR
117
118Thauvin Olivier
119
120=head1 LICENSE
121
122This library is free software, you can redistribute it and/or modify
123it under the same terms as Perl itself.
124
125=cut
126
1271;
Note: See TracBrowser for help on using the repository browser.