Changeset 297
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB.pm
r296 r297 2235 2235 2236 2236 ## DNSDB::delUser() 2237 # 2237 # Delete a user. 2238 # Takes a database handle and user ID 2239 # Returns a success/failure code and matching message 2238 2240 sub delUser { 2239 2241 my $dbh = shift; 2240 return ('FAIL',"Need database handle") if !$dbh;2241 2242 my $userid = shift; 2242 return ('FAIL',"Missing userid") if !defined($userid); 2243 2244 my $sth = $dbh->prepare("delete from users where user_id=?"); 2245 $sth->execute($userid); 2246 2247 return ('FAIL',"Couldn't remove user: ".$sth->errstr) if $sth->err; 2248 2249 return ('OK','OK'); 2250 2243 2244 return ('FAIL',"Bad userid") if !defined($userid); 2245 2246 my $userdata = getUserData($dbh, $userid); 2247 2248 # Allow transactions, and raise an exception on errors so we can catch it later. 2249 # Use local to make sure these get "reset" properly on exiting this block 2250 local $dbh->{AutoCommit} = 0; 2251 local $dbh->{RaiseError} = 1; 2252 2253 eval { 2254 $dbh->do("DELETE FROM users WHERE user_id=?", undef, ($userid)); 2255 _log($dbh, (group_id => $userdata->{group_id}, 2256 entry => "Deleted user ID $userid/".$userdata->{username}. 2257 " (".$userdata->{firstname}." ".$userdata->{lastname}.")") ); 2258 $dbh->commit; 2259 }; 2260 if ($@) { 2261 my $msg = $@; 2262 eval { $dbh->rollback; }; 2263 if ($config{log_failures}) { 2264 _log($dbh, (group_id => $userdata->{group_id}, entry => "Error deleting user ID ". 2265 "$userid/".$userdata->{username}.": $msg") ); 2266 $dbh->commit; 2267 } 2268 return ('FAIL',"Error deleting user $userid/".$userdata->{username}.": $msg"); 2269 } 2270 2271 return ('OK',"Deleted user ".$userdata->{username}." (".$userdata->{firstname}." ".$userdata->{lastname}.")"); 2251 2272 } # end delUser 2252 2273 … … 2303 2324 $dbh->do("UPDATE users SET status=? WHERE user_id=?", undef, ($newstatus, $id)); 2304 2325 2305 $resultstr = ($newstatus ? 'Enabled' : 'Disabled')." user ".$userdata->{username}; 2326 $resultstr = ($newstatus ? 'Enabled' : 'Disabled')." user ".$userdata->{username}. 2327 " (".$userdata->{firstname}." ".$userdata->{lastname}.")"; 2306 2328 2307 2329 my %loghash; -
trunk/dns.cgi
r296 r297 1383 1383 $page->param(user => userFullName($dbh,$webvar{id})); 1384 1384 } elsif ($webvar{del} eq 'ok') { 1385 ##fixme: find group id user is in (for logging) *before* we delete the user1386 ##fixme: get other user data too for log1387 my $userref = getUserData($dbh, $webvar{id});1388 1385 my ($code,$msg) = delUser($dbh, $webvar{id}); 1389 1386 if ($code eq 'OK') { 1390 1387 # success. go back to the user list, do not pass "GO" 1391 # actions on users have a domain id of 0, always 1392 logaction(0, $session->param("username"), $curgroup, "Deleted user $webvar{id}/".$userref->{username}. 1393 " (".$userref->{lastname}.", ".$userref->{firstname}.")"); 1394 changepage(page => "useradmin", resultmsg => "Deleted user ".$userref->{username}. 1395 " (".$userref->{lastname}.", ".$userref->{firstname}.")"); 1388 changepage(page => "useradmin", resultmsg => $msg); 1396 1389 } else { 1397 # need to find failure mode 1398 $page->param(del_failed => 1); 1399 $page->param(errmsg => $msg); 1400 list_users($curgroup); 1401 logaction(0, $session->param("username"), $curgroup, "Failed to delete user ". 1402 "$webvar{id}/".$userref->{username}.": $msg") 1403 if $config{log_failures}; 1390 changepage(page => "useradmin", errmsg => $msg); 1404 1391 } 1405 1392 } else {
Note:
See TracChangeset
for help on using the changeset viewer.