X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FController%2FLoginScreen.pm;h=13b7b8a8c9d2e4f3eb755f45eb295b9686fb0f8b;hb=f964437c368c7ebf2a11e61648ccc66d5a2743d8;hp=f561a394b23faa56a5561be405c168f085f0b2b8;hpb=540c0b5e9a38158e6f7a6efacd20b2477efad7ac;p=kivitendo-erp.git diff --git a/SL/Controller/LoginScreen.pm b/SL/Controller/LoginScreen.pm index f561a394b..13b7b8a8c 100644 --- a/SL/Controller/LoginScreen.pm +++ b/SL/Controller/LoginScreen.pm @@ -7,6 +7,7 @@ use parent qw(SL::Controller::Base); use SL::Dispatcher::AuthHandler::User; use SL::User; +__PACKAGE__->run_before('set_layout'); # # actions # @@ -14,7 +15,12 @@ use SL::User; sub action_user_login { my ($self) = @_; - $self->render('login_screen/user_login'); + # If the user is already logged in then redirect to the proper menu + # script. + return if $self->_redirect_to_main_script_if_already_logged_in; + + # Otherwise show the login form. + $self->render('login_screen/user_login', error => error_state($::form->{error})); } sub action_logout { @@ -28,11 +34,13 @@ sub action_logout { sub action_login { my ($self) = @_; - %::myconfig = $::form->{'{AUTH}login'} ? $::auth->read_user(login => $::form->{'{AUTH}login'}) : (); - %::myconfig = SL::Dispatcher::AuthHandler::User->new->handle(countrycode => $::myconfig{countrycode}); + my $login = $::form->{'{AUTH}login'} || $::auth->get_session_value('login'); + %::myconfig = $login ? $::auth->read_user(login => $login) : (); + SL::Dispatcher::AuthHandler::User->new->handle(countrycode => $::myconfig{countrycode}); $::form->{login} = $::myconfig{login}; $::locale = Locale->new($::myconfig{countrycode}) if $::myconfig{countrycode}; my $user = User->new(login => $::myconfig{login}); + $::request->{layout} = SL::Layout::Dispatcher->new(style => $user->{menustyle}); # if we get an error back, bale out my $result = $user->login($::form); @@ -55,17 +63,7 @@ sub action_login { # Everything is fine. $::auth->set_cookie_environment_variable(); - return $self->redirect_to($::form->{callback}) if $::form->{callback}; - - my %style_to_script_map = ( - v3 => 'v3', - neu => 'new', - v4 => 'v4', - ); - - my $menu_script = $style_to_script_map{$user->{menustyle}} || ''; - - $self->redirect_to(controller => "menu${menu_script}.pl", action => 'display'); + $self->_redirect_to_main_script($user); } # @@ -79,4 +77,49 @@ sub keep_auth_vars_in_form { return 1; } +# +# private methods +# + +sub _redirect_to_main_script { + my ($self, $user) = @_; + + return $self->redirect_to($::form->{callback}) if $::form->{callback}; + + $self->redirect_to(controller => "login.pl", action => 'company_logo'); +} + +sub _redirect_to_main_script_if_already_logged_in { + my ($self) = @_; + + # Get 'login' from valid session. + my $login = $::auth->get_session_value('login'); + return unless $login; + + # See whether or not the user exists in the database. + my %user = $::auth->read_user(login => $login); + return if ($user{login} || '') ne $login; + + # Check if the session is logged in correctly. + return if SL::Auth::OK() != $::auth->authenticate($login, undef); + + $::auth->create_or_refresh_session; + $::auth->delete_session_value('FLASH'); + + $self->_redirect_to_main_script(\%user); + + return 1; +} + +sub error_state { + return { + session => $::locale->text('The session is invalid or has expired.'), + password => $::locale->text('Incorrect password!'), + }->{$_[0]}; +} + +sub set_layout { + $::request->{layout} = SL::Layout::Dispatcher->new(style => 'login'); +} + 1;