1 package SL::Controller::LoginScreen;
5 use parent qw(SL::Controller::Base);
7 use SL::Dispatcher::AuthHandler::User;
10 __PACKAGE__->run_before('set_layout');
15 sub action_user_login {
18 # If the user is already logged in then redirect to the proper menu
20 return if $self->_redirect_to_main_script_if_already_logged_in;
22 # Otherwise show the login form.
23 $self->render('login_screen/user_login', { no_menu => 1 }, error => error_state($::form->{error}));
29 $::auth->destroy_session;
30 $::auth->create_or_refresh_session;
31 $self->render('login_screen/user_login', { no_menu => 1 }, error => $::locale->text('You are logged out!'));
37 %::myconfig = $::form->{'{AUTH}login'} ? $::auth->read_user(login => $::form->{'{AUTH}login'}) : ();
38 %::myconfig = SL::Dispatcher::AuthHandler::User->new->handle(countrycode => $::myconfig{countrycode});
39 $::form->{login} = $::myconfig{login};
40 $::locale = Locale->new($::myconfig{countrycode}) if $::myconfig{countrycode};
41 my $user = User->new(login => $::myconfig{login});
42 $::request->{layout} = SL::Layout::Dispatcher->new(style => $user->{menustyle});
44 # if we get an error back, bale out
45 my $result = $user->login($::form);
47 # Database update available?
48 ::end_of_request() if -2 == $result;
50 # Auth DB needs update? If so log the user out forcefully.
52 $::auth->destroy_session;
53 return $self->render('login_screen/auth_db_needs_update');
58 $::auth->punish_wrong_login;
59 return $self->render('login_screen/user_login', { no_menu => 1 }, error => $::locale->text('Incorrect username or password!'));
63 $::auth->set_cookie_environment_variable();
65 $self->_redirect_to_main_script($user);
75 sub keep_auth_vars_in_form {
83 sub _redirect_to_main_script {
84 my ($self, $user) = @_;
86 return $self->redirect_to($::form->{callback}) if $::form->{callback};
88 $self->redirect_to(controller => "login.pl", action => 'company_logo');
91 sub _redirect_to_main_script_if_already_logged_in {
94 # Get 'login' from valid session.
95 my $login = $::auth->get_session_value('login');
98 # See whether or not the user exists in the database.
99 my %user = $::auth->read_user(login => $login);
100 return if ($user{login} || '') ne $login;
102 # Check if the session is logged in correctly.
103 return if SL::Auth::OK() != $::auth->authenticate($login, undef);
105 $::auth->create_or_refresh_session;
106 $::auth->delete_session_value('FLASH');
108 $self->_redirect_to_main_script(\%user);
115 session => $::locale->text('The session is invalid or has expired.'),
116 password => $::locale->text('Incorrect password!'),
121 $::request->{layout} = SL::Layout::Dispatcher->new(style => 'login');