Fehler etwas abgefedert bei falschem/fehlendem Login.
[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::User;
32 use SL::Form;
33
34 require "bin/mozilla/common.pl";
35
36 $form = new Form;
37
38 $locale = new Locale $language, "login";
39
40 # customization
41 if (-f "bin/mozilla/custom_$form->{script}") {
42   eval { require "bin/mozilla/custom_$form->{script}"; };
43   $form->error($@) if ($@);
44 }
45
46 # per login customization
47 if (-f "bin/mozilla/$form->{login}_$form->{script}") {
48   eval { require "bin/mozilla/$form->{login}_$form->{script}"; };
49   $form->error($@) if ($@);
50 }
51
52 # window title bar, user info
53 $form->{titlebar} = "Lx-Office " . $locale->text('Version') . " $form->{version}";
54
55 if ($form->{action}) {
56   $form->{titlebar} .= " - $myconfig{name} - $myconfig{dbname}";
57   call_sub($locale->findsub($form->{action}));
58
59 } else {
60   login_screen();
61 }
62
63 1;
64
65 sub login_screen {
66   $lxdebug->enter_sub();
67   my ($msg) = @_;
68
69   if (-f "css/lx-office-erp.css") {
70     $form->{stylesheet} = "lx-office-erp.css";
71   }
72
73   $form->{msg}   = $msg;
74   $form->{fokus} = "loginscreen.login";
75   $form->header;
76
77   print $form->parse_html_template('login/login_screen');
78
79   $lxdebug->leave_sub();
80 }
81
82 sub login {
83   $lxdebug->enter_sub();
84
85   unless ($form->{login}) {
86     login_screen($locale->text('You did not enter a name!'));
87     exit;
88   }
89
90   $user = new User $memberfile, $form->{login};
91
92   # if we get an error back, bale out
93   if (($result = $user->login(\%$form, $userspath)) <= -1) {
94     exit if $result == -2;
95     login_screen($locale->text('Incorrect username or password!'));
96     exit;
97   }
98
99   my %style_to_script_map = ( 'v3'  => 'v3',
100                               'neu' => 'new',
101                               'xml' => 'XML',
102     );
103
104   my $menu_script = $style_to_script_map{$user->{menustyle}} || '';
105
106   # made it this far, execute the menu
107   $form->{callback} = build_std_url("script=menu${menu_script}.pl", 'action=display');
108
109   $form->redirect();
110
111   $lxdebug->leave_sub();
112 }
113
114 sub logout {
115   $lxdebug->enter_sub();
116
117   unlink "$userspath/$form->{login}.conf";
118
119   # remove the callback to display the message
120   $form->{callback} = "login.pl?action=&login=";
121   $form->redirect($locale->text('You are logged out!'));
122
123   $lxdebug->leave_sub();
124 }
125
126 sub company_logo {
127   $lxdebug->enter_sub();
128
129   require "$userspath/$form->{login}.conf";
130
131   $locale             =  new Locale $myconfig{countrycode}, "login" if ($language ne $myconfig{countrycode});
132
133   $form->{stylesheet} =  $myconfig{stylesheet};
134   $form->{title}      =  $locale->text('About');
135
136   # create the logo screen
137   $form->header() unless $form->{noheader};
138
139   print $form->parse_html_template('login/company_logo');
140
141   $lxdebug->leave_sub();
142 }