User Tools

Site Tools


advocacy:perl_reset_email

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

advocacy:perl_reset_email [2008/02/25 14:13] – created ericksonadvocacy:perl_reset_email [2022/02/10 13:34] (current) – external edit 127.0.0.1
Line 1: Line 1:
 +<code>
  
 +__PACKAGE__->register_method(
 +    method => 'reset_password_by_email',
 +    api_name => 'open-ils.actor.user.password.reset.email',
 +    signature => {
 +        desc => q/Reset a user's password and email the results to the user/,
 +        params => [{desc => 'username', type => 'string'}],
 +        return => {desc => q/Returns 1 on success, 0 on failure/, type  => 'number'}
 +    }
 + );
 + use Email::Send;
 + sub reset_password_by_email {
 +    my($self, $conn, $username) = @_;
 +    my $e = new_editor(xact=>1);
 +
 +    my $user = $e->search_actor_user({usrname => $username})->[0] 
 +        or  return 0;
 +    return 0 unless $user->email;
 +
 +    my $password =int(rand 10000);
 +    $user->passwd($password);
 +    $e->update_actor_user($user) or return 0;
 +
 +    my $sender = Email::Send->new({mailer => 'SMTP', mailer_args => 
 + [Host => 'localhost']});
 +    my $to_addr = $user->email;
 +    my $from_addr = 'evergreen@localhost';
 +
 +    my $email = <<EMAIL;
 +To: $to_addr
 +From: $from_addr
 +Subject: Password Verification
 +
 +Your password has been reset to $password.  Please log in and change it.
 +EMAIL
 +
 +    my $stat = $sender->send($email);
 +    if($stat and $stat->type eq 'success') {
 +        $e->commit;
 +        return 1;
 +    }
 +    return 0;
 +}
 +</code>

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki

© 2008-2022 GPLS and others. Evergreen is open source software, freely licensed under GNU GPLv2 or later.
The Evergreen Project is a U.S. 501(c)3 non-profit organization.