Chop stuff out
[catagits/Catalyst-Authentication-Store-LDAP.git] / t / lib / 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 sub index :Path :Args(0) {
8     my ( $self, $c ) = @_;
9
10     $c->res->body("Login");
11 }
12
13 sub login :Path("login") :Args(0) {
14     my ( $self, $c ) = @_;
15
16     my $user = $c->req->params->{'username'};
17     my $pass = $c->req->params->{'password'};
18
19
20     if ($c->user_exists) {
21         $c->response->redirect( $c->uri_for( $c->controller("Auth")->action_for("index") ) )
22     }
23
24     # Got username / pass?
25     if ( defined ($user) && defined ($pass) ) {
26         # Let's auth
27         my $auth = $c->authenticate (
28             { username => $user, password => $pass }, "ldap"
29         );
30
31         # Let's check if we are authed, if we are then we forward to the index.
32         # Else we'll throw an error into message and display the login page
33         if ($auth) {
34             $c->response->redirect( $c->uri_for( $c->controller("Root")->action_for("index") ) );;
35
36             # Since we got auth, let's bind with the model with a dn & pass as well.
37             #$c->model('LDAP')->bind (dn => $
38         } else {
39             $c->res->body("Bad user/password")
40         }
41
42     } else {
43         # If not throw a message c
44         $c->res->body("Missing credentials");
45     }
46 }
47
48 sub logout : Path("logout") {
49     my ( $self, $c ) = @_;
50
51     if ($c->user_exists) {
52         $c->logout;
53     }
54     $c->response->redirect( $c->uri_for( $c->controller("Root")->action_for("index") ) )
55 }
56
57 __PACKAGE__->meta->make_immutable;
58
59 1;