Wenn man nach einem erfolgreichen Login die selbe Installation in einem zweiten Brows...
[kivitendo-erp.git] / bin / mozilla / login.pl
1 #=====================================================================
2 # LX-Office ERP
3 # Copyright (C) 2004
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
6 #
7 ######################################################################
8 # SQL-Ledger Accounting
9 # Copyright (c) 1998-2002
10 #
11 #  Author: Dieter Simader
12 #   Email: dsimader@sql-ledger.org
13 #     Web: http://www.sql-ledger.org
14 #
15 #
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.
20 #
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 #######################################################################
29
30 use DBI;
31 use SL::Auth;
32 use SL::User;
33 use SL::Form;
34
35 require "bin/mozilla/common.pl";
36
37 # This is required because the am.pl in the root directory
38 # is not scanned by locales.pl:
39 # $form->parse_html_template('login/password_error')
40
41 $form = new Form;
42
43 if (! -f 'config/authentication.pl') {
44   show_error('login/authentication_pl_missing');
45 }
46
47 $locale = new Locale $language, "login";
48
49 our $auth = SL::Auth->new();
50 if (!$auth->session_tables_present()) {
51   show_error('login/auth_db_unreachable');
52 }
53 $auth->expire_sessions();
54 $auth->restore_session();
55
56 # customization
57 if (-f "bin/mozilla/custom_$form->{script}") {
58   eval { require "bin/mozilla/custom_$form->{script}"; };
59   $form->error($@) if ($@);
60 }
61
62 # per login customization
63 if (-f "bin/mozilla/$form->{login}_$form->{script}") {
64   eval { require "bin/mozilla/$form->{login}_$form->{script}"; };
65   $form->error($@) if ($@);
66 }
67
68 # window title bar, user info
69 $form->{titlebar} = "Lx-Office " . $locale->text('Version') . " $form->{version}";
70
71 my $action = $form->{action};
72
73 if (!$action && $auth->{SESSION}->{login}) {
74   $action = 'login';
75 }
76
77 if ($action) {
78   our %myconfig = $auth->read_user($form->{login}) if ($form->{login});
79
80   if (!$myconfig{login} || (SL::Auth::OK != $auth->authenticate($form->{login}, $form->{password}, 0))) {
81     $form->{error_message} = $locale->text('Incorrect Password!');
82     login_screen();
83     exit;
84   }
85
86   $auth->set_session_value('login', $form->{login}, 'password', $form->{password});
87   $auth->create_or_refresh_session();
88
89   $form->{titlebar} .= " - $myconfig{name} - $myconfig{dbname}";
90   call_sub($locale->findsub($action));
91
92 } else {
93   login_screen();
94 }
95
96 1;
97
98 sub login_screen {
99   $lxdebug->enter_sub();
100   my ($msg) = @_;
101
102   if (-f "css/lx-office-erp.css") {
103     $form->{stylesheet} = "lx-office-erp.css";
104   }
105
106   $form->{msg}   = $msg;
107   $form->{fokus} = "loginscreen.login";
108   $form->header;
109
110   print $form->parse_html_template('login/login_screen');
111
112   $lxdebug->leave_sub();
113 }
114
115 sub login {
116   $lxdebug->enter_sub();
117
118   unless ($form->{login}) {
119     login_screen($locale->text('You did not enter a name!'));
120     exit;
121   }
122
123   $user = new User $form->{login};
124
125   # if we get an error back, bale out
126   if (($result = $user->login($form)) <= -1) {
127     exit if $result == -2;
128     login_screen($locale->text('Incorrect username or password!'));
129     exit;
130   }
131
132   my %style_to_script_map = ( 'v3'  => 'v3',
133                               'neu' => 'new',
134                               'xml' => 'XML',
135     );
136
137   my $menu_script = $style_to_script_map{$user->{menustyle}} || '';
138
139   # made it this far, execute the menu
140   $form->{callback} = build_std_url("script=menu${menu_script}.pl", 'action=display');
141
142   $auth->set_cookie_environment_variable();
143
144   $form->redirect();
145
146   $lxdebug->leave_sub();
147 }
148
149 sub logout {
150   $lxdebug->enter_sub();
151
152   $auth->destroy_session();
153
154   # remove the callback to display the message
155   $form->{callback} = "login.pl?action=";
156   $form->redirect($locale->text('You are logged out!'));
157
158   $lxdebug->leave_sub();
159 }
160
161 sub company_logo {
162   $lxdebug->enter_sub();
163
164   $locale             =  new Locale $myconfig{countrycode}, "login" if ($language ne $myconfig{countrycode});
165
166   $form->{stylesheet} =  $myconfig{stylesheet};
167   $form->{title}      =  $locale->text('About');
168
169   # create the logo screen
170   $form->header() unless $form->{noheader};
171
172   print $form->parse_html_template('login/company_logo');
173
174   $lxdebug->leave_sub();
175 }
176
177 sub show_error {
178   my $template           = shift;
179   $locale                = Locale->new($language, 'all');
180   $myconfig{countrycode} = $language;
181   $form->{stylesheet}    = 'css/lx-office-erp.css';
182
183   $form->header();
184   print $form->parse_html_template($template);
185
186   # $form->parse_html_template('login/auth_db_unreachable');
187   # $form->parse_html_template('login/authentication_pl_missing');
188
189   exit;
190 }