#######################################################################
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}";
+ $cgi = $::cgi;
+ $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($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->set_session_value('login', $form->{login}, 'password', $form->{password});
+ $auth->create_or_refresh_session();
+
+ $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;
+ $form->{msg} = $msg;
+ $form->header();
- print qq|
+ print $form->parse_html_template('login/login_screen');
+ $main::lxdebug->leave_sub();
+}
-<body class=login onLoad="fokus()">
-
-<pre>
+sub login {
+ $main::lxdebug->enter_sub();
-</pre>
+ unless ($form->{login}) {
+ login_screen($::locale->text('You did not enter a name!'));
+ ::end_of_request();
+ }
-<center>
-<table class=login border=3 cellpadding=20>
- <tr>
- <td class=login align=center><a href="http://www.lx-office.org" target=_top><img src="image/lx-office-erp.png" border=0></a>
-<h1 class=login align=center>|
- . $locale->text('Version') . qq| $form->{version}
-</h1>
+ my $user = new User $form->{login};
-<p>
+ # if we get an error back, bale out
+ my $result;
+ if (($result = $user->login($form)) <= -1) {
+ ::end_of_request() if $result == -2;
+ login_screen($::locale->text('Incorrect username or password!'));
+ ::end_of_request();
+ }
-<form method=post name=loginscreen action=$form->{script}>
+ my %style_to_script_map = ( 'v3' => 'v3',
+ 'neu' => 'new',
+ 'v4' => 'v4',
+ 'xml' => 'XML',
+ );
- <table width=100%>
- <tr>
- <td align=center>
- <table>
- <tr>
- <th align=right>| . $locale->text('Login Name') . qq|</th>
- <td><input class=login name=login size=30 tabindex="1"></td>
- </tr>
- <tr>
- <th align=right>| . $locale->text('Password') . qq|</th>
- <td><input class=login type=password name=password size=30 tabindex="2"></td>
- </tr>
- <input type=hidden name=path value=$form->{path}>
- </table>
+ my $menu_script = $style_to_script_map{$user->{menustyle}} || '';
- <br>
- <input type=submit name=action value="| . $locale->text('Login') . qq|">
+ # made it this far, execute the menu
+ # 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}));
- </td>
- </tr>
- </table>
+ $main::auth->set_cookie_environment_variable();
-</form>
+ $::form->{script} = "menu${menu_script}.pl";
+ $::form->{action} = 'display';
+ $::form->{callback} = $::form->escape($::form->{callback});
- </td>
- </tr>
-</table>
+ require "bin/mozilla/$::form->{script}";
+ display();
-</body>
-</html>
-|;
+# $form->redirect();
- $lxdebug->leave_sub();
+ $main::lxdebug->leave_sub();
}
-sub login {
- $lxdebug->enter_sub();
-
- $form->error($locale->text('You did not enter a name!'))
- unless ($form->{login});
-
- $user = new User $memberfile, $form->{login};
+sub logout {
+ $main::lxdebug->enter_sub();
- # 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!');
+ $main::auth->destroy_session();
- if ($errno == 2) {
- exit;
- }
-
- $form->error($err[$errno]);
- }
+ # remove the callback to display the message
+ $form->{callback} = "login.pl?action=";
+ $form->redirect($::locale->text('You are logged out!'));
- # made it this far, execute the menu
- if ($user->{menustyle} eq "neu") {
- $form->{callback} =
- "menunew.pl?login=$form->{login}&password=$form->{password}&path=$form->{path}&action=display";
- } else {
- $form->{callback} =
- "menu.pl?login=$form->{login}&password=$form->{password}&path=$form->{path}&action=display";
- }
+ $main::lxdebug->leave_sub();
+}
- $form->redirect;
+sub company_logo {
+ $main::lxdebug->enter_sub();
- $lxdebug->leave_sub();
-}
+ my %myconfig = %main::myconfig;
+ $form->{todo_list} = create_todo_list('login_screen' => 1) if (!$form->{no_todo_list});
-sub logout {
- $lxdebug->enter_sub();
+ $form->{stylesheet} = $myconfig{stylesheet};
+ $form->{title} = $::locale->text('Lx-Office');
+ $form->{interface} = $::dispatcher->interface_type;
- unlink "$userspath/$form->{login}.conf";
+ # create the logo screen
+ $form->header() unless $form->{noheader};
- # remove the callback to display the message
- $form->{callback} = "login.pl?path=$form->{path}&action=&login=";
- $form->redirect($locale->text('You are logged out!'));
+ print $form->parse_html_template('login/company_logo');
- $lxdebug->leave_sub();
+ $main::lxdebug->leave_sub();
}
-sub company_logo {
- $lxdebug->enter_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';
- require "$userspath/$form->{login}.conf";
- $locale = new Locale $myconfig{countrycode}, "login"
- unless ($language eq $myconfig{countrycode});
+ $form->header();
+ print $form->parse_html_template($template);
- $myconfig{address} =~ s/\\n/<br>/g;
- $myconfig{dbhost} = $locale->text('localhost') unless $myconfig{dbhost};
+ # $form->parse_html_template('login/auth_db_unreachable');
+ # $form->parse_html_template('login/authentication_pl_missing');
- map { $form->{$_} = $myconfig{$_} } qw(charset stylesheet);
+ ::end_of_request();
+}
- $form->{title} = $locale->text('About');
+1;
- # create the logo screen
- $form->header unless $form->{noheader};
-
- print qq|
-<body>
-<center>
-<a href="http://www.lx-office.org" target=_top><img src="image/lx-office-erp.png" border=0></a>
-<h2 class=login>| . $locale->text('Version') . qq| $form->{version}</h2>
-
-| . $locale->text('Licensed to') . qq|
-<p>
-<b>
-$myconfig{company}
-<br>$myconfig{address}
-</b>
-
-
-<br>
-<table border=0>
- <tr>
- <th align=left>| . $locale->text('User') . qq|</th>
- <td>$myconfig{name}</td>
- </tr>
- <tr>
- <th align=left>| . $locale->text('Dataset') . qq|</th>
- <td>$myconfig{dbname}</td>
- </tr>
- <tr>
- <th align=left>| . $locale->text('Database Host') . qq|</th>
- <td>$myconfig{dbhost}</td>
- </tr>
- <tr>
- </tr>
- <tr>
- </tr>
- <tr>
- <th colspan="2" align="center"><a href="http://lx-office.org" target="blank">http://lx-office.org</a></th>
- </tr>
- <tr>
- <th colspan="2" align="center"><a href="mailto:info@lx-office.org" target="blank">info@lx-office.org</a></th>
- </tr>
-</table>
-
-</center>
-
-</body>
-</html>
-|;
-
- $lxdebug->leave_sub();
-}
+__END__