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

Last change on this file since 1088 was 1088, checked in by nanardon, 12 years ago
  • various fixes introduce by filter patch
  • Property svn:keywords set to Id Rev
File size: 2.7 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 begin : Private {
36    my ( $self, $c ) = @_;
37
38    $c->log->debug($c->config->{ssl}->{HTTP_SSL_CLIENT_I_DN});
39    if ($c->user_exists) {
40        # Set login user:
41        $c->model('Accounts')->db->{_user} = $c->user->{username};
42    } else {
43        # No need to login for About section
44        if (!$c->authenticate({}, 'la')) {
45            $c->forward('auth_required');
46            return;
47        }
48    }
49}
50
51=head2 default
52
53=cut
54
55sub default : Private {
56    my ( $self, $c ) = @_;
57    $c->res->redirect($c->uri_for('/users', $c->user->{username})) if($c->user);
58}
59
60sub login : Local {
61    my ( $self, $c ) = @_;
62
63    $c->stash->{template} = 'login.tt';
64    if ($c->req->param('username')) {
65        if ($c->authenticate({
66                username => $c->req->param('username'),
67                password => $c->req->param('password')})) {
68            my $redirurl = $c->uri_for($c->req->param('loguri') ||  '/');
69            $c->res->redirect($redirurl || $c->uri_for('/'));
70        } else {
71            # invalid login...
72        }
73    }
74    my ($redirurl) = grep { $_ } (
75        $c->req->param('loguri'),
76        ($c->req->path ? '/' . $c->req->path : undef),
77        $c->uri_for('/'),
78    );
79    $c->stash->{redirurl} = $redirurl;
80}
81
82sub no_object : Local {
83    my ($self, $c) = @_;
84    $c->stash->{template} = 'no_object.tt';
85}
86
87sub obj_to_uri : Private {
88    my ($self, $c, $ref) = @_;
89    my $uri_part = {
90        user => 'users',
91        group => 'groups',
92        nethost => 'nethosts',
93        netzone => 'netzones',
94        site => 'sites',
95    }->{$ref} || $ref;
96}
97
98=head2 end
99
100Attempt to render a view, if needed.
101
102=cut
103
104sub end : ActionClass('RenderView') {
105    my ($self, $c) = @_;
106    $c->forward($c->view('TT')) unless($c->res->body);
107    $c->model('Accounts')->db->rollback;
108    $c->model('Accounts')->call_batch_sync;
109}
110
111=head1 AUTHOR
112
113Thauvin Olivier
114
115=head1 LICENSE
116
117This library is free software, you can redistribute it and/or modify
118it under the same terms as Perl itself.
119
120=cut
121
1221;
Note: See TracBrowser for help on using the repository browser.