[rt-users] configuration question

Larry Stone lcs at MIT.EDU
Wed Jun 25 01:52:33 EDT 2003


> When someone sends an email the first time to RT, his account is automatically
> created  with *NO-PASSWORD* in RT database.  Instead of this, I like his account
> be created with a RANDOM password and then the password be sent to the requestor
> of the email automatically.  I see there is a "ResetPassword" function in
> 'lib/RT/User_Overlay.pm' but can't seems to figure out how to get that working.

Here's a slightly improved version of the scrip I posted a few days ago
that does this.

[How can this get into the FAQ or the contrib directory, since it
 seems to come up pretty often..?]

---
The following scrip and template are running on RT 3.0.2 plus a couple
of my patches which I'm also appending below.

Scrip & Template to automatically set random password for a newly-created
unprivileged user (created by his/her first email message to a queue).  The
scrip also emails the password to the new user so they can login.

NOTE: You MUST apply the source patches at the end of this page to
any version of RT before 3.0.4. (They will be included in 3.0.4)

This is just an example; of course the names of the scrip and template
can be different in your implementation.

1. Add a global email template:

Name: "RT_PasswordChange"
---------------- Contents of template ----------------------------------
Subject: Welcome to RT: How to login

Greetings, {$Transaction->CreatorObj->Name()}

A login account has been created for you automatically
with your first request to this tracking system.
To use it, go to the following URL with your browser:

  {$RT::WebURL}

To login, enter the username "{$Transaction->CreatorObj->Name()}"
and the password "{$Argument}".

Please contact {$RT::OwnerEmail} if you have any problems or questions.

Enjoy,

   -- Your RT Administrator
---------------- End Contents of template ----------------------------------



2. Add a new global scrip called "Create Password", with the following
settings:

  Condition: "On Create"
  Action: "User Defined"
  Template: "RT_PasswordChange"
  Set custom action condition and cleanup code to "1;".
  All of the action is in the "preparation" code, which is:
----------start code-------------
{
  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;
}
----------------end scrip prepare code-----------------


3. Finally apply the following source patches to fix a couple of bugs
that interfered with this working.

---------------- Begin source patch  ----------------------------------
*** RT/User_Overlay.pm.orig     Mon May 12 20:31:24 2003
--- RT/User_Overlay.pm  Wed Jun 18 02:16:33 2003
***************
*** 871,877 ****

      my $length = $min_length + int( rand( $max_length - $min_length ) );

!     my $char = $self->GenerateRandomNextChar( $total_sum, $start_freq );
      my @word = ( $char + $a );
      for ( 2 .. $length ) {
          $char =
--- 871,877 ----

      my $length = $min_length + int( rand( $max_length - $min_length ) );

!     my $char = $self->_GenerateRandomNextChar( $total_sum, $start_freq );
      my @word = ( $char + $a );
      for ( 2 .. $length ) {
          $char =
*** RT/Template_Overlay.pm.orig Mon May 12 20:31:24 2003
--- RT/Template_Overlay.pm      Wed Jun 18 02:21:51 2003
***************
*** 203,212 ****
      my $self = shift;
      my %args = (
          Queue => undef,
!         Name  => undef
      );

!     return ( $self->LoadByCols( Name => $args{'Name'}, Queue => {'Queue'} ) );

  }

--- 203,213 ----
      my $self = shift;
      my %args = (
          Queue => undef,
!         Name  => undef,
!         @_
      );

!     return ( $self->LoadByCols( Name => $args{'Name'}, Queue => $args{'Queue'} ) );

  }

_______________________________________________
rt-users mailing list
rt-users at lists.fsck.com
http://lists.fsck.com/mailman/listinfo/rt-users

Have you read the FAQ? The RT FAQ Manager lives at http://fsck.com/rtfm




More information about the rt-users mailing list