User Tools

Site Tools


advocacy:perl_reset_email
__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;
}
advocacy/perl_reset_email.txt · Last modified: 2008/02/25 14:13 by erickson

© 2008-2017 GPLS and others. Evergreen is open source software, freely licensed under GNU GPLv2 or later.
The Evergreen Project is a member of Software Freedom Conservancy.