From: Moritz Bunkus Date: Thu, 13 Jun 2013 10:23:01 +0000 (+0200) Subject: Beim Login alle für diesen Mandanten gültigen User in employee anlegen X-Git-Tag: release-3.1.0beta1~331^2~19 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=383534cc74519de23e1298cd5bb1fc542d836b42;p=kivitendo-erp.git Beim Login alle für diesen Mandanten gültigen User in employee anlegen --- diff --git a/SL/Controller/LoginScreen.pm b/SL/Controller/LoginScreen.pm index e64ad0c78..50cae1816 100644 --- a/SL/Controller/LoginScreen.pm +++ b/SL/Controller/LoginScreen.pm @@ -10,6 +10,7 @@ use SL::Dispatcher::AuthHandler::User; use SL::DB::AuthClient; use SL::DB::AuthGroup; use SL::DB::AuthUser; +use SL::DB::Employee; use SL::Locale::String qw(t8); use SL::User; @@ -82,9 +83,6 @@ sub action_login { # Everything is fine. $::auth->set_cookie_environment_variable(); - # TODO: Employees anlegen/checken - # $self->_ensure_employees_for_authorized_users_exist; - $self->_redirect_to_main_script; } @@ -106,6 +104,8 @@ sub keep_auth_vars_in_form { sub _redirect_to_main_script { my ($self) = @_; + $self->_ensure_employees_for_authorized_users_exist; + return $self->redirect_to($::form->{callback}) if $::form->{callback}; $self->redirect_to(controller => "login.pl", action => 'company_logo'); @@ -133,6 +133,23 @@ sub _redirect_to_main_script_if_already_logged_in { return 1; } +sub _ensure_employees_for_authorized_users_exist { + my ($self) = @_; + + my %employees_by_login = map { ($_->login => $_) } @{ SL::DB::Manager::Employee->get_all }; + + foreach my $user (@{ SL::DB::AuthClient->new(id => $::auth->client->{id})->load->users || [] }) { + my $user_config = $user->config_values; + my $employee = $employees_by_login{$user->login} || SL::DB::Employee->new(login => $user->login); + + $employee->update_attributes( + name => $user_config->{name}, + workphone => $user_config->{tel}, + deleted => 0, + ); + } +} + sub error_state { return { session => $::locale->text('The session is invalid or has expired.'),