1 package SL::Dispatcher::AuthHandler::User;
4 use parent qw(SL::Dispatcher::AuthHandler::Base);
6 use SL::Helper::UserPreferences::DisplayPreferences;
7 use SL::Layout::Dispatcher;
10 my ($self, %param) = @_;
12 my ($http_auth_login, $http_auth_password) = $self->_parse_http_basic_auth;
13 my ($http_headers_client, $http_headers_login) = $self->_parse_http_headers_auth;
15 my $login = $::form->{'{AUTH}login'} // $http_auth_login // $http_headers_login // $::auth->get_session_value('login');
17 return $self->_error(%param) if !defined $login;
19 my $client_id = $::form->{'{AUTH}client_id'} // $http_headers_client // $::auth->get_session_value('client_id') // $::auth->get_default_client_id;
21 return $self->_error(%param) if !$client_id || !$::auth->set_client($client_id);
23 %::myconfig = User->get_default_myconfig($::auth->read_user(login => $login));
25 return $self->_error(%param) unless $::myconfig{login};
27 $::locale = Locale->new($::myconfig{countrycode});
29 # user can force a layout version
30 my $user_prefs = SL::Helper::UserPreferences::DisplayPreferences->new();
31 $::request->is_mobile(0) if ($user_prefs->get_layout_style || '') eq 'desktop';
32 $::request->is_mobile(1) if ($user_prefs->get_layout_style || '') eq 'mobile';
33 $::request->{layout} = $::request->is_mobile
34 ? SL::Layout::Dispatcher->new(style => 'mobile')
35 : SL::Layout::Dispatcher->new(style => $::myconfig{menustyle});
37 my $ok = $::auth->is_api_token_cookie_valid;
38 $ok ||= $http_headers_login && (SL::Auth::OK() == $::auth->authenticate($::myconfig{login}, \'dummy!'));
39 $ok ||= $::form->{'{AUTH}login'} && (SL::Auth::OK() == $::auth->authenticate($::myconfig{login}, $::form->{'{AUTH}password'}));
40 $ok ||= !$::form->{'{AUTH}login'} && $http_auth_login && (SL::Auth::OK() == $::auth->authenticate($::myconfig{login}, $http_auth_password));
41 $ok ||= !$::form->{'{AUTH}login'} && !$http_auth_login && (SL::Auth::OK() == $::auth->authenticate($::myconfig{login}, undef));
43 return $self->_error(%param) if !$ok;
45 $::auth->create_or_refresh_session;
46 $::auth->delete_session_value('FLASH');
47 $::instance_conf->reload->data;
53 my ($self, %param) = @_;
55 $::auth->punish_wrong_login;
56 $::dispatcher->handle_login_error(%param, error => 'password');