@@ -, +, @@
1) apply the patch
2) go to system preferences OPAC>>Privacy and set 'OpacResetPassword' to ON. That will cause the link 'Forgot your password' to show up on the welcome page, below connection box.
3) refresh front page, click on 'Forgot your password' and enter a VALID address (one that is associated to an entry in borrowers.email or borrowers.email_pro.
3b) Also try an INVALID address (valid yet not in your koha db). An error message will show up.
4) An email should be received at that address with a link.
5) Follow the link in the mail to fill the new password.
Until a satisfactory new password is entered, the old password is not reset.
6) Go to main page try the new password.
http://bugs.koha-community.org/show_bug.cgi?id=10951
---
C4/Auth.pm | 2 +
C4/Members.pm | 82 ++++++-
installer/data/mysql/kohastructure.sql | 12 ++
installer/data/mysql/sysprefs.sql | 3 +-
installer/data/mysql/updatedatabase.pl | 8 +
.../prog/en/modules/admin/preferences/opac.pref | 7 +
koha-tmpl/opac-tmpl/prog/en/modules/opac-auth.tt | 3 +
koha-tmpl/opac-tmpl/prog/en/modules/opac-main.tt | 6 +-
.../prog/en/modules/opac-password-recovery.tt | 129 +++++++++++
.../prog/en/modules/opac-send-password-recovery.tt | 13 ++
opac/opac-main.pl | 1 +
opac/opac-password-recovery.pl | 223 ++++++++++++++++++++
12 files changed, 486 insertions(+), 3 deletions(-)
create mode 100644 koha-tmpl/opac-tmpl/prog/en/modules/opac-password-recovery.tt
create mode 100644 koha-tmpl/opac-tmpl/prog/en/modules/opac-send-password-recovery.tt
create mode 100755 opac/opac-password-recovery.pl
--- a/C4/Auth.pm
+++ a/C4/Auth.pm
@@ -1044,6 +1044,8 @@ sub checkauth {
PatronSelfRegistrationDefaultCategory => C4::Context->preference("PatronSelfRegistrationDefaultCategory"),
persona => C4::Context->preference("Persona"),
opac_css_override => $ENV{'OPAC_CSS_OVERRIDE'},
+ OpacResetPassword => C4::Context->preference("OpacResetPassword"),
+ OpacPasswordChange => C4::Context->preference("OpacPasswordChange"),
);
$template->param( OpacPublic => C4::Context->preference("OpacPublic"));
--- a/C4/Members.pm
+++ a/C4/Members.pm
@@ -41,6 +41,12 @@ use Koha::DateUtils;
use Text::Unaccent qw( unac_string );
use C4::Auth qw(hash_password);
+## Password recovery
+use CGI;
+use Encode qw(encode decode);
+use MIME::QuotedPrint qw(encode_qp);
+use Mail::Sendmail;
+
our ($VERSION,@ISA,@EXPORT,@EXPORT_OK,$debug);
BEGIN {
@@ -109,7 +115,12 @@ BEGIN {
push @EXPORT, qw(
&ModMember
&changepassword
- &ModPrivacy
+ &ModPrivacy
+ );
+
+ # Password recovery
+ push @EXPORT, qw(
+ &SendPasswordRecoveryEmail
);
#Delete data
@@ -2264,6 +2275,75 @@ sub ModPrivacy {
privacy => $privacy );
}
+
+sub SendPasswordRecoveryEmail {
+ my $borrowernumber = shift;
+ my $email = shift;
+ my $dbh = C4::Context->dbh;
+ #use constant EMAIL_ENCODE = 'iso-8859-1';
+ my $emailEncode = 'iso-8859-1';
+ my $username = GetMemberDetails($borrowernumber)->{userid};
+
+ #generate UUID
+ my @chars = ("A".."Z", "a".."z", "0".."9");
+ my $uuid_str;
+ $uuid_str .= $chars[rand @chars] for 1..32;
+
+ #insert into database
+ my $sth = $dbh->prepare( 'INSERT INTO borrower_password_recovery VALUES (? ,? , ADDDATE(NOW(), INTERVAL 2 DAY) )' );
+ $sth->execute($borrowernumber, $uuid_str);
+
+ my $userEmail = ( $email ) ? $email : GetFirstValidEmailAddress($borrowernumber);
+ #define to/from emails
+ my $kohaEmail = C4::Context->preference( 'KohaAdminEmailAddress' );
+
+ #create link
+ my $uuidLink = "http://" . C4::Context->preference( 'OPACBaseURL' ) . "/cgi-bin/koha/opac-password-recovery.pl?uniqueKey=$uuid_str";
+ #warn $uuidLink;
+
+ #build email content
+ my $query = new CGI;
+ my ( $template2, $borrower_number, $cookie ) = C4::Auth::get_template_and_user(
+ {
+ template_name => "opac-send-password-recovery.tmpl",
+ query => $query,
+ type => "opac",
+ authnotrequired => 1,
+ }
+ );
+ $template2->param(
+ uuidLink => $uuidLink,
+ username => $username,
+ );
+
+ # Getting template result and
+ my $template_res = $template2->output();
+
+ #Mail attributes
+ my %mail = (
+ To => $userEmail,
+ From => $kohaEmail,
+ 'Content-Type' => 'text/html; charset="' . $emailEncode . '"',
+ );
+
+ #getting mail properties
+ if ( $template_res =~ /(.*)/s ) { $mail{'subject'} = decode( 'utf-8', $1 ); }
+ if ( $template_res =~ /\n(.*)\n/s ) { $mail{'body'} = decode( 'utf-8', $1 ); }
+ #send mail
+ if ( sendmail %mail )
+ {
+ # if it works....
+ return 1;
+ }
+ else
+ {
+ # if it doesnt work....
+ warn "Error sending mail: $Mail::Sendmail::error \n";
+ return 0;
+ }
+}
+
+
=head2 AddMessage
AddMessage( $borrowernumber, $message_type, $message, $branchcode );
--- a/installer/data/mysql/kohastructure.sql
+++ a/installer/data/mysql/kohastructure.sql
@@ -3232,6 +3232,18 @@ CREATE TABLE IF NOT EXISTS plugin_data (
PRIMARY KEY (plugin_class,plugin_key)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+--
+-- Table structure for table 'borrower_password_recovery'
+-- this stores the unique ID sent by email to the patron, for future validation
+--
+
+CREATE TABLE IF NOT EXISTS `borrower_password_recovery` (
+ `borrowernumber` int(11) NOT NULL,
+ `uuid` varchar(128) NOT NULL,
+ `valid_until` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ KEY `borrowernumber` (`borrowernumber`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
+
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
--- a/installer/data/mysql/sysprefs.sql
+++ a/installer/data/mysql/sysprefs.sql
@@ -252,6 +252,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `
('opacreadinghistory','1','','If ON, enables display of Patron Circulation History in OPAC','YesNo'),
('OpacRenewalAllowed','0',NULL,'If ON, users can renew their issues directly from their OPAC account','YesNo'),
('OpacRenewalBranch','checkoutbranch','itemhomebranch|patronhomebranch|checkoutbranch|null','Choose how the branch for an OPAC renewal is recorded in statistics','Choice'),
+('OpacResetPassword','1','','Shows the \'Forgot your password?\' link in the OPAC','YesNo'),
('OPACResultsSidebar','','70|10','Define HTML to be included on the search results page, underneath the facets sidebar','Textarea'),
('OPACSearchForTitleIn','
','70|10','Enter the HTML that will appear in the \'Search for this title in\' box on the detail page in the OPAC. Enter {TITLE}, {AUTHOR}, or {ISBN} in place of their respective variables in the URL. Leave blank to disable \'More Searches\' menu.','Textarea'),
('OpacSeparateHoldings','0',NULL,'Separate current branch holdings from other holdings (OPAC)','YesNo'),
@@ -418,5 +419,5 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `
('XSLTResultsDisplay','default','','Enable XSL stylesheet control over results page display on intranet','Free'),
('yuipath','local','local|http://yui.yahooapis.com/2.5.1/build','Insert the path to YUI libraries, choose local if you use koha offline','Choice'),
('z3950AuthorAuthFields','701,702,700',NULL,'Define the MARC biblio fields for Personal Name Authorities to fill biblio.author','free'),
-('z3950NormalizeAuthor','0','','If ON, Personal Name Authorities will replace authors in biblio.author','YesNo')
+('z3950NormalizeAuthor','0','','If ON, Personal Name Authorities will replace authors in biblio.author','YesNo'),
;
--- a/installer/data/mysql/updatedatabase.pl
+++ a/installer/data/mysql/updatedatabase.pl
@@ -7169,6 +7169,14 @@ if ( CheckVersion($DBversion) ) {
SetVersion ($DBversion);
}
+$DBversion = "3.13.00.XXX";
+if ( CheckVersion($DBversion) ) {
+ $dbh->do("INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type)
+VALUES('OpacResetPassword','1','Shows the ''Forgot your password?'' link in the OPAC','','YesNo');");
+ print "Upgrade to $DBversion done (Bug 8753: Add forgot password link to OPAC)\n";
+ SetVersion($DBversion);
+}
+
=head1 FUNCTIONS
=head2 TableExists($table)
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref
+++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref
@@ -551,6 +551,13 @@ OPAC:
track: "Track"
no: "Don't track"
- links that patrons click on
+ -
+ - pref: OpacResetPassword
+ default: 1
+ choices:
+ yes: "On"
+ no: "Off"
+ - ". If On, the user can reset his password on OPAC."
Shelf Browser:
-
--- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-auth.tt
+++ a/koha-tmpl/opac-tmpl/prog/en/modules/opac-auth.tt
@@ -85,6 +85,9 @@ please choose against which one you would like to authenticate:
+[% IF OpacPasswordChange && OpacResetPassword %]
+
If you don't have a password yet, stop by the circulation desk the next time you're in the library. We'll happily set one up for you.
Don't have a library card?
If you don't have a library card, stop by your local library to sign up[% IF PatronSelfRegistration && PatronSelfRegistrationDefaultCategory %] or register here[% END %].
[% END %]
--- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-password-recovery.tt
+++ a/koha-tmpl/opac-tmpl/prog/en/modules/opac-password-recovery.tt
@@ -0,0 +1,129 @@
+[% INCLUDE 'doc-head-open.inc' %]
+[% IF (LibraryNameTitle) %][% LibraryNameTitle %][% ELSE %]Koha Online[% END %] Catalog ›
+[% INCLUDE 'doc-head-close.inc' %]
+
+
+
+
+
+
+
+[% INCLUDE 'masthead.inc' %]
+
+
+
+
+[% IF (!OpacResetPassword) %]
+
You can't reset your password.
+[% ELSIF (password_recovery) %]
+ [% IF (hasError) %]
+
+ [% IF (sendmailError) %]
+ An error has occured while sending you the password recovery link.
+ Please try again later.
+ [% ELSIF (errNoEmailFound) %]
+ No account was found with the email address "[% email %]"
+ Check if you typed it correctly.
+ [% ELSIF (errTooManyEmailFound) %]
+ More than one account has been found for the email address: "[% email %]"
+ Try yo use your alternative email if you have another.
+ [% ELSIF (errAlreadyStartRecovery) %]
+ The process of password recovery has already started for this account ("[% email %]")
+ Check your emails; you should recieve the link to reset your password.
+ If you didn't recieve it, click here to get a new password recovery link
+ [% END %]
+
Please contact the staff if you need further assistance.
+
+ [% END %]
+
+ We could not authentify you as the account owner.
+ Be sure to use the link you recieved in your email.
+
+ [% ELSE %]
+ [% IF (hasError) %]
+
+ [% IF (errPassNotMatch) %]
+ The passwords entered does not match.
+ Please try again.
+ [% ELSIF (errPassTooShort) %]
+ The password is too short.
+ The password must contain at least [% minPassLength %] characters.
+ [% END %]
+
+ [% END %]
+
+
+
+ [% END %]
+[% ELSIF (mail_sent) %]
+
A mail has been sent to "[% email %]".
+ It contains a link to create a new password.
+ This link will be valid for 2 days from now.