1 package Test::LDAP::Controller::Auth;
3 use namespace::autoclean;
5 BEGIN {extends 'Catalyst::Controller'; }
9 Test::LDAP::Controller::Auth - Catalyst Controller
23 sub index :Path :Args(0) {
24 my ( $self, $c ) = @_;
26 $c->res->body("Login");
29 sub login :Path("login") :Args(0) {
30 my ( $self, $c ) = @_;
32 my $user = $c->req->params->{'username'};
33 my $pass = $c->req->params->{'password'};
36 if ($c->user_exists) {
37 $c->response->redirect( $c->uri_for( $c->controller("Auth")->action_for("index") ) )
40 # Got username / pass?
41 if ( defined ($user) && defined ($pass) ) {
43 my $auth = $c->authenticate (
44 { username => $user, password => $pass }, "ldap"
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
50 $c->response->redirect( $c->uri_for( $c->controller("Root")->action_for("index") ) );;
52 # Since we got auth, let's bind with the model with a dn & pass as well.
53 #$c->model('LDAP')->bind (dn => $
55 $c->res->body("Bad user/password")
59 # If not throw a message c
60 $c->res->body("Missing credentials");
64 sub logout : Path("logout") {
65 my ( $self, $c ) = @_;
67 if ($c->user_exists) {
70 $c->response->redirect( $c->uri_for( $c->controller("Root")->action_for("index") ) )
79 This library is free software. You can redistribute it and/or modify
80 it under the same terms as Perl itself.
84 __PACKAGE__->meta->make_immutable;