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 ( C4
::Context
->preference('ExtendedPatronAttributes') ) {
99 my $attributes = GetBorrowerAttributes
( $bor->{'borrowernumber'} );
101 ExtendedPatronAttributes
=> 1,
102 extendedattributes
=> $attributes
108 destination
=> $destination,
109 csrf_token
=> Koha
::Token
->new->generate_csrf({ session_id
=> scalar $input->cookie('CGISESSID'), }),
112 if ( scalar(@errors) ) {
113 $template->param( errormsg
=> 1 );
114 foreach my $error (@errors) {
115 $template->param($error) || $template->param( $error => 1 );
119 output_html_with_http_headers
$input, $cookie, $template->output;