use CGI qw ( -utf8 );
-use C4::Auth; # checkauth, getborrowernumber.
+use C4::Auth qw( get_template_and_user checkpw checkpw_hash );
use C4::Context;
-use Digest::MD5 qw(md5_base64);
-use C4::Circulation;
-use C4::Members;
-use C4::Output;
-use Koha::AuthUtils qw(hash_password);
+use C4::Output qw( output_html_with_http_headers );
use Koha::Patrons;
-my $query = new CGI;
-my $dbh = C4::Context->dbh;
+use Try::Tiny qw( catch try );
+
+my $query = CGI->new;
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
{
template_name => "opac-passwd.tt",
query => $query,
type => "opac",
- authnotrequired => 0,
- debug => 1,
}
);
my $patron = Koha::Patrons->find( $borrowernumber );
-if ( C4::Context->preference("OpacPasswordChange") ) {
+if ( $patron->category->effective_change_password ) {
if ( $query->param('Oldkey')
&& $query->param('Newkey')
&& $query->param('Confirm') )
$template->param( 'Error_messages' => '1' );
$template->param( 'passwords_mismatch' => '1' );
} else {
- my ( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( $new_password );
- unless ( $is_valid ) {
- $error = 'password_too_short' if $error eq 'too_short';
- $error = 'password_too_weak' if $error eq 'too_weak';
- $error = 'password_has_whitespaces' if $error eq 'has_whitespaces';
- } else {
- # Password is valid and match
- $patron->set_password( $new_password );
+ try {
+ $patron->set_password({ password => $new_password });
$template->param( 'password_updated' => '1' );
$template->param( 'borrowernumber' => $borrowernumber );
}
+ catch {
+ $error = 'password_too_short'
+ if $_->isa('Koha::Exceptions::Password::TooShort');
+ $error = 'password_too_weak'
+ if $_->isa('Koha::Exceptions::Password::TooWeak');
+ $error = 'password_has_whitespaces'
+ if $_->isa('Koha::Exceptions::Password::WhitespaceCharacters');
+ };
}
}
else {