Merge branch 'rb-wiederkehrende-rechnungen' into after-262
[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 require "bin/mozilla/todo.pl";
37
38 use strict;
39
40 our $cgi;
41 our $form;
42 our $auth;
43
44 sub run {
45   $::lxdebug->enter_sub;
46   my $session_result = shift;
47
48   $cgi    = $::cgi;
49   $form   = $::form;
50   $auth   = $::auth;
51
52   $form->{stylesheet} = "lx-office-erp.css";
53   $form->{favicon}    = "favicon.ico";
54
55   if (SL::Auth::SESSION_EXPIRED == $session_result) {
56     $form->{error_message} = $::locale->text('The session is invalid or has expired.');
57     login_screen();
58     ::end_of_request();
59   }
60   my $action = $form->{action};
61   if (!$action && $auth->{SESSION}->{login}) {
62     $action = 'login';
63   }
64   if ($action) {
65     %::myconfig = $auth->read_user($form->{login}) if ($form->{login});
66     $::locale   = Locale->new($::myconfig{countrycode}) if $::myconfig{countrycode};
67
68     if (!$::myconfig{login} || (SL::Auth::OK != $auth->authenticate($form->{login}, $form->{password}, 0))) {
69       $form->{error_message} = $::locale->text('Incorrect username or password!');
70       login_screen();
71     } else {
72       $auth->set_session_value('login', $form->{login}, 'password', $form->{password});
73       $auth->create_or_refresh_session();
74
75       $form->{titlebar} .= " - $::myconfig{name} - $::myconfig{dbname}";
76       call_sub($::locale->findsub($action));
77     }
78   } else {
79     login_screen();
80   }
81
82   $::lxdebug->leave_sub;
83 }
84
85 sub login_screen {
86   $main::lxdebug->enter_sub();
87   my ($msg) = @_;
88
89   if (-f "css/lx-office-erp.css") {
90     $form->{stylesheet} = "lx-office-erp.css";
91   }
92
93   $form->{msg} = $msg;
94   $form->header();
95
96   print $form->parse_html_template('login/login_screen');
97
98   $main::lxdebug->leave_sub();
99 }
100
101 sub login {
102   $main::lxdebug->enter_sub();
103
104   unless ($form->{login}) {
105     login_screen($::locale->text('You did not enter a name!'));
106     ::end_of_request();
107   }
108
109   my $user = new User $form->{login};
110
111   # if we get an error back, bale out
112   my $result;
113   if (($result = $user->login($form)) <= -1) {
114     ::end_of_request() if $result == -2;
115     login_screen($::locale->text('Incorrect username or password!'));
116     ::end_of_request();
117   }
118
119   my %style_to_script_map = ( 'v3'  => 'v3',
120                               'neu' => 'new',
121                               'v4' => 'v4',
122                               'xml' => 'XML',
123     );
124
125   my $menu_script = $style_to_script_map{$user->{menustyle}} || '';
126
127   # made it this far, execute the menu
128   # standard redirect does not seem to work for this invocation, (infinite loops?)
129   # do a manual invocation instead
130 #  $form->{callback} = build_std_url("script=menu${menu_script}.pl", 'action=display', "callback=" . $form->escape($form->{callback}));
131
132   $main::auth->set_cookie_environment_variable();
133
134   $::form->{script}   = "menu${menu_script}.pl";
135   $::form->{action}   = 'display';
136   $::form->{callback} = $::form->escape($::form->{callback});
137
138   require "bin/mozilla/$::form->{script}";
139   display();
140
141 #  $form->redirect();
142
143   $main::lxdebug->leave_sub();
144 }
145
146 sub logout {
147   $main::lxdebug->enter_sub();
148
149   $main::auth->destroy_session();
150
151   # remove the callback to display the message
152   $form->{callback} = "login.pl?action=";
153   $form->redirect($::locale->text('You are logged out!'));
154
155   $main::lxdebug->leave_sub();
156 }
157
158 sub company_logo {
159   $main::lxdebug->enter_sub();
160
161   my %myconfig = %main::myconfig;
162   $form->{todo_list}  =  create_todo_list('login_screen' => 1) if (!$form->{no_todo_list});
163
164   $form->{stylesheet} =  $myconfig{stylesheet};
165   $form->{title}      =  $::locale->text('Lx-Office');
166
167   # create the logo screen
168   $form->header() unless $form->{noheader};
169
170   print $form->parse_html_template('login/company_logo');
171
172   $main::lxdebug->leave_sub();
173 }
174
175 sub show_error {
176   my $template           = shift;
177   my %myconfig           = %main::myconfig;
178   $myconfig{countrycode} = $::lx_office_conf{system}->{language};
179   $form->{stylesheet}    = 'css/lx-office-erp.css';
180
181   $form->header();
182   print $form->parse_html_template($template);
183
184   # $form->parse_html_template('login/auth_db_unreachable');
185   # $form->parse_html_template('login/authentication_pl_missing');
186
187   ::end_of_request();
188 }
189
190 1;
191
192 __END__