X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Flogin.pl;h=3c90891183c444a67254de8fc1169ad0adf8e1d5;hb=b81f2b8fd88c28f96f49fbe50e94276384d0d511;hp=e6dd8e7a25648d5940e6cd90df698207451c9f06;hpb=d319704a66e9be64da837ccea10af6774c2b0838;p=kivitendo-erp.git diff --git a/bin/mozilla/login.pl b/bin/mozilla/login.pl index e6dd8e7a2..3c9089118 100644 --- a/bin/mozilla/login.pl +++ b/bin/mozilla/login.pl @@ -28,214 +28,173 @@ ####################################################################### use DBI; +use SL::Auth; use SL::User; use SL::Form; -$form = new Form; +require "bin/mozilla/common.pl"; +require "bin/mozilla/todo.pl"; -$locale = new Locale $language, "login"; +use strict; -# customization -if (-f "$form->{path}/custom_$form->{script}") { - eval { require "$form->{path}/custom_$form->{script}"; }; - $form->error($@) if ($@); -} +our $cgi; +our $form; +our $auth; -# per login customization -if (-f "$form->{path}/$form->{login}_$form->{script}") { - eval { require "$form->{path}/$form->{login}_$form->{script}"; }; - $form->error($@) if ($@); -} +sub run { + $::lxdebug->enter_sub; + my $session_result = shift; -# window title bar, user info -$form->{titlebar} = - "Lx-Office " . $locale->text('Version') . " $form->{version}"; + $form = $::form; + $auth = $::auth; -if ($form->{action}) { - $form->{titlebar} .= " - $myconfig{name} - $myconfig{dbname}"; - &{ $locale->findsub($form->{action}) }; -} else { - &login_screen; -} + $form->{stylesheet} = "lx-office-erp.css"; + $form->{favicon} = "favicon.ico"; -1; + if (SL::Auth::SESSION_EXPIRED == $session_result) { + $form->{error_message} = $::locale->text('The session is invalid or has expired.'); + login_screen(); + ::end_of_request(); + } + my $action = $form->{action}; + if (!$action && $auth->{SESSION}->{login}) { + $action = 'login'; + } + if ($action) { + %::myconfig = $auth->read_user(login => $form->{login}) if ($form->{login}); + $::locale = Locale->new($::myconfig{countrycode}) if $::myconfig{countrycode}; + + if (SL::Auth::OK != $auth->authenticate($::myconfig{login}, $form->{password})) { + $form->{error_message} = $::locale->text('Incorrect username or password!'); + login_screen(); + } else { + $auth->store_credentials_in_session(login => $form->{login}, password => $form->{password}); + $auth->create_or_refresh_session(); + delete $form->{password}; + + $form->{titlebar} .= " - $::myconfig{name} - $::myconfig{dbname}"; + call_sub($::locale->findsub($action)); + } + } else { + login_screen(); + } + + $::lxdebug->leave_sub; +} sub login_screen { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + my ($msg) = @_; if (-f "css/lx-office-erp.css") { $form->{stylesheet} = "lx-office-erp.css"; } - $form->{fokus} = "loginscreen.login"; - $form->header; - - print qq| - - - - -
-
-
- -
- - - - -
- - - -|; - - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub login { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); - $form->error($locale->text('You did not enter a name!')) - unless ($form->{login}); + unless ($form->{login}) { + login_screen($::locale->text('You did not enter a name!')); + ::end_of_request(); + } - $user = new User $memberfile, $form->{login}; + my $user = User->new(login => $form->{login}); # if we get an error back, bale out - if (($errno = $user->login(\%$form, $userspath)) <= -1) { - $errno *= -1; - $err[1] = $err[3] = $locale->text('Incorrect username or password!'); - - if ($errno == 2) { - - # upgraded dataset, login again - $form->redirect( - "{login}&password=$form->{password}&path=$form->{path}&action=display>Continue" - ); - exit; + my $result; + if (($result = $user->login($form)) <= -1) { + if ($result == -3) { + show_error('login/auth_db_needs_update'); + $::auth->destroy_session; + ::end_of_request(); } - $form->error($err[$errno]); + ::end_of_request() if $result == -2; + login_screen($::locale->text('Incorrect username or password!')); + ::end_of_request(); } + my %style_to_script_map = ( + v3 => 'v3', + neu => 'new', + v4 => 'v4', + ); + + my $menu_script = $style_to_script_map{$user->{menustyle}} || ''; + # made it this far, execute the menu - $form->{callback} = - "menu.pl?login=$form->{login}&password=$form->{password}&path=$form->{path}&action=display"; + # standard redirect does not seem to work for this invocation, (infinite loops?) + # do a manual invocation instead +# $form->{callback} = build_std_url("script=menu${menu_script}.pl", 'action=display', "callback=" . $form->escape($form->{callback})); + + $main::auth->set_cookie_environment_variable(); + + $::form->{script} = "menu${menu_script}.pl"; + $::form->{action} = 'display'; + $::form->{callback} = $::form->escape($::form->{callback}); + + require "bin/mozilla/$::form->{script}"; + display(); - $form->redirect; +# $form->redirect(); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub logout { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); - unlink "$userspath/$form->{login}.conf"; + $main::auth->destroy_session(); # remove the callback to display the message - $form->{callback} = "login.pl?path=$form->{path}&action=&login="; - $form->redirect($locale->text('You are logged out!')); + $form->{callback} = "login.pl?action="; + $form->redirect($::locale->text('You are logged out!')); - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub company_logo { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); - require "$userspath/$form->{login}.conf"; - $locale = new Locale $myconfig{countrycode}, "login" - unless ($language eq $myconfig{countrycode}); + my %myconfig = %main::myconfig; + $form->{todo_list} = create_todo_list('login_screen' => 1) if (!$form->{no_todo_list}); - $myconfig{address} =~ s/\\n/
/g; - $myconfig{dbhost} = $locale->text('localhost') unless $myconfig{dbhost}; + $form->{stylesheet} = $myconfig{stylesheet}; + $form->{title} = $::locale->text('kivitendo'); + $form->{interface} = $::dispatcher->interface_type; - map { $form->{$_} = $myconfig{$_} } qw(charset stylesheet); + # create the logo screen + $form->header() unless $form->{noheader}; - $form->{title} = $locale->text('About'); + print $form->parse_html_template('login/company_logo'); - # create the logo screen - $form->header unless $form->{noheader}; - - print qq| - -
- - - -| . $locale->text('Licensed to') . qq| -

- -$myconfig{company} -
$myconfig{address} -
- - -
- - - - - - - - - - - - - - - - - - - - - - - -
| . $locale->text('User') . qq|$myconfig{name}
| . $locale->text('Dataset') . qq|$myconfig{dbname}
| . $locale->text('Database Host') . qq|$myconfig{dbhost}
http://lx-office.org
info@lx-office.org
- -

- - - -|; - - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } +sub show_error { + my $template = shift; + my %myconfig = %main::myconfig; + $myconfig{countrycode} = $::lx_office_conf{system}->{language}; + $form->{stylesheet} = 'css/lx-office-erp.css'; + + $form->header(); + print $form->parse_html_template($template); + + # $form->parse_html_template('login/auth_db_unreachable'); + # $form->parse_html_template('login/auth_db_needs_update'); + # $form->parse_html_template('login/authentication_pl_missing'); + + ::end_of_request(); +} + +1; + +__END__