Bug 22048: Use set_password opac/opac-password-recovery.pl
authorTomas Cohen Arazi <tomascohen@theke.io>
Thu, 13 Dec 2018 15:56:42 +0000 (12:56 -0300)
committerNick Clemens <nick@bywatersolutions.com>
Fri, 25 Jan 2019 20:15:31 +0000 (20:15 +0000)
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

opac/opac-password-recovery.pl

index 2b39e52..6429f7b 100755 (executable)
@@ -146,19 +146,26 @@ elsif ( $query->param('passwordReset') ) {
     } elsif ( $password ne $repeatPassword ) {
         $error = 'errPassNotMatch';
     } else {
-        my ( $is_valid, $err) = Koha::AuthUtils::is_password_valid( $password );
-        unless ( $is_valid ) {
-            $error = 'password_too_short' if $err eq 'too_short';
-            $error = 'password_too_weak' if $err eq 'too_weak';
-            $error = 'password_has_whitespaces' if $err eq 'has_whitespaces';
-        } else {
-            Koha::Patrons->find($borrower_number)->update_password( $username, $password );
+        try {
+            Koha::Patrons->find($borrower_number)->set_password({ password => $password });
+
             CompletePasswordRecovery($uniqueKey);
             $template->param(
                 password_reset_done => 1,
                 username            => $username
             );
         }
+        catch {
+            if ( $_->isa('Koha::Exceptions::Password::TooShort') ) {
+                $error = 'password_too_short';
+            }
+            elsif ( $_->isa('Koha::Exceptions::Password::WhitespaceCharacters') ) {
+                $error = 'password_has_whitespaces';
+            }
+            elsif ( $_->isa('Koha::Exceptions::Password::TooWeak') ) {
+                $error = 'password_too_weak';
+            }
+        };
     }
     if ( $error ) {
         $template->param(