Mistakenly put back
[catagits/Catalyst-Authentication-Store-LDAP.git] / Test-Session-Broken / lib / Test / LDAP / Controller / Auth.pm
1 package Test::LDAP::Controller::Auth;
2 use Moose;
3 use namespace::autoclean;
4
5 BEGIN {extends 'Catalyst::Controller'; }
6
7 =head1 NAME
8
9 Test::LDAP::Controller::Auth - 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 sub index :Path :Args(0) {
24     my ( $self, $c ) = @_;
25
26     $c->res->body("Login");
27 }
28
29 sub login :Path("login") :Args(0) {
30     my ( $self, $c ) = @_;
31
32     my $user = $c->req->params->{'username'};
33     my $pass = $c->req->params->{'password'};
34
35
36     if ($c->user_exists) {
37         $c->response->redirect( $c->uri_for( $c->controller("Auth")->action_for("index") ) )
38     }
39
40     # Got username / pass?
41     if ( defined ($user) && defined ($pass) ) {
42         # Let's auth
43         my $auth = $c->authenticate (
44             { username => $user, password => $pass }, "ldap"
45         );
46
47         # Let's check if we are authed, if we are then we forward to the index.
48         # Else we'll throw an error into message and display the login page
49         if ($auth) {
50             $c->response->redirect( $c->uri_for( $c->controller("Root")->action_for("index") ) );;
51
52             # Since we got auth, let's bind with the model with a dn & pass as well.
53             #$c->model('LDAP')->bind (dn => $
54         } else {
55             $c->res->body("Bad user/password")
56         }
57
58     } else {
59         # If not throw a message c
60         $c->res->body("Missing credentials");
61     }
62 }
63
64 sub logout : Path("logout") {
65     my ( $self, $c ) = @_;
66
67     if ($c->user_exists) {
68         $c->logout;
69     }
70     $c->response->redirect( $c->uri_for( $c->controller("Root")->action_for("index") ) )
71 }
72
73 =head1 AUTHOR
74
75 root
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 __PACKAGE__->meta->make_immutable;
85
86 1;