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
9 use C4::Auth qw( get_template_and_user );
10 use C4::Output qw( output_and_exit_if_error output_and_exit output_html_with_http_headers );
15 use Koha::Patron::Categories;
17 use Try::Tiny qw( catch try );
21 my $theme = $input->param('theme') || "default";
23 # only used if allowthemeoverride is set
25 my ( $template, $loggedinuser, $cookie, $staffflags ) = get_template_and_user(
27 template_name => "members/member-password.tt",
30 flagsrequired => { borrowers => 'edit_borrowers' },
34 my $op = $input->param('op') // q{};
35 my $patron_id = $input->param('member');
36 my $destination = $input->param('destination');
37 my $newpassword = $input->param('newpassword');
38 my $newpassword2 = $input->param('newpassword2');
39 my $new_user_id = $input->param('newuserid');
43 my $logged_in_user = Koha::Patrons->find( $loggedinuser );
44 my $patron = Koha::Patrons->find( $patron_id );
45 output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } );
47 my $category_type = $patron->category->category_type;
49 if ( ( $patron_id ne $loggedinuser ) && ( $category_type eq 'S' ) ) {
50 push( @errors, 'NOPERMISSION' )
51 unless ( $staffflags->{'superlibrarian'} || $staffflags->{'staffaccess'} );
53 # need superlibrarian for koha-conf.xml fakeuser.
56 push( @errors, 'NOMATCH' ) if ( ( $newpassword && $newpassword2 ) && ( $newpassword ne $newpassword2 ) );
58 if ( $op eq 'cud-update' && defined($newpassword) and not @errors ) {
61 if ( $newpassword ne '' ) {
62 $patron->set_password({ password => $newpassword });
63 $template->param( newpassword => $newpassword );
65 $patron->userid($new_user_id)->store
66 if $new_user_id and $new_user_id ne $patron->userid;
67 if ( $destination eq 'circ' ) {
68 print $input->redirect("/cgi-bin/koha/circ/circulation.pl?findborrower=" . $patron->cardnumber);
71 print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$patron_id");
75 if ( $_->isa('Koha::Exceptions::Password::TooShort') ) {
76 push @errors, 'ERROR_password_too_short';
78 elsif ( $_->isa('Koha::Exceptions::Password::WhitespaceCharacters') ) {
79 push @errors, 'ERROR_password_has_whitespaces';
81 elsif ( $_->isa('Koha::Exceptions::Password::TooWeak') ) {
82 push @errors, 'ERROR_password_too_weak';
84 elsif ( $_->isa('Koha::Exceptions::Password::Plugin') ) {
85 push @errors, 'ERROR_from_plugin';
88 push( @errors, 'BADUSERID' );
95 destination => $destination,
98 if ( scalar(@errors) ) {
99 $template->param( errormsg => 1 );
100 foreach my $error (@errors) {
101 $template->param($error) || $template->param( $error => 1 );
105 output_html_with_http_headers $input, $cookie, $template->output;