1 | package LATMOS::Accounts::Web::Controller::Root; |
---|
2 | |
---|
3 | use strict; |
---|
4 | use warnings; |
---|
5 | use 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 | |
---|
15 | LATMOS::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 | |
---|
25 | sub 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 | |
---|
35 | sub component_disabled : Private { |
---|
36 | my ( $self, $c ) = @_; |
---|
37 | $c->res->status(403); |
---|
38 | } |
---|
39 | |
---|
40 | sub 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 | |
---|
60 | sub default : Private { |
---|
61 | my ( $self, $c ) = @_; |
---|
62 | $c->res->redirect($c->uri_for('/users', $c->user->{username})) if($c->user); |
---|
63 | } |
---|
64 | |
---|
65 | sub 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 | |
---|
87 | sub no_object : Local { |
---|
88 | my ($self, $c) = @_; |
---|
89 | $c->stash->{template} = 'no_object.tt'; |
---|
90 | } |
---|
91 | |
---|
92 | sub 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 | |
---|
105 | Attempt to render a view, if needed. |
---|
106 | |
---|
107 | =cut |
---|
108 | |
---|
109 | sub 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 | |
---|
118 | Thauvin Olivier |
---|
119 | |
---|
120 | =head1 LICENSE |
---|
121 | |
---|
122 | This library is free software, you can redistribute it and/or modify |
---|
123 | it under the same terms as Perl itself. |
---|
124 | |
---|
125 | =cut |
---|
126 | |
---|
127 | 1; |
---|