From 1edf59efe57c9e5cb158a9fe3958501bb05dee7c Mon Sep 17 00:00:00 2001 From: tipaul Date: Thu, 2 Sep 2004 16:27:09 +0000 Subject: [PATCH] road to a better member management code. Useful for LDAP integration --- C4/Members.pm | 33 +++++++++++++++++++++++++-------- members/member-password.pl | 33 +++++++++++---------------------- 2 files changed, 36 insertions(+), 30 deletions(-) diff --git a/C4/Members.pm b/C4/Members.pm index 37ace296b5..053b0f146d 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -49,7 +49,7 @@ C4::Members - Perl Module containing convenience functions for member handling @EXPORT = qw(); @EXPORT = qw( - &fixup_cardnumber &findguarantees &modmember &newmember + &fixup_cardnumber &findguarantees &modmember &newmember &changepassword ); @@ -105,16 +105,33 @@ sub newmember { $sth->execute; $sth->finish; $data{borrowernumber} =$dbh->{'mysql_insertid'}; - # ok if its an adult (type) it may have borrowers that depend on it as a guarantor - # so when we update information for an adult we should check for guarantees and update the relevant part - # of their records, ie addresses and phone numbers - if ($data{'categorycode'} eq 'A' || $data{'categorycode'} eq 'W'){ - # is adult check guarantees; - updateguarantees(%data); - } return $data{borrowernumber}; } +sub changepassword { + my ($uid,$member,$digest) = @_; + my $dbh = C4::Context->dbh; + #Make sure the userid chosen is unique and not theirs if non-empty. If it is not, + #Then we need to tell the user and have them create a new one. + my $sth=$dbh->prepare("select * from borrowers where userid=? and borrowernumber != ?"); + $sth->execute($uid,$member); + if ( ($uid ne '') && ($sth->fetchrow) ) { + return 0; + } else { + #Everything is good so we can update the information. + $sth=$dbh->prepare("update borrowers set userid=?, password=? where borrowernumber=?"); + $sth->execute($uid, $digest, $member); + return 1; + } +} + +sub getmemberfromuserid { + my ($userid) = @_; + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare("select * from borrowers where userid=?"); + $sth->execute($userid); + return $sth->fetchrow_hashref; +} sub updateguarantees { my (%data) = @_; my $dbh = C4::Context->dbh; diff --git a/members/member-password.pl b/members/member-password.pl index 942dc9e03b..a5251493c3 100755 --- a/members/member-password.pl +++ b/members/member-password.pl @@ -10,6 +10,7 @@ use C4::Output; use C4::Interface::CGI::Output; use C4::Search; use C4::Context; +use C4::Members; use C4::Circulation::Circ2; use CGI; use HTML::Template; @@ -48,30 +49,18 @@ my ($bor,$flags)=getpatroninformation(\%env, $member,''); my $newpassword = $input->param('newpassword'); if ( $newpassword ) { - my $digest=md5_base64($input->param('newpassword')); - my $uid = $input->param('newuserid'); - my $dbh=C4::Context->dbh; - - #Make sure the userid chosen is unique and not theirs if non-empty. If it is not, - #Then we need to tell the user and have them create a new one. - my $sth2=$dbh->prepare("select * from borrowers where userid=? and borrowernumber != ?"); - $sth2->execute($uid,$member); - - if ( ($uid ne '') && ($sth2->fetchrow) ) { - #The userid exists so we should display a warning. - my $warn = 1; - $template->param( warn => $warn, - othernames => $bor->{'othernames'}, - surname => $bor->{'surname'}, - firstname => $bor->{'firstname'}, - userid => $bor->{'userid'}, - defaultnewpassword => $newpassword ); - } else { - #Everything is good so we can update the information. - my $sth=$dbh->prepare("update borrowers set userid=?, password=? where borrowernumber=?"); - $sth->execute($uid, $digest, $member); + my $digest=md5_base64($input->param('newpassword')); + my $uid = $input->param('newuserid'); + my $dbh=C4::Context->dbh; + if (changepassword($uid,$member,$digest)) { $template->param(newpassword => $newpassword); print $input->redirect("/cgi-bin/koha/members/moremember.pl?bornum=$member"); + } else { + $template->param(othernames => $bor->{'othernames'}, + surname => $bor->{'surname'}, + firstname => $bor->{'firstname'}, + userid => $bor->{'userid'}, + defaultnewpassword => $newpassword ); } } else { my $userid = $bor->{'userid'}; -- 2.39.5