1 package Test::LDAP::Controller::Auth;
3 use namespace::autoclean;
5 BEGIN {extends 'Catalyst::Controller'; }
7 sub login :Path("login") :Args(0) {
10 my $user = $c->req->params->{'username'};
11 my $pass = $c->req->params->{'password'};
14 if ($c->user_exists) {
15 $c->response->redirect( $c->uri_for( $c->controller("Auth")->action_for("index") ) )
18 # Got username / pass?
19 if ( defined ($user) && defined ($pass) ) {
21 my $auth = $c->authenticate (
22 { username => $user, password => $pass }, "ldap"
25 # Let's check if we are authed, if we are then we forward to the index.
26 # Else we'll throw an error into message and display the login page
28 $c->response->redirect( $c->uri_for( $c->controller("Root")->action_for("index") ) );;
30 # Since we got auth, let's bind with the model with a dn & pass as well.
31 #$c->model('LDAP')->bind (dn => $
33 $c->res->body("Bad user/password")
37 # If not throw a message c
38 $c->res->body("Missing credentials");
42 sub logout : Path("logout") {
43 my ( $self, $c ) = @_;
45 if ($c->user_exists) {
48 $c->response->redirect( $c->uri_for( $c->controller("Root")->action_for("index") ) )
51 __PACKAGE__->meta->make_immutable;