Dzahn has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/71719


Change subject: add AfterForm to RT4 to (re-)enable Password Reset feature on RT
......................................................................

add AfterForm to RT4 to (re-)enable Password Reset feature on RT

RT #5408
puppetize livehack. the additional dirs and file needed per:

http://requesttracker.wikia.com/wiki/PasswordReset

plus a few minor fixes needed to make it work

still need to confirm it actually sends out the mail

Change-Id: Ib7ebd69f1c4a25c51fd7146a6711d9ac66a2b310
---
A files/rt/AfterForm
M manifests/misc/rt-server-apache.pp
2 files changed, 150 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/19/71719/1

diff --git a/files/rt/AfterForm b/files/rt/AfterForm
new file mode 100644
index 0000000..020cd62
--- /dev/null
+++ b/files/rt/AfterForm
@@ -0,0 +1,141 @@
+%# this adds the "Reset Password" feature to RT.
+%# slightly modified version from:
+%# http://requesttracker.wikia.com/wiki/PasswordReset
+%# taken from http://www2.usit.uio.no/it/rt/modifications/
+%# Add template named 'Password Change', with description
+%#
+%#   Automatically generate password for external users who have forgotten 
their password
+%#
+
+
+<div style="margin: -20px auto 10px auto; text-align: center;">
+
+
+            <b>Forgot Your Password?</b>
+            <div style="color: green; font-weight: 
bold;"><%$forgotSuccess%></div>
+           <form method="get" style="display: <%$forgotFormDisplay%>;" 
action="NoAuth/Login.html">
+
+% if($forgotFail) {
+        <div class="error" style="text-align: left;">
+            <div class="titlebox error">
+                <div class="titlebox-title">
+                    <span class="left">Error</span><span class="right-empty"> 
</span>
+                </div>
+                <div class="titlebox-content">
+                    <%$forgotFail%><hr class="clear" />
+                </div>
+            </div>
+        </div>
+% }
+                <%$forgotPrompt%> <input type="text" name="email"> <input 
type="submit" value='Send New Password'>
+            </form>
+        </div>
+
+
+        <%INIT>
+        my $forgotPrompt = "Enter your email address: ";
+        my $forgotFail = '';
+        my $forgotFormDisplay = 'block';
+        my $forgotSuccess = '';
+
+        my $mailfrom = 'RT <[email protected]>';
+        if ($email)
+        {
+            $email =~ s/^\s+|\s+$//g;
+            my $UserObj = RT::User->new($RT::SystemUser);
+            $UserObj->LoadByEmail($email);
+
+            if (defined($UserObj->Id))
+            {
+                my ($val, $str) = ResetPassword($UserObj, $mailfrom);
+                if($val > 0)
+                {
+                    $forgotFormDisplay = 'none';
+                    $forgotSuccess = $str;
+                }
+                else
+                {
+                    $forgotFail = $str;
+                }
+            }
+            else
+            {
+                $forgotFail = "Sorry, no account in the ticket system has the 
email address: $email";
+                $forgotPrompt = "Please enter the email used in one of your 
existing tickets:";
+            }
+        }
+
+        sub ResetPassword {
+            my $self = shift;
+            my $mailfrom = shift;
+
+            my $email = $self->EmailAddress;
+
+            unless ( $self->CurrentUserCanModify('Password') ) {
+                return ( 0, $self->loc("You don't have permission to change 
your password.") );
+            }
+
+            unless ( ($self->Name =~ m/\@/) ) {
+                return ( 0, $self->loc("Only external users can reset their 
passwords this way.") );
+            }
+
+            my ( $status, $pass ) = $self->SetRandomPassword();
+
+            unless ($status) {
+                return ( 0, "$pass" );
+            }
+
+            my $template = RT::Template->new( $self->CurrentUser );
+
+            my $parsed;
+            # This test do not work.  I'm not sure how to detect if the 
template loading failed [pere 2006-08-16]
+            if ($template->LoadGlobalTemplate('PasswordChange')) {
+                $T::RealName = $self->RealName;
+                $T::Username = $self->Name;
+                $T::Password = $pass;
+                $parsed = $template->_ParseContent();
+            }
+            else
+            {
+
+        # hardcoded default text body in case 'Password Change' template is 
missing.
+
+                $parsed = <<EOF;
+
+        Greetings,
+
+        This message was automatically sent in response to a Reset Password 
request in
+        the web based ticket system.
+
+        You may now login using the following:
+
+                Username: $self->Name
+                Password: $pass
+
+        Wikimedia Ops
+
+EOF
+            }
+            my $entity = MIME::Entity->build(
+                                              From    => $mailfrom,
+                                              To      => $email,
+                                              Subject => loc("CF Ticket 
Password Changed"),
+                                              'X-RT-Loop-Prevention' => 
$RT::rtname,
+                                              Type    => "text/plain",
+                                              Charset => "UTF-8",
+                                              Data    => [$parsed]
+                                            );
+            open (MAIL, "|$RT::SendmailPath $RT::SendmailArguments -t") || 
return(0, "Failed to open mailpipe");
+            print MAIL $entity->as_string;
+            close(MAIL);
+
+            return (1, "SUCCESS! A new password was sent to your email 
address.");
+        }
+        </%INIT>
+
+        <%ARGS>
+        $email => undef
+  # if you are using RT4, you need this next line:
+        $next => undef
+  # end for RT4
+        </%ARGS>
diff --git a/manifests/misc/rt-server-apache.pp 
b/manifests/misc/rt-server-apache.pp
index d9a9f19..f5df9dd 100644
--- a/manifests/misc/rt-server-apache.pp
+++ b/manifests/misc/rt-server-apache.pp
@@ -46,6 +46,15 @@
     '/etc/request-tracker4/rt.conf':
       require => Package['request-tracker4'],
       content => $rtconf;
+    # the password-reset self-service form
+    '/usr/local/share/request-tracker4/html':
+    '/usr/local/share/request-tracker4/html/Callbacks':
+    '/usr/local/share/request-tracker4/html/Callbacks/Default':
+    '/usr/local/share/request-tracker4/html/Callbacks/Default/Elements':
+    '/usr/local/share/request-tracker4/html/Callbacks/Default/Elements/Login':
+      ensure => 'directory';
+    
'/usr/local/share/request-tracker4/html/Callbacks/Default/Elements/Login/AfterForm':
+      source  => 'puppet:///files/rt/AfterForm';
   }
 
   exec { 'update-rt-siteconfig':

-- 
To view, visit https://gerrit.wikimedia.org/r/71719
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib7ebd69f1c4a25c51fd7146a6711d9ac66a2b310
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Dzahn <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to