[Koha-patches] [PATCH] Bug 5299 Allow patron to update email if they are allowed to update password

Darrell Ulm koha at smfpl.org
Fri Oct 8 21:36:12 CEST 2010


The update email option is in a separate opac menu option.

To update or add an email requires the patron to type in their password as well
as the email address to change their email to.

This is the patch I meant to send!

   Darrell Ulm
---
 koha-tmpl/opac-tmpl/prog/en/includes/usermenu.inc  |    5 +-
 .../prog/en/modules/opac-changeemail.tmpl          |   87 +++++++++++++++
 opac/opac-changeemail.pl                           |  115 ++++++++++++++++++++
 3 files changed, 206 insertions(+), 1 deletions(-)
 create mode 100644 koha-tmpl/opac-tmpl/prog/en/modules/opac-changeemail.tmpl
 create mode 100755 opac/opac-changeemail.pl

diff --git a/koha-tmpl/opac-tmpl/prog/en/includes/usermenu.inc b/koha-tmpl/opac-tmpl/prog/en/includes/usermenu.inc
index 34d2a5f..3b1a901 100644
--- a/koha-tmpl/opac-tmpl/prog/en/includes/usermenu.inc
+++ b/koha-tmpl/opac-tmpl/prog/en/includes/usermenu.inc
@@ -12,6 +12,9 @@
   <!-- TMPL_IF NAME="OpacPasswordChange" -->
     <!-- TMPL_IF NAME="passwdview" --><li class="active"><!-- TMPL_ELSE --><li><!-- /TMPL_IF --><a href="/cgi-bin/koha/opac-passwd.pl">change my password</a></li>
   <!-- /TMPL_IF -->
+  <!-- TMPL_IF NAME="OpacPasswordChange" -->
+    <!-- TMPL_IF NAME="emailchangeview" --><li class="active"><!-- TMPL_ELSE --><li><!-- /TMPL_IF --><a href="/cgi-bin/koha/opac-changeemail.pl?display=privateshelves">add or change email</a></li>
+  <!-- /TMPL_IF -->
   <!-- TMPL_IF NAME="ShowOpacRecentSearchLink" -->
   <!-- TMPL_IF NAME="searchhistoryview" --><li class="active"><!-- TMPL_ELSE --><li><!-- /TMPL_IF --><a href="/cgi-bin/koha/opac-search-history.pl">my search history</a></li>
   <!-- /TMPL_IF -->
@@ -28,7 +31,7 @@
   <!-- /TMPL_IF -->
   <!-- TMPL_IF NAME="virtualshelves" --> 
   <!-- TMPL_IF NAME="listsview" --><li class="active"><!-- TMPL_ELSE --><li><!-- /TMPL_IF --><a href="/cgi-bin/koha/opac-shelves.pl?display=privateshelves">my lists</a></li>
-  <!-- /TMPL_IF -->
+
 </ul>
 </div>
 <!-- /TMPL_IF -->
diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-changeemail.tmpl b/koha-tmpl/opac-tmpl/prog/en/modules/opac-changeemail.tmpl
new file mode 100644
index 0000000..dc78ed7
--- /dev/null
+++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-changeemail.tmpl
@@ -0,0 +1,87 @@
+<!-- TMPL_INCLUDE name="doc-head-open.inc" -->
+<!-- TMPL_IF NAME="LibraryNameTitle" -->
+<!-- TMPL_VAR NAME="LibraryNameTitle" -->
+<!-- TMPL_ELSE -->Koha Online
+<!-- /TMPL_IF --> Catalog &rsaquo;  Account for <!-- TMPL_VAR name="firstname" --> <!-- TMPL_VAR name="surname" -->
+<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
+</head>
+<body id="opac-changeemail">
+<div id="doc3" class="yui-t1">
+  <div id="bd">
+<!-- TMPL_INCLUDE name="masthead.inc" -->
+
+       <div id="yui-main">
+       <div class="yui-b"><div class="yui-g">
+       <div class="container">
+       <h3><a href="/cgi-bin/koha/opac-user.pl
+ 
+"><!-- TMPL_VAR NAME="firstname" --> <!-- TMPL_VAR NAME="surname" -->'s account</a> <img src="<!-- TMPL_VAR NAME="themelang" -->l../../images/caret.gif" width="16" height="16" alt="&gt;" border="0" /> Change your Email or Add an Email </h3>
+
+   <!-- TMPL_IF NAME= "Error_messages" -->
+<div class="dialog error">        <h3>There was a problem with your submission</h3>
+       <p>
+           <!-- TMPL_IF NAME= "WrongPass" -->
+           Your current password was entered incorrectly.  If this problem persists, please ask a librarian to re-set your password for you.
+           <!-- /TMPL_IF -->
+           <!-- TMPL_IF NAME= "EmailPassMismatch" -->
+           When you tried to change your email, your current password was entered incorrectly.  If this problem persists, please ask a librarian to re-set your password for you.
+           <!-- /TMPL_IF -->
+           <!-- TMPL_IF NAME= "EmailNotChanged" -->
+           Your email was not changed because you did not provide your login password to verify. If you wish to
+           change your email then you need to include your password also.
+           <!-- /TMPL_IF -->
+           <!-- TMPL_IF NAME= "NoEmailAddress" -->
+           You did not provide an email address to either add or change. Please provide an email address
+           if you wish to update your email.
+           <!-- /TMPL_IF -->
+       </p></div>
+   <!-- /TMPL_IF -->
+
+   <!-- TMPL_IF NAME= "Ask_data" -->
+       <ul>
+       <li>Current Email: <i><!-- TMPL_VAR NAME="oldemail" --></i>
+       </li>
+       <li>Prior Email: <i><!-- TMPL_VAR NAME="oldemailpro" --></i>
+       </li>
+       </ul>
+ 
+       <!-- TMPL_IF NAME="OpacPasswordChange" -->
+       <form action="/cgi-bin/koha/opac-changeemail.pl
+ 
+" name="mainform" id="mainform" method="post"><fieldset class="brief">
+         <ol>  <li><label for="password">Current Password:</label> <input type="password" id="Oldkey" size="25"  name="Oldkey" /></li>
+
+               <li><label for="Newemail"><i>New Email: (Use only if you would like to change or add an email on file.<br /> &nbsp; If changing your email, only fill in your Current Password and the either new or changed email. </i> </label> <input type="text" id="Newemail"  size="40"  name="Newemail" /></li>
+               <li> &nbsp; </li>
+           </ol>
+           <fieldset class="action"><input type="submit" value="Submit Changes" class="submit" /> <a href="/cgi-bin/koha/opac-user.pl
+ 
+" class="cancel">Cancel</a></fieldset>
+   </form>
+       <!-- TMPL_ELSE -->
+           <div class="dialog alert">You can't change your email.</div>
+       <!-- /TMPL_IF -->
+   <!-- /TMPL_IF -->
+
+   <!-- TMPL_IF NAME= "email_updated" -->
+       <div class="dialog message"><h1>Email Updated</h1>
+       Your Email has been changed to: <!-- TMPL_VAR NAME="newemail" --></div>
+       <form action="/cgi-bin/koha/opac-user.pl
+ 
+" method="post">
+           <input type="hidden" name="borrowernumber" value="<!-- TMPL_VAR NAME="borrowernumber" -->" />
+           <p><input type="submit" class="icon back" value="Return to Your Record" /></p>
+       </form>
+   <!-- /TMPL_IF -->
+</div>
+</div>
+</div>
+</div>
+<div class="yui-b">
+<div class="container">
+<!--TMPL_INCLUDE NAME="navigation.inc" -->
+<!-- TMPL_INCLUDE name="usermenu.inc" -->
+</div>
+</div>
+</div>
+<!-- TMPL_INCLUDE NAME="opac-bottom.inc" -->
\ No newline at end of file
diff --git a/opac/opac-changeemail.pl b/opac/opac-changeemail.pl
new file mode 100755
index 0000000..3eec937
--- /dev/null
+++ b/opac/opac-changeemail.pl
@@ -0,0 +1,115 @@
+#!/usr/bin/perl
+# This script lets the users change their email by themselves.
+#
+# (c) 2005 Universidad ORT Uruguay.
+#
+# This file is part of the extensions and enhacments made to koha by Universidad ORT Uruguay
+#
+# Modification of Passwd.pl code by Darrell Ulm
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+# Suite 330, Boston, MA  02111-1307 USA
+
+use strict;
+
+use CGI;
+
+use C4::Auth;    # checkauth, getborrowernumber.
+use C4::Context;
+use Digest::MD5 qw(md5_base64);
+use C4::Circulation;
+use C4::Members;
+use C4::Output;
+
+my $query = new CGI;
+my $dbh   = C4::Context->dbh;
+
+my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
+   {
+       template_name   => "opac-changeemail.tmpl",
+       query           => $query,
+       type            => "opac",
+       authnotrequired => 0,
+       flagsrequired   => { borrow => 1 },
+       debug           => 1,
+   }
+);
+
+# get borrower information ....
+my ( $borr ) = GetMemberDetails( $borrowernumber );
+my $sth =  $dbh->prepare("UPDATE borrowers SET password = ? WHERE borrowernumber=?");
+my $minpasslen = C4::Context->preference("minPasswordLength");
+
+my $oldemail = $borr->{'email'};
+my $oldemailpro = $borr->{'emailpro'};
+
+if (   $query->param('Oldkey')
+       && $query->param('Newemail')   )
+       {
+   if ( goodkey( $dbh, $borrowernumber, $query->param('Oldkey') ) )
+               {
+               my $sthemail =  $dbh->prepare("UPDATE borrowers SET email = ? WHERE borrowernumber=?");
+               $sthemail->execute( $query->param('Newemail'), $borrowernumber );
+               $template->param( 'email_updated' => '1' );
+               if ($oldemailpro =~ /^$/)
+                       {
+                       my $sthemail2 =  $dbh->prepare("UPDATE borrowers SET emailpro = ? WHERE borrowernumber=?");
+                       $sthemail2->execute( $oldemail, $borrowernumber );
+                       }
+               }
+       else    {
+               $template->param( 'Error_messages' => '1' );
+               $template->param( 'EmailPassMismatch'   => '1' );
+               }
+       }
+elsif (   $query->param('Newemail')
+   && ! $query->param('Oldkey') )
+       {
+       $template->param( 'EmailNotChanged'   => '1' );
+       $template->param( 'Error_messages' => '1' );
+       }
+elsif ( !  $query->param('Newemail')
+   &&  $query->param('Oldkey') )
+       {
+       $template->param( 'NoEmailAddress'   => '1' );
+       $template->param( 'Error_messages' => '1' );
+       }
+else    {
+       $template->param( 'Ask_data'       => '1' );
+       $template->param(  emailchangeview => 1 );
+       }
+
+$template->param(                                      firstname => $borr->{'firstname'},
+                                                       oldemail => $borr->{'email'},
+                                                       oldemailpro => $borr->{'emailpro'},
+                                                       surname => $borr->{'surname'},
+                                                       minpasslen => $minpasslen,
+                                                       newemail => $query->param('Newemail'),
+                                                       emailview => 1,
+                                                       );
+
+output_html_with_http_headers $query, $cookie, $template->output;
+
+sub goodkey {
+   my ( $dbh, $borrowernumber, $key ) = @_;
+
+   my $sth =
+     $dbh->prepare("SELECT password FROM borrowers WHERE borrowernumber=?");
+   $sth->execute($borrowernumber);
+   if ( $sth->rows ) {
+       my ($md5password) = $sth->fetchrow;
+       if ( md5_base64($key) eq $md5password ) { return 1; }
+       else { return 0; }
+   }
+   else { return 0; }
+}
\ No newline at end of file
-- 
1.5.6.5



More information about the Koha-patches mailing list