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
=> 'edit_borrowers' },
40 my $member = $input->param('member');
41 my $cardnumber = $input->param('cardnumber');
42 my $destination = $input->param('destination');
43 my $newpassword = $input->param('newpassword');
44 my $newpassword2 = $input->param('newpassword2');
48 my $logged_in_user = Koha
::Patrons
->find( $loggedinuser ) or die "Not logged in";
49 my $patron = Koha
::Patrons
->find( $member );
50 output_and_exit_if_error
( $input, $cookie, $template, { module
=> 'members', logged_in_user
=> $logged_in_user, current_patron
=> $patron } );
52 my $category_type = $patron->category->category_type;
53 my $bor = $patron->unblessed;
55 if ( ( $member ne $loggedinuser ) && ( $category_type eq 'S' ) ) {
56 push( @errors, 'NOPERMISSION' )
57 unless ( $staffflags->{'superlibrarian'} || $staffflags->{'staffaccess'} );
59 # need superlibrarian for koha-conf.xml fakeuser.
62 push( @errors, 'NOMATCH' ) if ( ( $newpassword && $newpassword2 ) && ( $newpassword ne $newpassword2 ) );
64 if ( $newpassword and not @errors ) {
65 my ( $is_valid, $error ) = Koha
::AuthUtils
::is_password_valid
( $newpassword );
66 unless ( $is_valid ) {
67 push @errors, 'ERROR_password_too_short' if $error eq 'too_short';
68 push @errors, 'ERROR_password_too_weak' if $error eq 'too_weak';
69 push @errors, 'ERROR_password_has_whitespaces' if $error eq 'has_whitespaces';
73 if ( $newpassword and not @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 $uid = $input->param('newuserid') || $bor->{userid
};
82 my $password = $input->param('newpassword');
83 my $dbh = C4
::Context
->dbh;
84 if ( Koha
::Patrons
->find( $member )->update_password($uid, $password) ) {
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 ( $patron->is_child ) {
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->categorycode ) if $patron_categories->count == 1;
104 if ( C4
::Context
->preference('ExtendedPatronAttributes') ) {
105 my $attributes = GetBorrowerAttributes
( $bor->{'borrowernumber'} );
107 ExtendedPatronAttributes
=> 1,
108 extendedattributes
=> $attributes
114 destination
=> $destination,
115 csrf_token
=> Koha
::Token
->new->generate_csrf({ session_id
=> scalar $input->cookie('CGISESSID'), }),
118 if ( scalar(@errors) ) {
119 $template->param( errormsg
=> 1 );
120 foreach my $error (@errors) {
121 $template->param($error) || $template->param( $error => 1 );
125 output_html_with_http_headers
$input, $cookie, $template->output;