]> wagnertech.de Git - mfinanz.git/blobdiff - SL/Dispatcher.pm
Formularfelder und Session-Keys für Logins umbenannt
[mfinanz.git] / SL / Dispatcher.pm
index cfb4fb834f26ac298e4953f906cad9318daa63e6..747da04854ede10bf7998bafb00b49fc14e76550 100644 (file)
@@ -17,6 +17,7 @@ use List::MoreUtils qw(all);
 use List::Util qw(first);
 use POSIX;
 use SL::Auth;
+use SL::Dispatcher::AuthHandler;
 use SL::LXDebug;
 use SL::LxOfficeConf;
 use SL::Locale;
@@ -37,6 +38,7 @@ sub new {
 
   my $self           = bless {}, $class;
   $self->{interface} = lc($interface || 'cgi');
+  $self->{auth_handler} = SL::Dispatcher::AuthHandler->new;
 
   return $self;
 }
@@ -63,15 +65,15 @@ sub show_error {
   $::lxdebug->enter_sub;
   my $template             = shift;
   my $error_type           = shift || '';
+  my %params               = @_;
 
   $::locale                = Locale->new($::lx_office_conf{system}->{language});
   $::form->{error}         = $::locale->text('The session is invalid or has expired.') if ($error_type eq 'session');
   $::form->{error}         = $::locale->text('Incorrect password!.')                   if ($error_type eq 'password');
   $::myconfig{countrycode} = $::lx_office_conf{system}->{language};
-  $::form->{stylesheet}    = 'css/lx-office-erp.css';
 
   $::form->header;
-  print $::form->parse_html_template($template);
+  print $::form->parse_html_template($template, \%params);
   $::lxdebug->leave_sub;
 
   ::end_of_request();
@@ -144,10 +146,11 @@ sub require_main_code {
 sub _require_controller {
   my $controller =  shift;
   $controller    =~ s|[^A-Za-z0-9_]||g;
+  $controller    =  "SL/Controller/${controller}";
 
   eval {
     package main;
-    require "SL/Controller/${controller}.pm";
+    require "${controller}.pm";
   } or die $EVAL_ERROR;
 }
 
@@ -164,22 +167,19 @@ sub handle_request {
 
   my ($script, $path, $suffix, $script_name, $action, $routing_type);
 
-  $script_name = $ENV{SCRIPT_NAME};
-
   $self->unrequire_bin_mozilla;
 
-  $::cgi           = CGI->new('');
   $::locale        = Locale->new($::lx_office_conf{system}->{language});
   $::form          = Form->new;
   $::instance_conf = SL::InstanceConfiguration->new;
-  $::request       = { };
+  $::request       = { cgi => CGI->new({}) };
 
   my $session_result = $::auth->restore_session;
   $::auth->create_or_refresh_session;
 
   $::form->read_cgi_input;
 
-  eval { ($routing_type, $script_name, $action) = _route_request($script_name); 1; } or return;
+  eval { ($routing_type, $script_name, $action) = _route_request($ENV{SCRIPT_NAME}); 1; } or return;
 
   if ($routing_type eq 'old') {
     $::form->{action}  =  lc $::form->{action};
@@ -206,23 +206,20 @@ sub handle_request {
 
     } else {
       show_error('login/password_error', 'session') if SL::Auth::SESSION_EXPIRED == $session_result;
-      %::myconfig = $::auth->read_user($::form->{login});
-
-      show_error('login/password_error', 'password') unless $::myconfig{login};
-
-      $::locale = Locale->new($::myconfig{countrycode});
 
-      show_error('login/password_error', 'password') if SL::Auth::OK != $::auth->authenticate($::form->{login}, $::form->{password});
+      my $auth_level = $self->{auth_handler}->handle(
+        routing_type => $routing_type,
+        script       => $script,
+        controller   => $script_name,
+        action       => $action,
+      );
 
-      $::auth->store_credentials_in_session(login => $::form->{login}, password => $::form->{password});
-      $::auth->create_or_refresh_session;
-      $::auth->delete_session_value('FLASH');
-      delete $::form->{password};
+      delete @{ $::form }{ grep { m/^\{AUTH\}/ } keys %{ $::form } };
 
       if ($action) {
-        $::instance_conf->init;
+        $::instance_conf->init if $auth_level eq 'user';
 
-        map { $::form->{$_} = $::myconfig{$_} } qw(stylesheet charset)
+        map { $::form->{$_} = $::myconfig{$_} } qw(charset)
           unless $action eq 'save' && $::form->{type} eq 'preferences';
 
         $::form->set_standard_title;
@@ -240,7 +237,7 @@ sub handle_request {
   } or do {
     if ($EVAL_ERROR ne END_OF_REQUEST) {
       print STDERR $EVAL_ERROR;
-      $::form->{label_error} = $::cgi->pre($EVAL_ERROR);
+      $::form->{label_error} = $::request->{cgi}->pre($EVAL_ERROR);
       eval { show_error('generic/error') };
     }
   };
@@ -311,7 +308,7 @@ sub _route_dispatcher_request {
 
     1;
   } or do {
-    $::form->{label_error} = $::cgi->pre($EVAL_ERROR);
+    $::form->{label_error} = $::request->{cgi}->pre($EVAL_ERROR);
     show_error('generic/error');
   };
 
@@ -328,7 +325,7 @@ sub _route_controller_request {
 
     1;
   } or do {
-    $::form->{label_error} = $::cgi->pre($EVAL_ERROR);
+    $::form->{label_error} = $::request->{cgi}->pre($EVAL_ERROR);
     show_error('generic/error');
   };
 
@@ -375,7 +372,6 @@ sub _check_for_old_config_files {
   return unless @old_files;
 
   $::form->{title}      = $::locale->text('Old configuration files');
-  $::form->{stylesheet} = 'lx-office-erp.css';
   $::form->header;
   print $::form->parse_html_template('login/old_configuration_files', { FILES => \@old_files });