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
16 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 if ( $newpassword and not @errors ) {
70 my ( $is_valid, $error ) = Koha
::AuthUtils
::is_password_valid
( $newpassword );
71 unless ( $is_valid ) {
72 push @errors, 'ERROR_password_too_short' if $error eq 'too_short';
73 push @errors, 'ERROR_password_too_weak' if $error eq 'too_weak';
74 push @errors, 'ERROR_password_has_whitespaces' if $error eq 'has_whitespaces';
78 if ( $newpassword and not @errors) {
80 die "Wrong CSRF token"
81 unless Koha
::Token
->new->check_csrf({
82 session_id
=> scalar $input->cookie('CGISESSID'),
83 token
=> scalar $input->param('csrf_token'),
86 my $digest = Koha
::AuthUtils
::hash_password
( scalar $input->param('newpassword') );
87 my $uid = $input->param('newuserid') || $bor->{userid
};
88 my $dbh = C4
::Context
->dbh;
89 if ( Koha
::Patrons
->find( $member )->update_password($uid, $digest) ) {
90 $template->param( newpassword
=> $newpassword );
91 if ( $destination eq 'circ' ) {
92 print $input->redirect("/cgi-bin/koha/circ/circulation.pl?findborrower=$cardnumber");
95 print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member");
99 push( @errors, 'BADUSERID' );
103 if ( $category_type eq 'C') {
104 my $patron_categories = Koha
::Patron
::Categories
->search_limited({ category_type
=> 'A' }, {order_by
=> ['categorycode']});
105 $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
106 $template->param( 'catcode' => $patron_categories->next->categorycode ) if $patron_categories->count == 1;
109 $template->param( adultborrower
=> 1 ) if ( $category_type =~ /^(A|I)$/ );
111 $template->param( picture
=> 1 ) if $patron->image;
113 if ( C4
::Context
->preference('ExtendedPatronAttributes') ) {
114 my $attributes = GetBorrowerAttributes
( $bor->{'borrowernumber'} );
116 ExtendedPatronAttributes
=> 1,
117 extendedattributes
=> $attributes
122 othernames
=> $bor->{'othernames'},
123 surname
=> $bor->{'surname'},
124 firstname
=> $bor->{'firstname'},
125 borrowernumber
=> $bor->{'borrowernumber'},
126 cardnumber
=> $bor->{'cardnumber'},
127 categorycode
=> $bor->{'categorycode'},
128 category_type
=> $category_type,
129 categoryname
=> $bor->{'description'},
130 address
=> $bor->{address
},
131 address2
=> $bor->{'address2'},
132 streettype
=> $bor->{streettype
},
133 city
=> $bor->{'city'},
134 state => $bor->{'state'},
135 zipcode
=> $bor->{'zipcode'},
136 country
=> $bor->{'country'},
137 phone
=> $bor->{'phone'},
138 phonepro
=> $bor->{'phonepro'},
139 streetnumber
=> $bor->{'streetnumber'},
140 mobile
=> $bor->{'mobile'},
141 email
=> $bor->{'email'},
142 emailpro
=> $bor->{'emailpro'},
143 branchcode
=> $bor->{'branchcode'},
144 userid
=> $bor->{'userid'},
145 destination
=> $destination,
146 is_child
=> ( $category_type eq 'C' ),
147 csrf_token
=> Koha
::Token
->new->generate_csrf({ session_id
=> scalar $input->cookie('CGISESSID'), }),
150 if ( scalar(@errors) ) {
151 $template->param( errormsg
=> 1 );
152 foreach my $error (@errors) {
153 $template->param($error) || $template->param( $error => 1 );
157 output_html_with_http_headers
$input, $cookie, $template->output;