[rt-users] Setting Password for new unpriv users (was: Newbie questions)
Larry Stone
lcs at MIT.EDU
Wed Jun 18 18:02:32 EDT 2003
> 1) Is there any way that e-mail tickets that require a new user to be
> created can assign a password too? None of the Scrips seem appropriate.
I just figured out how to implement this for a site here that's
planning to deploy RT. There was an old scrip posted to this list many
months ago that gave me a starting point, but it appears to have been
written for RT2 or an early prelrelease of RT3.
The following scrip and template are running on RT 3.0.2 plus a couple
of my patches which I'm also appending below.
First, the scrip. Perhaps more seasoned RT hackers can see a more
elegant way to accomplish the same thing; this is my first real RT work.
1. Add a new global scrip called "Create Password", with the following
settings:
Condition: "On Create"
Action: "User Defined"
Template: "Global Template: Blank"
The custom action condition and cleanup code are both set to "1;".
All of the business is in the "preparation" code, which is:
----------start code-------------
{
my $tmplName = 'RT_PasswordChange'; ## hardwired template name
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) {
my $template = RT::Template->new( $user->CurrentUser );
$template->LoadGlobalTemplate($tmplName);
unless ($template->Id) {
$RT::Logger->crit( "$user tried to send ". $user->Name .
" a password reminder, but couldn't find tmpl: $tmplName");
die "failed to load $tmplName template";
}
my $notification = RT::Action::SendEmail->new(
TemplateObj => $template,
TransactionObj => $self->TransactionObj,
TicketObj => $self->TicketObj,
ScripObj => $self->ScripObj,
Argument => $pass);
@{ $notification->{'To'} } = ( $user->EmailAddress );
my ($ret) = $notification->Prepare();
$ret = $notification->Commit() if $ret;
$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-----------------
2. Add a global template for the email:
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 ----------------------------------
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'} ) );
}
More information about the rt-users
mailing list