Layouts eingeführt
[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::Controller::Layout;
7
8 sub handle {
9   my ($self, %param) = @_;
10
11   my $login = $::form->{'{AUTH}login'} || $::auth->get_session_value('login');
12   $self->_error(%param) if !defined $login;
13
14   %::myconfig = $::auth->read_user(login => $login);
15
16   $self->_error(%param) unless $::myconfig{login};
17
18   $::locale = Locale->new($::myconfig{countrycode});
19   $::request->{layout} = SL::Controller::Layout->new(style => $::myconfig{menustyle});
20
21   my $ok   =  $::form->{'{AUTH}login'} && (SL::Auth::OK() == $::auth->authenticate($::myconfig{login}, $::form->{'{AUTH}password'}));
22   $ok    ||= !$::form->{'{AUTH}login'} && (SL::Auth::OK() == $::auth->authenticate($::myconfig{login}, undef));
23
24   $self->_error(%param) if !$ok;
25
26   $::auth->create_or_refresh_session;
27   $::auth->delete_session_value('FLASH');
28
29   return %::myconfig;
30 }
31
32 sub _error {
33   my $self = shift;
34
35   $::auth->punish_wrong_login;
36   print $::request->{cgi}->redirect('controller.pl?action=LoginScreen/user_login&error=password');
37 }
38
39 1;