1 #=====================================================================
 
   4 # Based on SQL-Ledger Version 2.1.9
 
   5 # Web http://www.lx-office.org
 
   7 ######################################################################
 
   8 # SQL-Ledger Accounting
 
   9 # Copyright (c) 1998-2002
 
  11 #  Author: Dieter Simader
 
  12 #   Email: dsimader@sql-ledger.org
 
  13 #     Web: http://www.sql-ledger.org
 
  16 # This program is free software; you can redistribute it and/or modify
 
  17 # it under the terms of the GNU General Public License as published by
 
  18 # the Free Software Foundation; either version 2 of the License, or
 
  19 # (at your option) any later version.
 
  21 # This program is distributed in the hope that it will be useful,
 
  22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  24 # GNU General Public License for more details.
 
  25 # You should have received a copy of the GNU General Public License
 
  26 # along with this program; if not, write to the Free Software
 
  27 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
  28 #######################################################################
 
  35 require "bin/mozilla/common.pl";
 
  36 require "bin/mozilla/todo.pl";
 
  40 # This is required because the am.pl in the root directory
 
  41 # is not scanned by locales.pl:
 
  42 # $form->parse_html_template('login/password_error')
 
  46 if (! -f 'config/authentication.pl') {
 
  47   show_error('login/authentication_pl_missing');
 
  50 our $locale = new Locale $main::language, "login";
 
  52 our $auth = SL::Auth->new();
 
  53 if (!$auth->session_tables_present()) {
 
  54   show_error('login/auth_db_unreachable');
 
  56 $auth->expire_sessions();
 
  57 my $session_result = $main::auth->restore_session();
 
  60 if (-f "bin/mozilla/custom_$form->{script}") {
 
  61   eval { require "bin/mozilla/custom_$form->{script}"; };
 
  62   $form->error($@) if ($@);
 
  65 # per login customization
 
  66 if (-f "bin/mozilla/$form->{login}_$form->{script}") {
 
  67   eval { require "bin/mozilla/$form->{login}_$form->{script}"; };
 
  68   $form->error($@) if ($@);
 
  71 # window title bar, user info
 
  72 $form->{titlebar} = "Lx-Office " . $locale->text('Version') . " $form->{version}";
 
  74 if (SL::Auth::SESSION_EXPIRED == $session_result) {
 
  75   $form->{error_message} = $locale->text('The session is invalid or has expired.');
 
  80 my $action = $form->{action};
 
  82 if (!$action && $auth->{SESSION}->{login}) {
 
  87   our %myconfig = $auth->read_user($form->{login}) if ($form->{login});
 
  89   if (!$myconfig{login} || (SL::Auth::OK != $auth->authenticate($form->{login}, $form->{password}, 0))) {
 
  90     $form->{error_message} = $locale->text('Incorrect Password!');
 
  95   $auth->set_session_value('login', $form->{login}, 'password', $form->{password});
 
  96   $auth->create_or_refresh_session();
 
  98   $form->{titlebar} .= " - $myconfig{name} - $myconfig{dbname}";
 
  99   call_sub($locale->findsub($action));
 
 108   $main::lxdebug->enter_sub();
 
 111   if (-f "css/lx-office-erp.css") {
 
 112     $form->{stylesheet} = "lx-office-erp.css";
 
 118   print $form->parse_html_template('login/login_screen');
 
 120   $main::lxdebug->leave_sub();
 
 124   $main::lxdebug->enter_sub();
 
 126   unless ($form->{login}) {
 
 127     login_screen($locale->text('You did not enter a name!'));
 
 131   my $user = new User $form->{login};
 
 133   # if we get an error back, bale out
 
 135   if (($result = $user->login($form)) <= -1) {
 
 136     exit if $result == -2;
 
 137     login_screen($locale->text('Incorrect username or password!'));
 
 141   my %style_to_script_map = ( 'v3'  => 'v3',
 
 147   my $menu_script = $style_to_script_map{$user->{menustyle}} || '';
 
 149   # made it this far, execute the menu
 
 150   $form->{callback} = build_std_url("script=menu${menu_script}.pl", 'action=display', "callback=" . $form->escape($form->{callback}));
 
 152   $main::auth->set_cookie_environment_variable();
 
 156   $main::lxdebug->leave_sub();
 
 160   $main::lxdebug->enter_sub();
 
 162   $main::auth->destroy_session();
 
 164   # remove the callback to display the message
 
 165   $form->{callback} = "login.pl?action=";
 
 166   $form->redirect($locale->text('You are logged out!'));
 
 168   $main::lxdebug->leave_sub();
 
 172   $main::lxdebug->enter_sub();
 
 174   my %myconfig = %main::myconfig;
 
 175   $locale             =  new Locale $myconfig{countrycode}, "login" if ($main::language ne $myconfig{countrycode});
 
 177   $form->{todo_list}  =  create_todo_list('login_screen' => 1) if (!$form->{no_todo_list});
 
 179   $form->{stylesheet} =  $myconfig{stylesheet};
 
 180   $form->{title}      =  $locale->text('About');
 
 182   # create the logo screen
 
 183   $form->header() unless $form->{noheader};
 
 185   print $form->parse_html_template('login/company_logo');
 
 187   $main::lxdebug->leave_sub();
 
 191   my $template           = shift;
 
 192   my %myconfig = %main::myconfig;
 
 193   $locale                = Locale->new($main::language, 'all');
 
 194   $myconfig{countrycode} = $main::language;
 
 195   $form->{stylesheet}    = 'css/lx-office-erp.css';
 
 198   print $form->parse_html_template($template);
 
 200   # $form->parse_html_template('login/auth_db_unreachable');
 
 201   # $form->parse_html_template('login/authentication_pl_missing');