[rt-users] Re: SelfService Login Not Working

Larry Stone lcs at MIT.EDU
Thu May 20 02:05:41 EDT 2004


> I don't recall that someone post extension which generate password for
> new account and send it to user.
> There is incomplete password reminder in RT which should regenerate
> password and send it to user.

I wrote scrips to do this for one of my instances; this is a scrip
that runs OnCreate with the following action, to set a random password
for newly-created users and email it to them: (runs on 3.0.10, I did have
to patch an earlier 3.0.x to make it work and got the patch adopted)

{
  my ($user) = $self->TransactionObj->CreatorObj;
  if (($user->id != $RT::Nobody->id) && (!$user->Privileged) &&
      $user->__Value('Password') eq '*NO-PASSWORD*' && $user->Name =~ /\@/) {
    my ($stat, $pass) = $self->TransactionObj->CreatorObj->SetRandomPassword();
    if ($stat) {
      unless ($self->TemplateObj) {
        $RT::Logger->crit( "$user tried to send ". $user->Name .
        " a password reminder, but doesn't have a template!");
        die "failed to find template";
      }
      my $email = RT::Action::SendEmail->new(ScripObj => $self->ScripObj,
            TemplateObj => $self->TemplateObj, TicketObj => $self->TicketObj,
            TransactionObj => $self->TransactionObj, Argument => $pass);
      @{ $email->{'To'} } = ( $user->EmailAddress );
      my ($ret) = $email->Prepare() && $email->Commit();
      $RT::Logger->crit("Set Password scrip: $user: SendEmail failed sending ".
         $user->Name . " the password setting reminder.") unless ($ret);
    } else {
      $RT::Logger->crit("Set Password Scrip: Failed to set password for: \"".
        $user->Name."\", pass=".$pass);
    }
  }
  1;
}

The relevant part of the template is:

    To login, enter the username "{$Transaction->CreatorObj->Name()}"
    and the password "{$Argument}". You may change your password once in the
    system.

I set up a separate queue for the purpose of resetting passwords automatically.
Any message sent to that queue invokes a scrip that resets the password
and sends mail back to the user with the new one; the guts of the scrip:

{
  my ($user) = $self->TransactionObj->CreatorObj;
  if (($user->id != $RT::Nobody->id) && (!$user->Privileged) &&
      $user->Name =~ /\@/) {
    my ($stat, $pass) = $self->TransactionObj->CreatorObj->SetRandomPassword();
    if ($stat) {
      unless ($self->TemplateObj) {
        $RT::Logger->crit( "$user tried to send ". $user->Name .
        " a password reminder, but doesn't have a template!");
        die "failed to find template";
      }
      my $email = RT::Action::SendEmail->new(ScripObj => $self->ScripObj,
            TemplateObj => $self->TemplateObj, TicketObj => $self->TicketObj,
            TransactionObj => $self->TransactionObj, Argument => $pass);
      @{ $email->{'To'} } = ( $user->EmailAddress );
      my ($ret) = $email->Prepare() && $email->Commit();
      $RT::Logger->crit("Set Password scrip: $user: SendEmail failed sending ".
         $user->Name . " the password setting reminder.") unless ($ret);
    } else {
      $RT::Logger->crit("Set Password Scrip: Failed to set password for: \"".
        $user->Name."\", pass=".$pass);
    }
  }
  1;
}

hope this helps,

    -- Larry




More information about the rt-users mailing list