Ticket #380: reset-pass.diff

File reset-pass.diff, 3.9 kB (added by dmorton, 2 years ago)

I think the formatting in email may have mugned this up, but I tried to repair it.

  • maiadbtool.pl

     
    118118sub unconflict($$$); 
    119119sub valid_address($); 
    120120sub valid_domain($); 
     121sub reset_password($$$$); 
    121122 
    122  
    123123# name of this script 
    124124my $script_name = "maiadbtool"; 
    125125 
     
    142142my @add_domains = (); 
    143143my @delete_domains = (); 
    144144my @link_addresses = (); 
     145my @reset_passwords = (); 
    145146my $link_account = undef; 
    146147my $add_from_file = undef; 
    147148my $delete_from_file = undef; 
     
    163164           "add-from-file=s" => \$add_from_file, 
    164165           "delete-from-file|del-from-file=s" => \$delete_from_file, 
    165166           "link-from-file=s" => \$link_from_file, 
     167           "reset-passwords=s" => \@reset_passwords, 
    166168           "address-rewriting-type=i" => \$address_rewriting_type, 
    167169           "routing-domain=s" => \$routing_domain, 
    168170           "auth-method|authentication-method=s" => \$auth_method, 
     
    180182@add_domains = split(/,/, join(',', @add_domains)); 
    181183@delete_domains = split(/,/, join(',', @delete_domains)); 
    182184@link_addresses = split(/,/, join(',', @link_addresses)); 
     185@reset_passwords = split(/,/, join(',', @reset_passwords)); 
    183186 
    184187# Display usage information 
    185188if ($help) { 
     
    203206           "   --delete-from-file file            : delete users and/or domains from a file\n" . 
    204207           "   --del-from-file file               : same as --delete-from-file\n" . 
    205208           "   --link-from-file file              : link addresses to user accounts from a file\n" . 
     209           "   --reset-passwords user1,user2,...  : reset password on accounts and send new user email\n" . 
    206210           "   --address-rewriting-type code      : address rewriting method [0..5] (see config.php)\n" . 
    207211           "   --routing-domain domain            : routing domain (see config.php)\n" . 
    208212           "   --auth-method method               : authentication method (see config.php)\n" . 
     
    276280dedupe(\@link_addresses); 
    277281dedupe(\@add_domains); 
    278282dedupe(\@delete_domains); 
     283dedupe(\@reset_passwords); 
    279284 
    280285# Identify any conflicting addresses and domains 
    281286unconflict(\@add_addresses, \@delete_addresses, $debug); 
     
    307312    link_address($dbh, $address, $account, $debug, $quiet); 
    308313} 
    309314 
     315# Reset passwords 
     316foreach my $user_name (@reset_passwords) { 
     317    reset_password($dbh, $user_name, $debug, $quiet); 
     318} 
    310319# Bayes clear/expire 
    311320if ($clear_bayes) { 
    312321    clear_bayes($dbh, $debug, $quiet); 
     
    15921601} 
    15931602 
    15941603 
     1604sub reset_password($$$$) { 
     1605       my($dbh, $user_name, $debug, $quiet) = @_; 
     1606    my($sth, $query, @row, $user_id, $user_primary_email_id, $user_email); 
     1607 
     1608    # get the id's of the account 
     1609    $query = "SELECT id, primary_email_id FROM maia_users WHERE user_name = ?"; 
     1610    $sth = $dbh->prepare($query) 
     1611               or fatal(sprintf("Couldn't prepare query: %s", $dbh->errstr)); 
     1612    $sth->execute($user_name) 
     1613        or fatal(sprintf("Couldn't execute query: %s", $dbh->errstr)); 
     1614    if (!((@row) = $sth->fetchrow_array())) { 
     1615        fatal("Couldn't find user '$user_name' in the maia_users table"); 
     1616    } 
     1617       $user_id = $row[0]; 
     1618       $user_primary_email_id = $row[1]; 
     1619    $sth->finish; 
     1620 
     1621       # get the account's primary email 
     1622       $query = "SELECT email FROM users WHERE id = ?"; 
     1623    $sth = $dbh->prepare($query) 
     1624               or fatal(sprintf("Couldn't prepare query: %s", $dbh->errstr)); 
     1625    $sth->execute($user_primary_email_id) 
     1626        or fatal(sprintf("Couldn't execute query: %s", $dbh->errstr)); 
     1627    if (!(($user_email) = $sth->fetchrow())) { 
     1628        fatal("Couldn't find email for id '$user_id' (with user_name '$user_name' and primary_email_id '$user_primary_email_id')"); 
     1629    } 
     1630    $sth->finish; 
     1631 
     1632    output("Issuing new password to user account '$user_name' with id '$user_id' and primary address '$user_email'") if ($debug); 
     1633 
     1634       issue_password($dbh, $user_email, $user_id); 
     1635} 
     1636 No newline at end of file