%::myconfig mit sinnvollen Standardwerten vorbelegen
[kivitendo-erp.git] / SL / Dispatcher / AuthHandler / Admin.pm
1 package SL::Dispatcher::AuthHandler::Admin;
2
3 use strict;
4 use parent qw(Rose::Object);
5
6 use SL::Layout::Dispatcher;
7
8 sub handle {
9   my ($self, %params) = @_;
10
11   %::myconfig = User->get_default_myconfig;
12
13   my $ok =  $::auth->is_api_token_cookie_valid;
14   $ok  ||=  $::form->{'{AUTH}admin_password'} && ($::auth->authenticate_root($::form->{'{AUTH}admin_password'})            == $::auth->OK());
15   $ok  ||= !$::form->{'{AUTH}admin_password'} && ($::auth->authenticate_root($::auth->get_session_value('admin_password')) == $::auth->OK());
16   $ok  ||=  $params{action} eq 'login';
17
18   $::auth->create_or_refresh_session;
19
20   if ($ok) {
21     $::auth->delete_session_value('FLASH');
22     return 1;
23   }
24
25   $::request->{layout} = SL::Layout::Dispatcher->new(style => 'admin');
26   $::request->layout->no_menu(1);
27   $::auth->delete_session_value('admin_password');
28   $::auth->punish_wrong_login;
29   SL::Dispatcher::show_error('admin/adminlogin', 'password');
30
31   return 0;
32 }
33
34 1;