From f3f0322b124681461f386b95361f55f501409744 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Mon, 16 May 2011 17:26:57 +0200 Subject: [PATCH] =?utf8?q?L=C3=B6schen=20von=20usern=20erm=C3=B6glichen,?= =?utf8?q?=20wenn=20die=20Datenbank=20nicht=20existiert=20oder=20falsch=20?= =?utf8?q?eingetragen=20ist.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Auth.pm | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/SL/Auth.pm b/SL/Auth.pm index 347e95b08..2c4653b95 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 (!$may_fail && !$dbh) { + $::form->error($::locale->text('The connection to the authentication database failed:') . "\n" . $DBI::errstr); + } - if ($user{dboptions}) { + if ($user{dboptions} && $dbh) { $dbh->do($user{dboptions}) or $::form->dberror($user{dboptions}); } @@ -430,34 +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 %user = $self->read_user($login); - my $u_dbh = DBI->connect($user{dbconnect}, $user{dbuser}, $user{dbpasswd}); - - 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, $u_dbh, qq|UPDATE employee SET deleted = 't' WHERE login = ?|, $login); + 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; - $u_dbh->commit; + $u_dbh->commit if $u_dbh; - $main::lxdebug->leave_sub(); + $::lxdebug->leave_sub; } # -------------------------------------- -- 2.20.1