Changeset 25 for trunk


Ignore:
Timestamp:
11/02/09 16:40:07 (15 years ago)
Author:
Kris Deugau
Message:

/trunk

checkpoint

  • pass all entered data through to addUser()
  • copy-munge "delete user" segment
  • fill out missing addUser internals
  • fill out delUser stub
  • add userFullName
  • misc tweaks and normalizations
Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r24 r25  
    2626        &addDomain &delDomain &domainName
    2727        &addGroup &delGroup &getChildren &groupName
    28         &addUser &delUser
     28        &addUser &delUser &userFullName
    2929        &getSOA &getRecLine &getDomRecs
    3030        &addRec &updateRec &delRec
     
    3838                &addDomain &delDomain &domainName
    3939                &addGroup &delGroup &getChildren &groupName
    40                 &addUser &delUser
     40                &addUser &delUser &userFullName
    4141                &getSOA &getRecLine &getDomRecs
    4242                &addRec &updateRec &delRec
     
    442442  my $pass = shift;
    443443  return ('FAIL',"Missing password") if !defined($pass);
    444 
    445444  my $state = shift;
    446445  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;
    448450  my $lname = shift || '';
     451  my $phone = shift || '';      # not going format-check
    449452
    450453  my $user_id;
     
    458461  eval {
    459462    # 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);
    463466
    464467    # get the ID...
     
    466469    $sth->execute($username);
    467470    ($user_id) = $sth->fetchrow_array();
     471
     472##fixme: add another table to hold name/email for log table?
    468473
    469474    # once we get here, we should have suceeded.
     
    484489#
    485490sub 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
    486503} # 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
     514sub 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
    487530
    488531
  • trunk/dns.cgi

    r24 r25  
    445445  } else {
    446446    ($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});
    448449  }
    449450
    450451# hokay, a bit of magic to decide which page we hit.
    451452  if ($code eq 'OK') {
    452 # redirect to dns.cgi?etc&page=reclist
    453453    changepage(page => "useradmin");
    454 #    $page = HTML::Template->new(filename => "$templatedir/reclist.tmpl");
    455 #    showdomain(0,$msg);
    456 ##work
    457454  } else {
    458455# oooh, yeah, this is supposed to be a redirect.  er, maybe.  whee.
     
    469466
    470467  $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
    471492}
    472493
     
    821842
    822843  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 ".
    824845        "FROM users u ".
    825846        "INNER JOIN groups g ON u.group_id=g.group_id ".
  • trunk/templates/useradmin.tmpl

    r24 r25  
    2929        <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>&nbsp;<img border=0 alt='<TMPL_VAR NAME=sortorder>' src="images/<TMPL_VAR NAME=sortorder>.png"></TMPL_IF></a></td>
    3030<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>
    3333        <td class="underline" nowrap>Type</td>
    3434        <td class="underline" nowrap width="5%">Group</td>
Note: See TracChangeset for help on using the changeset viewer.