1 package Test::LDAP::Controller::Auth;
3 use namespace::autoclean;
5 BEGIN {extends 'Catalyst::Controller'; }
7 sub index :Path :Args(0) {
10 $c->res->body("Login");
13 sub login :Path("login") :Args(0) {
14 my ( $self, $c ) = @_;
16 my $user = $c->req->params->{'username'};
17 my $pass = $c->req->params->{'password'};
20 if ($c->user_exists) {
21 $c->response->redirect( $c->uri_for( $c->controller("Auth")->action_for("index") ) )
24 # Got username / pass?
25 if ( defined ($user) && defined ($pass) ) {
27 my $auth = $c->authenticate (
28 { username => $user, password => $pass }, "ldap"
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
34 $c->response->redirect( $c->uri_for( $c->controller("Root")->action_for("index") ) );;
36 # Since we got auth, let's bind with the model with a dn & pass as well.
37 #$c->model('LDAP')->bind (dn => $
39 $c->res->body("Bad user/password")
43 # If not throw a message c
44 $c->res->body("Missing credentials");
48 sub logout : Path("logout") {
49 my ( $self, $c ) = @_;
51 if ($c->user_exists) {
54 $c->response->redirect( $c->uri_for( $c->controller("Root")->action_for("index") ) )
57 __PACKAGE__->meta->make_immutable;