1 package SL::Controller::LoginScreen;
5 use parent qw(SL::Controller::Base);
7 use SL::Dispatcher::AuthHandler::User;
14 sub action_user_login {
17 # If the user is already logged in then redirect to the proper menu
19 return if $self->_redirect_to_main_script_if_already_logged_in;
21 # Otherwise show the login form.
22 $self->render('login_screen/user_login');
28 $::auth->destroy_session;
29 $::auth->create_or_refresh_session;
30 $self->render('login_screen/user_login', error => $::locale->text('You are logged out!'));
36 %::myconfig = $::form->{'{AUTH}login'} ? $::auth->read_user(login => $::form->{'{AUTH}login'}) : ();
37 %::myconfig = SL::Dispatcher::AuthHandler::User->new->handle(countrycode => $::myconfig{countrycode});
38 $::form->{login} = $::myconfig{login};
39 $::locale = Locale->new($::myconfig{countrycode}) if $::myconfig{countrycode};
40 my $user = User->new(login => $::myconfig{login});
42 # if we get an error back, bale out
43 my $result = $user->login($::form);
45 # Database update available?
46 ::end_of_request() if -2 == $result;
48 # Auth DB needs update? If so log the user out forcefully.
50 $::auth->destroy_session;
51 return $self->render('login_screen/auth_db_needs_update');
56 $::auth->punish_wrong_login;
57 return $self->render('login_screen/user_login', error => $::locale->text('Incorrect username or password!'));
61 $::auth->set_cookie_environment_variable();
63 $self->_redirect_to_main_script($user);
73 sub keep_auth_vars_in_form {
81 sub _redirect_to_main_script {
82 my ($self, $user) = @_;
84 return $self->redirect_to($::form->{callback}) if $::form->{callback};
86 my %style_to_script_map = (
92 my $menu_script = $style_to_script_map{$user->{menustyle}} || '';
94 $self->redirect_to(controller => "menu${menu_script}.pl", action => 'display');
97 sub _redirect_to_main_script_if_already_logged_in {
100 # Get 'login' from valid session.
101 my $login = $::auth->get_session_value('login');
102 return unless $login;
104 # See whether or not the user exists in the database.
105 my %user = $::auth->read_user(login => $login);
106 return if ($user{login} || '') ne $login;
108 # Check if the session is logged in correctly.
109 return if SL::Auth::OK() != $::auth->authenticate($login, undef);
111 $::auth->create_or_refresh_session;
112 $::auth->delete_session_value('FLASH');
114 $self->_redirect_to_main_script(\%user);