From 4a0d87e642c4d97ee2a026f1207e25a001518f3a Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Sat, 8 Sep 2012 19:49:11 +0200 Subject: Abstracting the LDAP stuff in an OO library. --- lib/FPanel/Login.pm | 54 ++++++++++++++++++++++++++--------------------------- 1 file changed, 26 insertions(+), 28 deletions(-) (limited to 'lib/FPanel/Login.pm') diff --git a/lib/FPanel/Login.pm b/lib/FPanel/Login.pm index 9be724a..3a44768 100644 --- a/lib/FPanel/Login.pm +++ b/lib/FPanel/Login.pm @@ -11,17 +11,18 @@ Login.pm - =cut -use base 'CGI::Application'; +use parent 'CGI::Application'; use CGI::Application::Plugin::AutoRunmode; use CGI::Application::Plugin::Session; use CGI::Application::Plugin::Authentication; use CGI::Application::Plugin::Redirect; -use CGI::Application::Plugin::ConfigAuto qw/cfg/; +use CGI::Application::Plugin::ConfigAuto 'cfg'; use Net::LDAP; use Authen::SASL; use File::Spec::Functions qw/catfile catdir/; +use HTML::Entities; # This method is called right before the 'setup' method below. It @@ -50,12 +51,12 @@ sub cgiapp_init { }, SEND_COOKIE => 1, ); - + # Configure authentication parameters $self->authen->config( DRIVER => [ 'Generic', sub { my ($u,$p) = @_; - my ($l,$d) = split /@/, $u, 2; + my ($l,$d) = split /\@/, $u, 2; unless (defined $d) { $CFG{default_realm} // return 0; @@ -72,10 +73,10 @@ sub cgiapp_init { STORE => 'Session', LOGIN_RUNMODE => 'login', RENDER_LOGIN => \&login_box, - LOGIN_SESSION_TIMEOUT => { IDLE_FOR => $CFG{timeout} }, + LOGIN_SESSION_TIMEOUT => { IDLE_FOR => $CFG{timeout} }, LOGOUT_RUNMODE => 'logout', ); - + # The run modes that require authentication $self->authen->protected_runmodes( qw /okay error_rm/ ); } @@ -86,6 +87,7 @@ sub cgiapp_init { # on the URL and query string. sub setup { my $self = shift; + $self->header_props( -charset=>'utf-8' ); $self->tmpl_path( catdir ( $self->cfg('pwd'), $self->cfg('tmpl_path') ) ); @@ -121,11 +123,7 @@ sub setup { return 'ListLocals'; } - unless (defined $crap and $crap ne '') { - return 'EditLocal'; - } - - return 'error_404'; + return 'EditLocal'; }); } @@ -142,20 +140,20 @@ sub okay : Runmode { # This is the login Run Mode. sub login : Runmode { - my $self = shift; - + my $self = shift; + # A logged user has no reason to ask for a relogin, so s/he is seen as # an intruder $self->authen->logout if $self->authen->is_authenticated; - + # Do not come back here on the next Run Mode $self->query->delete('a') if (defined $self->query->param('a')) and $self->query->param('a') eq 'login'; - + # Where the users wants to go $self->query->param( destination => $self->query->self_url) unless defined $self->query->param('destination'); - + return $self->login_box; } @@ -163,11 +161,11 @@ sub login : Runmode { # This method loads the login form. sub login_box { my $self = shift; - + my $template = $self->load_tmpl( 'login.html', cache => 1, utf8 => 1 ); - $template->param( ERROR => $self->authen->login_attempts ); - $template->param( DESTINATION => $self->query->param('destination') ); - + $template->param( error => $self->authen->login_attempts ); + $template->param( destination => $self->query->param('destination') ); + return $template->output; } @@ -175,18 +173,18 @@ sub login_box { # This is the logout Run Mode. sub logout : Runmode { my $self = shift; - + if ($self->authen->is_authenticated) { # Log out the user, delete the session and flush it off the disk $self->authen->logout; $self->session->delete; $self->session->flush; } - + # Do not come back here on the next Run Mode $self->query->delete('a') if (defined $self->query->param('a')) and $self->query->param('a') eq 'logout'; - + return $self->redirect($self->query->self_url); } @@ -207,17 +205,17 @@ sub error_rm : ErrorRunmode { elsif ($error eq '404' ) { $mesg = 'Not found' } - $template->param( CODE => $error ); - $template->param( MESSAGE => $mesg ); + $template->param( code => $error ); + $template->param( message => encode_entities ($mesg, "‘‘") ); return $template->output; } else { # Users are not supposed to see that unless the CGI crashes :P my $template = $self->load_tmpl( 'error.html', cache => 1, utf8 => 1 ); - $template->param( EMAIL => $self->cfg('report_email') ); - $template->param( MESSAGE => $error ); - $template->param( URL => $self->query->url . '/'); + $template->param( email => $self->cfg('report_email') ); + $template->param( message => $error ); + $template->param( url => $self->query->url . '/'); return $template->output; } } -- cgit v1.2.3