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";
 
  38 # This is required because the am.pl in the root directory
 
  39 # is not scanned by locales.pl:
 
  40 # $form->parse_html_template('login/password_error')
 
  44 if (! -f 'config/authentication.pl') {
 
  45   show_error('login/authentication_pl_missing');
 
  48 $locale = new Locale $language, "login";
 
  50 our $auth = SL::Auth->new();
 
  51 if (!$auth->session_tables_present()) {
 
  52   show_error('login/auth_db_unreachable');
 
  54 $auth->expire_sessions();
 
  55 my $session_result = $auth->restore_session();
 
  58 if (-f "bin/mozilla/custom_$form->{script}") {
 
  59   eval { require "bin/mozilla/custom_$form->{script}"; };
 
  60   $form->error($@) if ($@);
 
  63 # per login customization
 
  64 if (-f "bin/mozilla/$form->{login}_$form->{script}") {
 
  65   eval { require "bin/mozilla/$form->{login}_$form->{script}"; };
 
  66   $form->error($@) if ($@);
 
  69 # window title bar, user info
 
  70 $form->{titlebar} = "Lx-Office " . $locale->text('Version') . " $form->{version}";
 
  72 if (SL::Auth::SESSION_EXPIRED == $session_result) {
 
  73   $form->{error_message} = $locale->text('The session is invalid or has expired.');
 
  78 my $action = $form->{action};
 
  80 if (!$action && $auth->{SESSION}->{login}) {
 
  85   our %myconfig = $auth->read_user($form->{login}) if ($form->{login});
 
  87   if (!$myconfig{login} || (SL::Auth::OK != $auth->authenticate($form->{login}, $form->{password}, 0))) {
 
  88     $form->{error_message} = $locale->text('Incorrect Password!');
 
  93   $auth->set_session_value('login', $form->{login}, 'password', $form->{password});
 
  94   $auth->create_or_refresh_session();
 
  96   $form->{titlebar} .= " - $myconfig{name} - $myconfig{dbname}";
 
  97   call_sub($locale->findsub($action));
 
 106   $lxdebug->enter_sub();
 
 109   if (-f "css/lx-office-erp.css") {
 
 110     $form->{stylesheet} = "lx-office-erp.css";
 
 116   print $form->parse_html_template('login/login_screen');
 
 118   $lxdebug->leave_sub();
 
 122   $lxdebug->enter_sub();
 
 124   unless ($form->{login}) {
 
 125     login_screen($locale->text('You did not enter a name!'));
 
 129   $user = new User $form->{login};
 
 131   # if we get an error back, bale out
 
 132   if (($result = $user->login($form)) <= -1) {
 
 133     exit if $result == -2;
 
 134     login_screen($locale->text('Incorrect username or password!'));
 
 138   my %style_to_script_map = ( 'v3'  => 'v3',
 
 143   my $menu_script = $style_to_script_map{$user->{menustyle}} || '';
 
 145   # made it this far, execute the menu
 
 146   $form->{callback} = build_std_url("script=menu${menu_script}.pl", 'action=display');
 
 148   $auth->set_cookie_environment_variable();
 
 152   $lxdebug->leave_sub();
 
 156   $lxdebug->enter_sub();
 
 158   $auth->destroy_session();
 
 160   # remove the callback to display the message
 
 161   $form->{callback} = "login.pl?action=";
 
 162   $form->redirect($locale->text('You are logged out!'));
 
 164   $lxdebug->leave_sub();
 
 168   $lxdebug->enter_sub();
 
 170   $locale             =  new Locale $myconfig{countrycode}, "login" if ($language ne $myconfig{countrycode});
 
 172   $form->{todo_list}  =  create_todo_list('login_screen' => 1) if (!$form->{no_todo_list});
 
 174   $form->{stylesheet} =  $myconfig{stylesheet};
 
 175   $form->{title}      =  $locale->text('About');
 
 177   # create the logo screen
 
 178   $form->header() unless $form->{noheader};
 
 180   print $form->parse_html_template('login/company_logo');
 
 182   $lxdebug->leave_sub();
 
 186   my $template           = shift;
 
 187   $locale                = Locale->new($language, 'all');
 
 188   $myconfig{countrycode} = $language;
 
 189   $form->{stylesheet}    = 'css/lx-office-erp.css';
 
 192   print $form->parse_html_template($template);
 
 194   # $form->parse_html_template('login/auth_db_unreachable');
 
 195   # $form->parse_html_template('login/authentication_pl_missing');