Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB.pm
r24 r25 26 26 &addDomain &delDomain &domainName 27 27 &addGroup &delGroup &getChildren &groupName 28 &addUser &delUser 28 &addUser &delUser &userFullName 29 29 &getSOA &getRecLine &getDomRecs 30 30 &addRec &updateRec &delRec … … 38 38 &addDomain &delDomain &domainName 39 39 &addGroup &delGroup &getChildren &groupName 40 &addUser &delUser 40 &addUser &delUser &userFullName 41 41 &getSOA &getRecLine &getDomRecs 42 42 &addRec &updateRec &delRec … … 442 442 my $pass = shift; 443 443 return ('FAIL',"Missing password") if !defined($pass); 444 445 444 my $state = shift; 446 445 return ('FAIL',"Need account status") if !defined($state); 447 my $fname = shift || ''; 446 447 my $type = shift || 'u'; # create limited users by default - fwiw, not sure yet how this will interact with ACLs 448 449 my $fname = shift || $username; 448 450 my $lname = shift || ''; 451 my $phone = shift || ''; # not going format-check 449 452 450 453 my $user_id; … … 458 461 eval { 459 462 # insert the user... 460 my $sth = $dbh->prepare("INSERT INTO users ( email,group_id,password,status) VALUES (?,?,?,?)");461 $sth->execute($username,$group,$pass,$state);462 die "user fail\n";463 my $sth = $dbh->prepare("INSERT INTO users (group_id,username,password,firstname,lastname,phone,type,status) ". 464 "VALUES (?,?,?,?,?,?,?,?)"); 465 $sth->execute($group,$username,$pass,$fname,$lname,$phone,$type,$state); 463 466 464 467 # get the ID... … … 466 469 $sth->execute($username); 467 470 ($user_id) = $sth->fetchrow_array(); 471 472 ##fixme: add another table to hold name/email for log table? 468 473 469 474 # once we get here, we should have suceeded. … … 484 489 # 485 490 sub delUser { 491 my $dbh = shift; 492 return ('FAIL',"Need database handle") if !$dbh; 493 my $userid = shift; 494 return ('FAIL',"Missing userid") if !defined($userid); 495 496 my $sth = $dbh->prepare("delete from users where user_id=?"); 497 $sth->execute($userid); 498 499 return ('FAIL',"Couldn't remove user: ".$sth->errstr) if $sth->err; 500 501 return ('OK','OK'); 502 486 503 } # end delUser 504 505 506 ## DNSDB::userFullName() 507 # Return a pretty string! 508 # Takes a user_id and optional printf-ish string to indicate which pieces where: 509 # %u for the username 510 # %f for the first name 511 # %l for the last name 512 # All other text in the passed string will be left as-is. 513 ##fixme: need a "smart" option too, so that missing/null/blank first/last names don't give funky output 514 sub userFullName { 515 $errstr = ''; 516 my $dbh = shift; 517 my $userid = shift; 518 my $fullformat = shift || '%f %l (%u)'; 519 my $sth = $dbh->prepare("select username,firstname,lastname from users where user_id=?"); 520 $sth->execute($userid); 521 my ($uname,$fname,$lname) = $sth->fetchrow_array(); 522 $errstr = $DBI::errstr if !$uname; 523 524 $fullformat =~ s/\%u/$uname/g; 525 $fullformat =~ s/\%f/$fname/g; 526 $fullformat =~ s/\%l/$lname/g; 527 528 return $fullformat; 529 } # end userFullName 487 530 488 531 -
trunk/dns.cgi
r24 r25 445 445 } else { 446 446 ($code,$msg) = addUser($dbh,$webvar{username}, $webvar{group}, $webvar{pass1}, 447 ($webvar{makeactive} eq 'on' ? 1 : 0), $webvar{fname}, $webvar{lname}); 447 ($webvar{makeactive} eq 'on' ? 1 : 0), $webvar{accttype}, 448 $webvar{fname}, $webvar{lname}, $webvar{phone}); 448 449 } 449 450 450 451 # hokay, a bit of magic to decide which page we hit. 451 452 if ($code eq 'OK') { 452 # redirect to dns.cgi?etc&page=reclist453 453 changepage(page => "useradmin"); 454 # $page = HTML::Template->new(filename => "$templatedir/reclist.tmpl");455 # showdomain(0,$msg);456 ##work457 454 } else { 458 455 # oooh, yeah, this is supposed to be a redirect. er, maybe. whee. … … 469 466 470 467 $page->param(add_failed => 1); 468 469 } elsif ($webvar{page} eq 'deluser') { 470 471 $page->param(id => $webvar{id}); 472 # first pass = confirm y/n (sorta) 473 if (!defined($webvar{del})) { 474 $page->param(del_getconf => 1); 475 $page->param(user => userFullName($dbh,$webvar{id})); 476 } elsif ($webvar{del} eq 'ok') { 477 my ($code,$msg) = delUser($dbh, $webvar{id}); 478 if ($code ne 'OK') { 479 # need to find failure mode 480 $page->param(del_failed => 1); 481 $page->param(errmsg => $msg); 482 list_users($curgroup); 483 } else { 484 # success. go back to the domain list, do not pass "GO" 485 changepage(page => "useradmin"); 486 } 487 } else { 488 # cancelled. whee! 489 changepage(page => "useradmin"); 490 } 491 471 492 } 472 493 … … 821 842 822 843 my @userlist; 823 $sth = $dbh->prepare("SELECT u.user_id, u. email, u.firstname, u.lastname, u.type, g.group_name, u.status ".844 $sth = $dbh->prepare("SELECT u.user_id, u.username, u.firstname, u.lastname, u.type, g.group_name, u.status ". 824 845 "FROM users u ". 825 846 "INNER JOIN groups g ON u.group_id=g.group_id ". -
trunk/templates/useradmin.tmpl
r24 r25 29 29 <td class="underline" align="center" nowrap><a href="dns.cgi?sid=<TMPL_VAR NAME=sid>&page=domlist&offset=<TMPL_VAR NAME=offset>">Group<TMPL_IF NAME=sortuser> <img border=0 alt='<TMPL_VAR NAME=sortorder>' src="images/<TMPL_VAR NAME=sortorder>.png"></TMPL_IF></a></td> 30 30 <TMPL_ELSE> 31 <td class="underline" nowrap>User </td>32 <td class="underline" nowrap> Name</td>31 <td class="underline" nowrap>Username</td> 32 <td class="underline" nowrap>Full name</td> 33 33 <td class="underline" nowrap>Type</td> 34 34 <td class="underline" nowrap width="5%">Group</td>
Note:
See TracChangeset
for help on using the changeset viewer.