|
Lines 91-124
sub set_public {
Link Here
|
| 91 |
|
91 |
|
| 92 |
my $user = $c->stash('koha.user'); |
92 |
my $user = $c->stash('koha.user'); |
| 93 |
|
93 |
|
| 94 |
unless ( $user->borrowernumber == $patron_id ) { |
94 |
return try { |
| 95 |
return $c->render( |
95 |
$c->auth->public($patron_id); |
| 96 |
status => 403, |
|
|
| 97 |
openapi => { |
| 98 |
error => "Changing other patron's password is forbidden" |
| 99 |
} |
| 100 |
); |
| 101 |
} |
| 102 |
|
96 |
|
| 103 |
unless ( $user->category->effective_change_password ) { |
97 |
unless ( $user->category->effective_change_password ) { |
| 104 |
return $c->render( |
98 |
return $c->render( |
| 105 |
status => 403, |
99 |
status => 403, |
| 106 |
openapi => { |
100 |
openapi => { error => "Changing password is forbidden" } |
| 107 |
error => "Changing password is forbidden" |
101 |
); |
| 108 |
} |
102 |
} |
| 109 |
); |
|
|
| 110 |
} |
| 111 |
|
103 |
|
| 112 |
my $old_password = $body->{old_password}; |
104 |
my $old_password = $body->{old_password}; |
| 113 |
my $password = $body->{password}; |
105 |
my $password = $body->{password}; |
| 114 |
my $password_2 = $body->{password_repeated}; |
106 |
my $password_2 = $body->{password_repeated}; |
| 115 |
|
107 |
|
| 116 |
unless ( $password eq $password_2 ) { |
108 |
unless ( $password eq $password_2 ) { |
| 117 |
return $c->render( status => 400, openapi => { error => "Passwords don't match" } ); |
109 |
return $c->render( status => 400, openapi => { error => "Passwords don't match" } ); |
| 118 |
} |
110 |
} |
| 119 |
|
111 |
|
| 120 |
return try { |
112 |
unless ( checkpw_internal( $user->userid, $old_password ) ) { |
| 121 |
unless ( checkpw_internal($user->userid, $old_password ) ) { |
|
|
| 122 |
return $c->render( |
113 |
return $c->render( |
| 123 |
status => 400, |
114 |
status => 400, |
| 124 |
openapi => { error => "Invalid password" } |
115 |
openapi => { error => "Invalid password" } |
|
Lines 126-144
sub set_public {
Link Here
|
| 126 |
} |
117 |
} |
| 127 |
|
118 |
|
| 128 |
## Change password |
119 |
## Change password |
| 129 |
$user->set_password({ password => $password }); |
120 |
$user->set_password( { password => $password } ); |
| 130 |
|
121 |
|
| 131 |
return $c->render( status => 200, openapi => "" ); |
122 |
return $c->render( status => 200, openapi => "" ); |
| 132 |
} |
123 |
} catch { |
| 133 |
catch { |
|
|
| 134 |
if ( blessed $_ and $_->isa('Koha::Exceptions::Password') ) { |
124 |
if ( blessed $_ and $_->isa('Koha::Exceptions::Password') ) { |
| 135 |
return $c->render( |
125 |
return $c->render( |
| 136 |
status => 400, |
126 |
status => 400, |
| 137 |
openapi => { error => "$_" } |
127 |
openapi => { error => "$_" } |
| 138 |
); |
128 |
); |
|
|
129 |
} elsif ( blessed $_ and $_->isa('Koha::Exceptions::REST::Public::Unauthorized') ) { |
| 130 |
return $c->render( status => 403, json => { error => "Changing other patron's password is forbidden" } ); |
| 131 |
} else { |
| 132 |
$c->unhandled_exception($_); |
| 139 |
} |
133 |
} |
| 140 |
|
|
|
| 141 |
$c->unhandled_exception($_); |
| 142 |
}; |
134 |
}; |
| 143 |
} |
135 |
} |
| 144 |
|
136 |
|