Lines 20-25
use Koha::Token;
Link Here
|
20 |
use Koha::Patrons; |
20 |
use Koha::Patrons; |
21 |
use Koha::Patron::Categories; |
21 |
use Koha::Patron::Categories; |
22 |
|
22 |
|
|
|
23 |
use Try::Tiny; |
24 |
|
23 |
my $input = new CGI; |
25 |
my $input = new CGI; |
24 |
|
26 |
|
25 |
my $theme = $input->param('theme') || "default"; |
27 |
my $theme = $input->param('theme') || "default"; |
Lines 37-58
my ( $template, $loggedinuser, $cookie, $staffflags ) = get_template_and_user(
Link Here
|
37 |
} |
39 |
} |
38 |
); |
40 |
); |
39 |
|
41 |
|
40 |
my $member = $input->param('member'); |
42 |
my $patron_id = $input->param('member'); |
41 |
my $cardnumber = $input->param('cardnumber'); |
43 |
my $destination = $input->param('destination'); |
42 |
my $destination = $input->param('destination'); |
|
|
43 |
my $newpassword = $input->param('newpassword'); |
44 |
my $newpassword = $input->param('newpassword'); |
44 |
my $newpassword2 = $input->param('newpassword2'); |
45 |
my $newpassword2 = $input->param('newpassword2'); |
|
|
46 |
my $new_user_id = $input->param('newuserid'); |
45 |
|
47 |
|
46 |
my @errors; |
48 |
my @errors; |
47 |
|
49 |
|
48 |
my $logged_in_user = Koha::Patrons->find( $loggedinuser ) or die "Not logged in"; |
50 |
my $logged_in_user = Koha::Patrons->find( $loggedinuser ) or die "Not logged in"; |
49 |
my $patron = Koha::Patrons->find( $member ); |
51 |
my $patron = Koha::Patrons->find( $patron_id ); |
50 |
output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } ); |
52 |
output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } ); |
51 |
|
53 |
|
52 |
my $category_type = $patron->category->category_type; |
54 |
my $category_type = $patron->category->category_type; |
53 |
my $bor = $patron->unblessed; |
|
|
54 |
|
55 |
|
55 |
if ( ( $member ne $loggedinuser ) && ( $category_type eq 'S' ) ) { |
56 |
if ( ( $patron_id ne $loggedinuser ) && ( $category_type eq 'S' ) ) { |
56 |
push( @errors, 'NOPERMISSION' ) |
57 |
push( @errors, 'NOPERMISSION' ) |
57 |
unless ( $staffflags->{'superlibrarian'} || $staffflags->{'staffaccess'} ); |
58 |
unless ( $staffflags->{'superlibrarian'} || $staffflags->{'staffaccess'} ); |
58 |
|
59 |
|
Lines 61-75
if ( ( $member ne $loggedinuser ) && ( $category_type eq 'S' ) ) {
Link Here
|
61 |
|
62 |
|
62 |
push( @errors, 'NOMATCH' ) if ( ( $newpassword && $newpassword2 ) && ( $newpassword ne $newpassword2 ) ); |
63 |
push( @errors, 'NOMATCH' ) if ( ( $newpassword && $newpassword2 ) && ( $newpassword ne $newpassword2 ) ); |
63 |
|
64 |
|
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'; |
70 |
} |
71 |
} |
72 |
|
73 |
if ( $newpassword and not @errors) { |
65 |
if ( $newpassword and not @errors) { |
74 |
|
66 |
|
75 |
die "Wrong CSRF token" |
67 |
die "Wrong CSRF token" |
Lines 78-102
if ( $newpassword and not @errors) {
Link Here
|
78 |
token => scalar $input->param('csrf_token'), |
70 |
token => scalar $input->param('csrf_token'), |
79 |
}); |
71 |
}); |
80 |
|
72 |
|
81 |
my $uid = $input->param('newuserid') || $bor->{userid}; |
73 |
try { |
82 |
my $password = $input->param('newpassword'); |
74 |
$patron->set_password({ password => $newpassword }); |
83 |
my $dbh = C4::Context->dbh; |
75 |
$patron->userid($new_user_id)->store |
84 |
if ( Koha::Patrons->find( $member )->update_password($uid, $password) ) { |
76 |
if $new_user_id and $new_user_id ne $patron->userid; |
85 |
$template->param( newpassword => $newpassword ); |
77 |
$template->param( newpassword => $newpassword ); |
86 |
if ( $destination eq 'circ' ) { |
78 |
if ( $destination eq 'circ' ) { |
87 |
print $input->redirect("/cgi-bin/koha/circ/circulation.pl?findborrower=$cardnumber"); |
79 |
print $input->redirect("/cgi-bin/koha/circ/circulation.pl?findborrower=" . $patron->cardnumber); |
88 |
} |
80 |
} |
89 |
else { |
81 |
else { |
90 |
print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$member"); |
82 |
print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$patron_id"); |
91 |
} |
83 |
} |
92 |
} |
84 |
} |
93 |
else { |
85 |
catch { |
94 |
push( @errors, 'BADUSERID' ); |
86 |
if ( $_->isa('Koha::Exceptions::Password::TooShort') ) { |
95 |
} |
87 |
push @errors, 'ERROR_password_too_short'; |
|
|
88 |
} |
89 |
elsif ( $_->isa('Koha::Exceptions::Password::WhitespaceCharacters') ) { |
90 |
push @errors, 'ERROR_password_has_whitespaces'; |
91 |
} |
92 |
elsif ( $_->isa('Koha::Exceptions::Password::TooWeak') ) { |
93 |
push @errors, 'ERROR_password_too_weak'; |
94 |
} |
95 |
else { |
96 |
push( @errors, 'BADUSERID' ); |
97 |
} |
98 |
}; |
96 |
} |
99 |
} |
97 |
|
100 |
|
98 |
if ( C4::Context->preference('ExtendedPatronAttributes') ) { |
101 |
if ( C4::Context->preference('ExtendedPatronAttributes') ) { |
99 |
my $attributes = GetBorrowerAttributes( $bor->{'borrowernumber'} ); |
102 |
my $attributes = GetBorrowerAttributes( $patron_id ); |
100 |
$template->param( |
103 |
$template->param( |
101 |
ExtendedPatronAttributes => 1, |
104 |
ExtendedPatronAttributes => 1, |
102 |
extendedattributes => $attributes |
105 |
extendedattributes => $attributes |
Lines 104-112
if ( C4::Context->preference('ExtendedPatronAttributes') ) {
Link Here
|
104 |
} |
107 |
} |
105 |
|
108 |
|
106 |
$template->param( |
109 |
$template->param( |
107 |
patron => $patron, |
110 |
patron => $patron, |
108 |
destination => $destination, |
111 |
destination => $destination, |
109 |
csrf_token => Koha::Token->new->generate_csrf({ session_id => scalar $input->cookie('CGISESSID'), }), |
112 |
csrf_token => Koha::Token->new->generate_csrf({ session_id => scalar $input->cookie('CGISESSID'), }), |
110 |
); |
113 |
); |
111 |
|
114 |
|
112 |
if ( scalar(@errors) ) { |
115 |
if ( scalar(@errors) ) { |
113 |
- |
|
|