Ticket #380: reset-pass.diff
| File reset-pass.diff, 3.9 kB (added by dmorton, 2 years ago) |
|---|
-
maiadbtool.pl
118 118 sub unconflict($$$); 119 119 sub valid_address($); 120 120 sub valid_domain($); 121 sub reset_password($$$$); 121 122 122 123 123 # name of this script 124 124 my $script_name = "maiadbtool"; 125 125 … … 142 142 my @add_domains = (); 143 143 my @delete_domains = (); 144 144 my @link_addresses = (); 145 my @reset_passwords = (); 145 146 my $link_account = undef; 146 147 my $add_from_file = undef; 147 148 my $delete_from_file = undef; … … 163 164 "add-from-file=s" => \$add_from_file, 164 165 "delete-from-file|del-from-file=s" => \$delete_from_file, 165 166 "link-from-file=s" => \$link_from_file, 167 "reset-passwords=s" => \@reset_passwords, 166 168 "address-rewriting-type=i" => \$address_rewriting_type, 167 169 "routing-domain=s" => \$routing_domain, 168 170 "auth-method|authentication-method=s" => \$auth_method, … … 180 182 @add_domains = split(/,/, join(',', @add_domains)); 181 183 @delete_domains = split(/,/, join(',', @delete_domains)); 182 184 @link_addresses = split(/,/, join(',', @link_addresses)); 185 @reset_passwords = split(/,/, join(',', @reset_passwords)); 183 186 184 187 # Display usage information 185 188 if ($help) { … … 203 206 " --delete-from-file file : delete users and/or domains from a file\n" . 204 207 " --del-from-file file : same as --delete-from-file\n" . 205 208 " --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" . 206 210 " --address-rewriting-type code : address rewriting method [0..5] (see config.php)\n" . 207 211 " --routing-domain domain : routing domain (see config.php)\n" . 208 212 " --auth-method method : authentication method (see config.php)\n" . … … 276 280 dedupe(\@link_addresses); 277 281 dedupe(\@add_domains); 278 282 dedupe(\@delete_domains); 283 dedupe(\@reset_passwords); 279 284 280 285 # Identify any conflicting addresses and domains 281 286 unconflict(\@add_addresses, \@delete_addresses, $debug); … … 307 312 link_address($dbh, $address, $account, $debug, $quiet); 308 313 } 309 314 315 # Reset passwords 316 foreach my $user_name (@reset_passwords) { 317 reset_password($dbh, $user_name, $debug, $quiet); 318 } 310 319 # Bayes clear/expire 311 320 if ($clear_bayes) { 312 321 clear_bayes($dbh, $debug, $quiet); … … 1592 1601 } 1593 1602 1594 1603 1604 sub 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

