Mistakenly put back
[catagits/Catalyst-Authentication-Store-LDAP.git] / t / lib / Test-Session-Broken / lib / Test / LDAP / Controller / User.pm
1 package Test::LDAP::Controller::User;
2 use Moose;
3 use namespace::autoclean;
4
5 BEGIN {extends 'Catalyst::Controller::HTML::FormFu'; }
6
7 =head1 NAME
8
9 Test::LDAP::Controller::User - Catalyst Controller
10
11 =head1 DESCRIPTION
12
13 Catalyst Controller.
14
15 =head1 METHODS
16
17 =cut
18
19
20 =head2 index
21
22 =cut
23
24 sub base :Chained('/') :PathPart('user') :CaptureArgs(0) {
25     my ($self, $c) = @_;
26 }
27
28 sub user :Chained('base') :PathPart('') :CaptureArgs(2) {
29     my $self = shift;
30     my $c    = shift;
31
32     # Do we have an id?
33     my $noargs = undef;
34     if ($#_ != -1) {
35         foreach (@_) {
36             if ($_ =~ /^$/) { $noargs = 1 }
37         }
38     }
39
40     if ($noargs) {
41         $c->res->body("No Args");
42         $c->detach;
43     }
44
45     my ($id, $ou) = @_;
46
47     # Store div stuff for use in templates.
48     $c->stash( 
49         id => $id, 
50         ou => $ou, 
51         type => "User",
52         resultset => { $id => $c->model('LDAP')->user("etk") }
53     );
54
55     my $noresult = undef;
56     # Do we have any entries?
57     if ( $ou !~ /^\*$/ ) {
58         if (not defined $c->stash->{resultset}->{$id}->{$ou}) {
59             $noresult = 1;
60         } else {
61             $c->stash->{result}->{$id}->{$ou} = $c->stash->{resultset}->{$id}->{$ou}
62         }
63     } else {
64         if ($c->model('LDAP')->mesg->count == 0) {
65             $noresult = 1;
66         } else {
67             $c->stash->{result} = $c->stash->{resultset};
68         }
69     }
70
71     if ($noresult) {
72         $c->res->body("No results");
73         $c->detach;
74     }
75 }
76
77 sub view :Chained('user') :PathPart('view') :Args(0) {
78     my ($self, $c) = @_;
79
80     $c->res->body("Results");
81 }
82
83 sub edit :Chained('user') :PathPart('edit') :Args(0)  {
84     my ( $self, $c ) = @_;
85
86     # Check if the loc that is specified is a wildcard, do an error if it's true
87     if ($c->stash->{ou} =~ /^\*/) {
88         $c->res->body("You cannot use '*' as an OU / Location when editing a user!");
89         $c->res->status("500");
90         $c->detach
91     }
92 }
93
94 =head2 auto
95
96 Check if the user is authenicated, if not we just forward to the login page.
97
98 =cut
99 sub auto :Private {
100     my ( $self, $c ) = @_;
101
102     if (!$c->user_exists) {
103         $c->log->debug('*** $c->controller::auto User not found, forwarding to auth');
104
105         $c->response->redirect( $c->uri_for( $c->controller("Auth")->action_for("index") ) );
106
107         return 0
108     }
109
110     return 1
111 }
112
113
114 =head1 AUTHOR
115
116 root
117
118 =head1 LICENSE
119
120 This library is free software. You can redistribute it and/or modify
121 it under the same terms as Perl itself.
122
123 =cut
124
125 __PACKAGE__->meta->make_immutable;
126
127 1;