Admin-Controller: bei Session-Fehler MenĂ¼ nicht anzeigen
[kivitendo-erp.git] / SL / Dispatcher / AuthHandler / Admin.pm
index 77202e8..ad7c1f4 100644 (file)
@@ -1,18 +1,34 @@
 package SL::Dispatcher::AuthHandler::Admin;
 
 use strict;
-
 use parent qw(Rose::Object);
 
+use SL::Layout::Dispatcher;
+
 sub handle {
+  my ($self, %params) = @_;
+
   %::myconfig = ();
 
-  return if  $::form->{'{AUTH}admin_password'} && ($::auth->authenticate_root($::form->{'{AUTH}admin_password'})            == $::auth->OK());
-  return if !$::form->{'{AUTH}admin_password'} && ($::auth->authenticate_root($::auth->get_session_value('admin_password')) == $::auth->OK());
+  my $ok =  $::auth->get_api_token_cookie ? 1 : 0;
+  $ok  ||=  $::form->{'{AUTH}admin_password'} && ($::auth->authenticate_root($::form->{'{AUTH}admin_password'})            == $::auth->OK());
+  $ok  ||= !$::form->{'{AUTH}admin_password'} && ($::auth->authenticate_root($::auth->get_session_value('admin_password')) == $::auth->OK());
+  $ok  ||=  $params{action} eq 'login';
 
-  $::auth->punish_wrong_login;
+  $::auth->create_or_refresh_session;
+
+  if ($ok) {
+    $::auth->delete_session_value('FLASH');
+    return 1;
+  }
+
+  $::request->{layout} = SL::Layout::Dispatcher->new(style => 'admin');
+  $::request->layout->no_menu(1);
   $::auth->delete_session_value('admin_password');
+  $::auth->punish_wrong_login;
   SL::Dispatcher::show_error('admin/adminlogin', 'password');
+
+  return 0;
 }
 
 1;