Bug 13515: DBRev 18.12.00.014
[koha.git] / installer / onboarding.pl
index 8b032c9..1acc420 100755 (executable)
@@ -22,15 +22,14 @@ use C4::Context;
 use C4::InstallAuth;
 use CGI qw ( -utf8 );
 use C4::Output;
-use C4::Members;
+use C4::Members qw(checkcardnumber);
 use Koha::Patrons;
 use Koha::Libraries;
 use Koha::Database;
 use Koha::DateUtils;
+use Koha::Patrons;
 use Koha::Patron::Categories;
-use Koha::Patron::Category;
 use Koha::ItemTypes;
-use Koha::IssuingRule;
 use Koha::IssuingRules;
 
 #Setting variables
@@ -146,6 +145,8 @@ if ( $step == 3 ) {
         my $cardnumber     = $input->param('cardnumber');
         my $userid         = $input->param('userid');
 
+        my ( $is_valid, $passworderror) = Koha::AuthUtils::is_password_valid( $firstpassword );
+
         if ( my $error_code = checkcardnumber($cardnumber) ) {
             if ( $error_code == 1 ) {
                 push @messages, { code => 'ERROR_cardnumber_already_exists' };
@@ -158,8 +159,13 @@ if ( $step == 3 ) {
 
             push @messages, { code => 'ERROR_password_mismatch' };
         }
-        else {
+        elsif ( $passworderror) {
+                push @messages, { code => 'ERROR_password_too_short'} if $passworderror eq 'too_short';
+                push @messages, { code => 'ERROR_password_too_weak'} if $passworderror eq 'too_weak';
+                push @messages, { code => 'ERROR_password_has_whitespaces'} if $passworderror eq 'has_whitespaces';
 
+        }
+        else {
             my $patron_data = {
                 surname      => scalar $input->param('surname'),
                 firstname    => scalar $input->param('firstname'),
@@ -167,12 +173,10 @@ if ( $step == 3 ) {
                 branchcode   => scalar $input->param('libraries'),
                 categorycode => scalar $input->param('categorycode_entry'),
                 userid       => scalar $input->param('userid'),
-                password     => scalar $input->param('password'),
-                password2    => scalar $input->param('password2'),
                 privacy      => "default",
                 address      => "",
                 city         => "",
-                flags => 1,    # Will be superlibrarian
+                flags        => 1,    # Will be superlibrarian
             };
 
             my $patron_category =
@@ -180,13 +184,17 @@ if ( $step == 3 ) {
             $patron_data->{dateexpiry} =
               $patron_category->get_expiry_date( $patron_data->{dateenrolled} );
 
-            my $borrowernumber = C4::Members::AddMember(%$patron_data);
+            eval {
+                my $patron = Koha::Patron->new($patron_data)->store;
+                $patron->set_password({ password =>  $firstpassword });
+            };
 
             #Error handling checking if the patron was created successfully
-            if ($borrowernumber) {
+            unless ($@) {
                 push @messages, { code => 'success_on_insert_patron' };
             }
             else {
+                warn $@;
                 push @messages, { code => 'error_on_insert_patron' };
             }
         }
@@ -267,22 +275,6 @@ if ( $step == 5 ) {
 
 my $libraries = Koha::Libraries->search( {}, { order_by => ['branchcode'] }, );
 $template_params->{libraries}   = $libraries;
-$template_params->{group_types} = [
-    {
-        categorytype => 'searchdomain',
-        categories   => [
-            Koha::LibraryCategories->search(
-                { categorytype => 'searchdomain' }
-            )
-        ],
-    },
-    {
-        categorytype => 'properties',
-        categories   => [
-            Koha::LibraryCategories->search( { categorytype => 'properties' } )
-        ],
-    },
-];
 
 if ( $step > 5 ) {
     $template_params->{all_done} = 1;    # If step 5 is complete, we are done!