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
17 use C4::Members::Attributes qw(GetBorrowerAttributes);
21 use Koha::Patron::Categories;
25 my $theme = $input->param('theme') || "default";
27 # only used if allowthemeoverride is set
29 my ( $template, $loggedinuser, $cookie, $staffflags ) = get_template_and_user(
31 template_name => "members/member-password.tt",
35 flagsrequired => { borrowers => 1 },
41 $flagsrequired->{borrowers} = 1;
43 my $member = $input->param('member');
44 my $cardnumber = $input->param('cardnumber');
45 my $destination = $input->param('destination');
46 my $newpassword = $input->param('newpassword');
47 my $newpassword2 = $input->param('newpassword2');
51 my $patron = Koha::Patrons->find( $member );
53 print $input->redirect("/cgi-bin/koha/circ/circulation.pl?borrowernumber=$member");
57 my $category_type = $patron->category->category_type;
58 my $bor = $patron->unblessed;
60 if ( ( $member ne $loggedinuser ) && ( $category_type eq 'S' ) ) {
61 push( @errors, 'NOPERMISSION' )
62 unless ( $staffflags->{'superlibrarian'} || $staffflags->{'staffaccess'} );
64 # need superlibrarian for koha-conf.xml fakeuser.
67 push( @errors, 'NOMATCH' ) if ( ( $newpassword && $newpassword2 ) && ( $newpassword ne $newpassword2 ) );
69 my $minpw = C4::Context->preference('minPasswordLength');
70 $minpw = 3 if not $minpw or $minpw < 3;
71 push( @errors, 'SHORTPASSWORD' ) if ( $newpassword && $minpw && ( length($newpassword) < $minpw ) );
73 if ( $newpassword && !scalar(@errors) ) {
75 die "Wrong CSRF token"
76 unless Koha::Token->new->check_csrf({
77 session_id => scalar $input->cookie('CGISESSID'),
78 token => scalar $input->param('csrf_token'),
81 my $digest = Koha::AuthUtils::hash_password( scalar $input->param('newpassword') );
82 my $uid = $input->param('newuserid') || $bor->{userid};
83 my $dbh = C4::Context->dbh;
84 if ( Koha::Patrons->find( $member )->update_password($uid, $digest) ) {
85 $template->param( newpassword => $newpassword );
86 if ( $destination eq 'circ' ) {
87 print $input->redirect("/cgi-bin/koha/circ/circulation.pl?findborrower=$cardnumber");
90 print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member");
94 push( @errors, 'BADUSERID' );
98 if ( $category_type eq 'C') {
99 my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
100 $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
101 $template->param( 'catcode' => $patron_categories->next ) if $patron_categories->count == 1;
104 $template->param( adultborrower => 1 ) if ( $category_type =~ /^(A|I)$/ );
106 $template->param( picture => 1 ) if $patron->image;
108 if ( C4::Context->preference('ExtendedPatronAttributes') ) {
109 my $attributes = GetBorrowerAttributes( $bor->{'borrowernumber'} );
111 ExtendedPatronAttributes => 1,
112 extendedattributes => $attributes
117 othernames => $bor->{'othernames'},
118 surname => $bor->{'surname'},
119 firstname => $bor->{'firstname'},
120 borrowernumber => $bor->{'borrowernumber'},
121 cardnumber => $bor->{'cardnumber'},
122 categorycode => $bor->{'categorycode'},
123 category_type => $category_type,
124 categoryname => $bor->{'description'},
125 address => $bor->{address},
126 address2 => $bor->{'address2'},
127 streettype => $bor->{streettype},
128 city => $bor->{'city'},
129 state => $bor->{'state'},
130 zipcode => $bor->{'zipcode'},
131 country => $bor->{'country'},
132 phone => $bor->{'phone'},
133 phonepro => $bor->{'phonepro'},
134 streetnumber => $bor->{'streetnumber'},
135 mobile => $bor->{'mobile'},
136 email => $bor->{'email'},
137 emailpro => $bor->{'emailpro'},
138 branchcode => $bor->{'branchcode'},
139 userid => $bor->{'userid'},
140 destination => $destination,
141 is_child => ( $category_type eq 'C' ),
142 minPasswordLength => $minpw,
143 RoutingSerials => C4::Context->preference('RoutingSerials'),
144 csrf_token => Koha::Token->new->generate_csrf({ session_id => scalar $input->cookie('CGISESSID'), }),
147 if ( scalar(@errors) ) {
148 $template->param( errormsg => 1 );
149 foreach my $error (@errors) {
150 $template->param($error) || $template->param( $error => 1 );
154 output_html_with_http_headers $input, $cookie, $template->output;