X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FAuth.pm;h=77ea226ae0ff7b03171e26821d21a6c22bd8305c;hb=de9a3d743c168703dcaf3aef85dd2d117aacecc9;hp=8b8d859ae2c7ad060c0a23638c357e1a63f659f1;hpb=27ae86579fb8833067e9d6c02cf5429d98b28449;p=kivitendo-erp.git diff --git a/SL/Auth.pm b/SL/Auth.pm index 8b8d859ae..77ea226ae 100644 --- a/SL/Auth.pm +++ b/SL/Auth.pm @@ -46,7 +46,9 @@ sub reset { } sub get_user_dbh { - my ($self, $login) = @_; + my ($self, $login, %params) = @_; + my $may_fail = delete $params{may_fail}; + my %user = $self->read_user($login); my $dbh = SL::DBConnect->connect( $user{dbconnect}, @@ -56,9 +58,13 @@ sub get_user_dbh { pg_enable_utf8 => $::locale->is_utf8, AutoCommit => 0 } - ) or $::form->dberror; + ); - if ($user{dboptions}) { + if (!$may_fail && !$dbh) { + $::form->error($::locale->text('The connection to the authentication database failed:') . "\n" . $DBI::errstr); + } + + if ($user{dboptions} && $dbh) { $dbh->do($user{dboptions}) or $::form->dberror($user{dboptions}); } @@ -430,29 +436,30 @@ sub get_user_id { } sub delete_user { - $main::lxdebug->enter_sub(); + $::lxdebug->enter_sub; my $self = shift; my $login = shift; - my $form = $main::form; - - my $dbh = $self->dbconnect(); + my $u_dbh = $self->get_user_dbh($login, may_fail => 1); + my $dbh = $self->dbconnect; $dbh->begin_work; my $query = qq|SELECT id FROM auth."user" WHERE login = ?|; - my ($id) = selectrow_query($form, $dbh, $query, $login); + my ($id) = selectrow_query($::form, $dbh, $query, $login); - $dbh->rollback and return $main::lxdebug->leave_sub() if (!$id); + $dbh->rollback and return $::lxdebug->leave_sub if (!$id); - do_query($form, $dbh, qq|DELETE FROM auth.user_group WHERE user_id = ?|, $id); - do_query($form, $dbh, qq|DELETE FROM auth.user_config WHERE user_id = ?|, $id); + do_query($::form, $dbh, qq|DELETE FROM auth.user_group WHERE user_id = ?|, $id); + do_query($::form, $dbh, qq|DELETE FROM auth.user_config WHERE user_id = ?|, $id); + do_query($::form, $u_dbh, qq|UPDATE employee SET deleted = 't' WHERE login = ?|, $login) if $u_dbh; - $dbh->commit(); + $dbh->commit; + $u_dbh->commit if $u_dbh; - $main::lxdebug->leave_sub(); + $::lxdebug->leave_sub; } # -------------------------------------- @@ -694,7 +701,6 @@ sub create_unique_sesion_value { $self->{unique_counter}++; $value = { expiration => $params{expiration} ? ($now[0] + $params{expiration}) * 1000000 + $now[1] : undef, - no_auto => !$params{auto_restore}, data => $value, }; @@ -1086,25 +1092,20 @@ sub check_right { } sub assert { - $main::lxdebug->enter_sub(2); - - my $self = shift; - my $right = shift; - my $dont_abort = shift; + $::lxdebug->enter_sub(2); + my ($self, $right, $dont_abort) = @_; - my $form = $main::form; - - if ($self->check_right($form->{login}, $right)) { - $main::lxdebug->leave_sub(2); + if ($self->check_right($::myconfig{login}, $right)) { + $::lxdebug->leave_sub(2); return 1; } if (!$dont_abort) { - delete $form->{title}; - $form->show_generic_error($main::locale->text("You do not have the permissions to access this function.")); + delete $::form->{title}; + $::form->show_generic_error($::locale->text("You do not have the permissions to access this function.")); } - $main::lxdebug->leave_sub(2); + $::lxdebug->leave_sub(2); return 0; } @@ -1176,11 +1177,6 @@ If C<$params{expiration}> is set then it is interpreted as a number of seconds after which the value is removed from the session. It will never expire if that parameter is falsish. -If C<$params{auto_restore}> is trueish then the value will be copied -into C<$::form> upon the next request automatically. It defaults to -C and has therefore different behaviour than -L. - Returns the key created in the session. =item C