road to a better member management code.
authortipaul <tipaul>
Thu, 2 Sep 2004 16:27:09 +0000 (16:27 +0000)
committertipaul <tipaul>
Thu, 2 Sep 2004 16:27:09 +0000 (16:27 +0000)
Useful for LDAP integration

C4/Members.pm
members/member-password.pl

index 37ace29..053b0f1 100644 (file)
@@ -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;
index 942dc9e..a525149 100755 (executable)
@@ -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'};