User-Login auf Controller umgestellt
[kivitendo-erp.git] / SL / Controller / LoginScreen.pm
1 package SL::Controller::LoginScreen;
2
3 use strict;
4
5 use parent qw(SL::Controller::Base);
6
7 use SL::Dispatcher::AuthHandler::User;
8 use SL::User;
9
10 #
11 # actions
12 #
13
14 sub action_user_login {
15   my ($self) = @_;
16
17   $self->render('login_screen/user_login');
18 }
19
20 sub action_logout {
21   my ($self) = @_;
22
23   $::auth->destroy_session;
24   $::auth->create_or_refresh_session;
25   $self->render('login_screen/user_login', error => $::locale->text('You are logged out!'));
26 }
27
28 sub action_login {
29   my ($self) = @_;
30
31   %::myconfig      = $::form->{'{AUTH}login'} ? $::auth->read_user(login => $::form->{'{AUTH}login'}) : ();
32   %::myconfig      = SL::Dispatcher::AuthHandler::User->new->handle(countrycode => $::myconfig{countrycode});
33   $::form->{login} = $::myconfig{login};
34   $::locale        = Locale->new($::myconfig{countrycode}) if $::myconfig{countrycode};
35   my $user         = User->new(login => $::myconfig{login});
36
37   # if we get an error back, bale out
38   my $result = $user->login($::form);
39
40   # Database update available?
41   ::end_of_request() if -2 == $result;
42
43   # Auth DB needs update? If so log the user out forcefully.
44   if (-3 == $result) {
45     $::auth->destroy_session;
46     return $self->render('login_screen/auth_db_needs_update');
47   }
48
49   # Other login errors.
50   if (0 > $result) {
51     $::auth->punish_wrong_login;
52     return $self->render('login_screen/user_login', error => $::locale->text('Incorrect username or password!'));
53   }
54
55   # Everything is fine.
56   $::auth->set_cookie_environment_variable();
57
58   return $self->redirect_to($::form->{callback}) if $::form->{callback};
59
60   my %style_to_script_map = (
61     v3  => 'v3',
62     neu => 'new',
63     v4  => 'v4',
64   );
65
66   my $menu_script = $style_to_script_map{$user->{menustyle}} || '';
67
68   $self->redirect_to(controller => "menu${menu_script}.pl", action => 'display');
69 }
70
71 #
72 # settings
73 #
74 sub get_auth_level {
75   return 'none';
76 }
77
78 sub keep_auth_vars_in_form {
79   return 1;
80 }
81
82 1;