2 #script to set the password, and optionally a userid, for a borrower
5 #converted to using templates 3/16/03 by mwhansen@hmc.edu
10 use C4::Interface::CGI::Output;
13 use C4::Circulation::Circ2;
16 use Digest::MD5 qw(md5_base64);
20 my $theme = $input->param('theme') || "default";
21 # only used if allowthemeoverride is set
23 my ($template, $loggedinuser, $cookie)
24 = get_template_and_user({template_name => "members/member-password.tmpl",
28 flagsrequired => {borrowers => 1},
33 $flagsrequired->{borrowers}=1;
34 my ($loggedinuser, $cookie, $sessionID) = checkauth($input, 0, $flagsrequired);
36 my $member=$input->param('member');
38 $env{'nottodayissues'}=1;
40 $member2{'borrowernumber'}=$member;
41 my $issues=currentissues(\%env,\%member2);
43 foreach (sort keys %$issues) {
47 my ($bor,$flags)=getpatroninformation(\%env, $member,'');
48 my $newpassword = $input->param('newpassword');
51 my $digest=md5_base64($input->param('newpassword'));
52 my $uid = $input->param('newuserid');
53 my $dbh=C4::Context->dbh;
55 if ($uid eq '') { $uid = $bor->{'userid'} }
56 #Make sure the userid chosen is unique and not theirs. If it is not,
57 #Then we need to tell the user and have them create a new one.
58 my $sth2=$dbh->prepare("select * from borrowers where userid=? and borrowernumber != ?");
59 $sth2->execute($uid,$member);
61 if ( $sth2->fetchrow ) {
62 #The userid exists so we should display a warning.
64 $template->param( warn => $warn,
65 othernames => $bor->{'othernames'},
66 surname => $bor->{'surname'},
67 firstname => $bor->{'firstname'},
68 userid => $bor->{'userid'},
69 defaultnewpassword => $newpassword );
71 #Everything is good so we can update the information.
72 my $sth=$dbh->prepare("update borrowers set userid=?, password=? where borrowernumber=?");
73 $sth->execute($uid, $digest, $member);
74 $template->param(newpassword => $newpassword);
78 my $userid = $bor->{'userid'};
80 my $chars='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
81 my $length=int(rand(2))+4;
82 my $defaultnewpassword='';
83 for (my $i=0; $i<$length; $i++) {
84 $defaultnewpassword.=substr($chars, int(rand(length($chars))),1);
86 $template->param( othernames => $bor->{'othernames'},
87 surname => $bor->{'surname'},
88 firstname => $bor->{'firstname'},
89 userid => $bor->{'userid'},
90 defaultnewpassword => $defaultnewpassword );
95 $template->param( member => $member );
97 output_html_with_http_headers $input, $cookie, $template->output;