kivi.Validator: Tests auf strikteres parse_amount geƤndert
[kivitendo-erp.git] / SL / Dispatcher / AuthHandler / User.pm
1 package SL::Dispatcher::AuthHandler::User;
2
3 use strict;
4 use parent qw(Rose::Object);
5
6 use SL::Layout::Dispatcher;
7
8 sub handle {
9   my ($self, %param) = @_;
10
11   my $login = $::form->{'{AUTH}login'} || $::auth->get_session_value('login');
12   return $self->_error(%param) if !defined $login;
13
14   my $client_id = $::form->{'{AUTH}client_id'} || $::auth->get_session_value('client_id');
15   return $self->_error(%param) if !$client_id || !$::auth->set_client($client_id);
16
17   %::myconfig = User->get_default_myconfig($::auth->read_user(login => $login));
18
19   return $self->_error(%param) unless $::myconfig{login};
20
21   $::locale = Locale->new($::myconfig{countrycode});
22   $::request->{layout} = SL::Layout::Dispatcher->new(style => $::myconfig{menustyle});
23
24   my $ok   =  $::auth->is_api_token_cookie_valid;
25   $ok    ||=  $::form->{'{AUTH}login'} && (SL::Auth::OK() == $::auth->authenticate($::myconfig{login}, $::form->{'{AUTH}password'}));
26   $ok    ||= !$::form->{'{AUTH}login'} && (SL::Auth::OK() == $::auth->authenticate($::myconfig{login}, undef));
27
28   return $self->_error(%param) if !$ok;
29
30   $::auth->create_or_refresh_session;
31   $::auth->delete_session_value('FLASH');
32   $::instance_conf->reload->data;
33
34   return 1;
35 }
36
37 sub _error {
38   my $self = shift;
39
40   $::auth->punish_wrong_login;
41
42   require SL::Controller::Base;
43   SL::Controller::Base->new->redirect_to('controller.pl?action=LoginScreen/user_login&error=password');
44   return 0;
45 }
46
47 1;