From 3509f3ef0f0cfb86c963112976c51cb954447906 Mon Sep 17 00:00:00 2001
From: Alex Buckley
Date: Thu, 22 Dec 2016 21:00:21 +0000
Subject: [PATCH] Bug 17855 - Implemented minimum password length check, which
will not allow a user to create a patron in the create patron screen of the
onboarding tool if the patrons password is less than 3 characters.
Test plan:
1. Go through the web installer and onboarding tool (up
to the first create patron screen) as outlined here:
https://koha-community.org/manual/installation/html/
2. In the first create patron screen write in the same 2 character
password into the 'Password' and 'Confirm Password' text inputs
and submit the form
3. Notice that there is an error message telling you the password is
too short
Bug 17855 - Implemented properly formatted errors
to be shown after submitting the first create patron screen in the
onboarding tool if the inputted passwords do not match
and/or the inputted card number already exists.
This prevents a software error being displayed to the
user.
Test plan:
1. Go through the web installer (keeping the MACR21 and basic setup
default options selected)
2. Select to install sample libraries, patron categories and patrons
in the web installer step 3
3. Finish the remainder of the web installer as outlined in the above
link
4. Go through the onboarding tool noticing that the forms to create a
library, and patron category are skipped (with a skip message being
displayed in their place).
5. On the create patron screen enter in the card number of 1 (which
already exists because you added sample patrons in the web installer)
and write in different passwords into the 'Password' and 'Confirm
password' input fields.
6. Submit the Create patron form
7. Notice the error messages in a properly formatted onboarding tool
screen. I.e. not software error messages. Click the 'Try again' button
which returns you to the create patron screen to refill out the
form again
Bug 17855 - removed test displays of
template variables in the second create patron screen
of the onboarding tool
Test plan:
1. Go through the web installer and onboarding tool
(up to the second create patron screen) as outlined here:
https://koha-community.org/manual/installation/html/
2. Notice that there is no text saying 'nok is ' at the
top of the second create patron screen
Bug 17855 - Implemented html validation
on the text input boxes for the create
library screen in the onboarding
tool.
Test plan:
1. Go through the web installer and up to the
create a library screen of the onboarding tool
as outlined here:
https://koha-community.org/manual/installation/html/
2. In the onboarding tool enter special
characters into the two text input boxes of the
create library screen and try to submit the form.
3. Notice that the form will not
submit until the special characters have been removed from
the two text input fields
Bug 17855 - Implemented a password check
into the create patron screen so that
when the user writes the patron password into
the 'Password' and 'Confirm password' input
boxes the password inputs are checked to make
sure they are consistent.
If the passwords are not the same then the patron record is
not inserted into the datbase.
Test plan:
1. Go through the web installer and onboarding tool
(up to the first create a patron screen) as outlined here:
https://koha-community.org/manual/installation/html/
2. Enter in a different password in the 'Confirm Password' input
to the 'Password' input.
3. Notice that the patron record is not instered into the borrowers
table of the database when the passwords are not the same.
HTML data validation of the library
Trying to work out errors
Working errors for password mismatch
Password min length check is working for create a patron. Still need to fix user ID check and test if card number length is working. FOr now, Mika out!
---
installer/onboarding.pl | 234 ++++++++++++---------
.../prog/en/modules/installer/step3.tt | 4 +-
.../prog/en/modules/onboarding/onboardingstep1.tt | 6 +-
.../prog/en/modules/onboarding/onboardingstep2.tt | 19 +-
.../prog/en/modules/onboarding/onboardingstep3.tt | 141 +++++++++----
5 files changed, 249 insertions(+), 155 deletions(-)
diff --git a/installer/onboarding.pl b/installer/onboarding.pl
index 5435db5..eab874b 100755
--- a/installer/onboarding.pl
+++ b/installer/onboarding.pl
@@ -4,11 +4,8 @@ use strict;
use warnings;
use diagnostics;
-
use Modern::Perl;
- use C4::InstallAuth;
-
-#External modules
+use C4::InstallAuth;
use CGI qw ( -utf8 );
use List::MoreUtils qw/uniq/;
use Digest::MD5 qw(md5_base64);
@@ -44,10 +41,6 @@ use Module::Load;
use Koha::IssuingRule;
use Koha::IssuingRules;
-
-
-
-
#Setting variables
my $input = new CGI;
my $query = new CGI;
@@ -92,7 +85,7 @@ if ( $op && $op eq 'finish' ) { #If the value of $op equals 'finish' then redire
}
-#Store the value of the template input name='start' in the variable $start so we can check if the user has pressed this button and starting the onboarding tool process
+#Store the value of the template input name='start' in the variable $start so we can check if the user has pressed this button and started the onboarding tool process
my $start = $query->param('start');
$template->param('start'=>$start); #Hand the start variable back to the template
if ( $start && $start eq 'Start setting up my Koha' ){
@@ -108,8 +101,6 @@ if ( $start && $start eq 'Start setting up my Koha' ){
]
);
-
-#Select any library records from the database and hand them back to the template in the libraries variable.
}elsif ( $start && $start eq 'Add a patron category' ){
#Select all the patron category records in the categories database table and store them in the newly declared variable $categories
@@ -122,12 +113,11 @@ if ( $start && $start eq 'Start setting up my Koha' ){
my $itemtypes = Koha::ItemTypes->search();
$template->param(
itemtypes => $itemtypes,
- );
+ );#Hand the variable itemtypes back to the template
#Check if the $step variable equals 1 i.e. the user has clicked to create a library in the create library screen 1
}elsif ( $step && $step == 1 ) {
-
- my $createlibrary = $query->param('createlibrary'); #Store the inputted library branch code and name in $createlibrary
+ my $createlibrary = $query->param('createlibrary'); #Store the inputted library branch code and name in $createlibrary variable
$template->param('createlibrary'=>$createlibrary); # Hand the library values back to the template in the createlibrary variable
#store inputted parameters in variables
@@ -136,20 +126,16 @@ if ( $start && $start eq 'Start setting up my Koha' ){
my $op = $input->param('op') || 'list';
my $message;
my $library;
-#my @messages;
#Take the text 'branchname' and store it in the @fields array
my @fields = qw(
branchname
);
-
-#test
$template->param('branchcode'=>$branchcode);
-
$branchcode =~ s|\s||g; # Use a regular expression to check the value of the inputted branchcode
- #Create a new library object and store the branchcode and @fields array values in this new library object
+ #Create a new library object and store the branchcode and @fields array values in this new library object
$library = Koha::Library->new(
{ branchcode => $branchcode,
( map { $_ => scalar $input->param($_) || undef } @fields )
@@ -157,29 +143,27 @@ if ( $start && $start eq 'Start setting up my Koha' ){
);
eval { $library->store; }; #Use the eval{} function to store the library object
-
if($library){
$message = 'success_on_insert';
- }else{
+ }else{
$message = 'error_on_insert';
- }
+ }
- $template->param('message' => $message);
+ $template->param('message' => $message);
-#Check if the $step vairable equals 2 i.e. the user has clicked to create a patron category in the create patron category screen 1
+#Check if the $step variable equals 2 i.e. the user has clicked to create a patron category in the create patron category screen 1
}elsif ( $step && $step == 2 ){
- my $createcat = $query->param('createcat'); #Store the inputted library branch code and name in $createlibrary
- $template->param('createcat'=>$createcat); # Hand the library values back to the template in the createlibrary variable
-
+ my $createcat = $query->param('createcat'); #Store the inputted category code and name in $createcat
+ $template->param('createcat'=>$createcat);
#Initialising values
- my $input = new CGI;
my $searchfield = $input->param('description') // q||;
my $categorycode = $input->param('categorycode');
my $op = $input->param('op') // 'list';
my $message;
my $category;
+ $template->param('categorycode' =>$categorycode);
my ( $template, $loggedinuser, $cookie ) = C4::InstallAuth::get_template_and_user(
{
@@ -194,7 +178,7 @@ if ( $start && $start eq 'Start setting up my Koha' ){
#Once the user submits the page, this code validates the input and adds it
#to the database as a new patron category
- my $categorycode = $input->param('categorycode');
+ $categorycode = $input->param('categorycode');
my $description = $input->param('description');
my $overduenoticerequired = $input->param('overduenoticerequired');
my $category_type = $input->param('category_type');
@@ -204,40 +188,53 @@ if ( $start && $start eq 'Start setting up my Koha' ){
#Converts the string into a date format
if ( $enrolmentperioddate) {
- $enrolmentperioddate = output_pref(
- {
- dt => dt_from_string($enrolmentperioddate),
- dateformat => 'iso',
- dateonly => 1,
- }
- );
- }
+ $enrolmentperioddate = output_pref(
+ {
+ dt => dt_from_string($enrolmentperioddate),
+ dateformat => 'iso',
+ dateonly => 1,
+ }
+ );
+ }
- #Adds to the database
+ #Adds a new patron category to the database
$category = Koha::Patron::Category->new({
- categorycode=> $categorycode,
- description => $description,
- overduenoticerequired => $overduenoticerequired,
- category_type=> $category_type,
- default_privacy => $default_privacy,
- enrolmentperiod => $enrolmentperiod,
- enrolmentperioddate => $enrolmentperioddate,
+ categorycode=> $categorycode,
+ description => $description,
+ overduenoticerequired => $overduenoticerequired,
+ category_type=> $category_type,
+ default_privacy => $default_privacy,
+ enrolmentperiod => $enrolmentperiod,
+ enrolmentperioddate => $enrolmentperioddate,
});
+
eval {
- $category->store;
+ $category->store;
};
#Error messages
if($category){
- $message = 'success_on_insert';
+ $message = 'success_on_insert';
}else{
- $message = 'error_on_insert';
+ $message = 'error_on_insert';
}
$template->param('message' => $message);
#Create a patron
}elsif ( $step && $step == 3 ){
+ my $firstpassword = $input->param('password');
+ my $secondpassword = $input->param('password2');
+
+
+ if ($firstpassword ne $secondpassword){
+ my $DisplayError='Please rewrite the password';
+ warn $DisplayError;
+ $template->param(DisplayError=>$DisplayError,
+ );
+ }
+
+#Find all library records in the database and hand them to the template to display in the library dropdown box
my $libraries = Koha::Libraries->search( {}, { order_by => ['branchcode'] }, );
$template->param(libraries => $libraries,
group_types => [
@@ -250,18 +247,65 @@ if ( $start && $start eq 'Start setting up my Koha' ){
]
);
- my $categories;
- $categories= Koha::Patron::Categories->search();
+#Find all patron categories in the database and hand them to the template to display in the patron category dropdown box
+ my $categories= Koha::Patron::Categories->search();
$template->param(
categories => $categories,
);
- my $input = new CGI;
my $op = $input->param('op') // 'list';
+ my $minpw = C4::Context->preference("minPasswordLength");
+ $template->param("minPasswordLength" => $minpw);
my @messages;
my @errors;
+ my $nok = $input->param('nok');
+ my $firstpassword = $input->param('password');
+ my $secondpassword = $input->param('password2');
+ my $cardnumber= $input->param('cardnumber');
+ my $borrowernumber= $input->param('borrowernumber');
+ my $userid=$input->param('userid');
+
+ if(my $error_code = checkcardnumber($cardnumber, $borrowernumber)){
+ push @errors, $error_code == 1
+ ? 'ERROR_cardnumber_already_exists'
+ :$error_code == 2
+ ? 'ERROR_cardnumber_length'
+ :()
+ }
+
+# unless(Check_Userid($userid, $borrowernumber)){
+# push @errors, "ERROR_login_exist";
+# }
+ push @errors, "ERROR_password_mismatch" if $firstpassword ne $secondpassword;
+ push @errors, "ERROR_short_password" if ($firstpassword && $minpw && $firstpassword ne '****' && (length($firstpassword) < $minpw));
+#
+#Passing errors to template
+ $nok = $nok || scalar(@errors);
+
+ if($nok){
+
+ foreach my $error (@errors){
+ if ($error eq 'ERROR_password_mismatch'){
+ $template->param(errorpasswordmismatch => 1);
+ }
+ if ($error eq 'ERROR_login_exist'){
+ $template->param(errorloginexists =>1);
+ }
+ if ($error eq 'ERROR_cardnumber_already_exists'){
+ $template->param(errorcardnumberexists => 1);
+ }
+ if ($error eq 'ERROR_cardnumber_length'){
+ $template->param(errorcardnumberlength => 1);
+ }
+ if ($error eq 'ERROR_short_password'){
+ $template->param(errorshortpassword => 1);
+ }
+ }
+ $template->param('nok' => 1);
+ warn $nok;
+ }else{
my ($template, $loggedinuser, $cookie)= C4::InstallAuth::get_template_and_user({
template_name => "/onboarding/onboardingstep3.tt",
query => $input,
@@ -287,21 +331,14 @@ if ( $start && $start eq 'Start setting up my Koha' ){
$newdata{dateexpiry} = '12/10/2016';
$newdata{privacy} = "default";
- if(my $error_code = checkcardnumber($newdata{cardnumber},$newdata{borrowernumber})){
- push @errors, $error_code == 1
- ? 'ERROR_cardnumber_already_exists'
- :$error_code == 2
- ? 'ERROR_cardnumber_length'
- :()
- }
-
-
#Hand the newdata hash to the AddMember subroutine in the C4::Members module and it creates a patron and hands back a borrowernumber which is being stored
my $borrowernumber = &AddMember(%newdata);
-#Create a hash named member2 and fillit with the borrowernumber of the borrower that has just been created
+
+#Create a hash named member2 and fill it with the borrowernumber of the borrower that has just been created
my %member2;
$member2{'borrowernumber'}=$borrowernumber;
+#Perform data validation on the flag that has been handed to onboarding.pl by the template
my $flag = $input->param('flag');
if ($input->param('newflags')) {
my $dbh=C4::Context->dbh();
@@ -317,33 +354,33 @@ if ( $start && $start eq 'Start setting up my Koha' ){
}
}
+ # construct flags
+ my $module_flags = 0;
+ my $sth=$dbh->prepare("SELECT bit,flag FROM userflags ORDER BY bit");
+ $sth->execute();
+ while (my ($bit, $flag) = $sth->fetchrow_array) {
+ if (exists $all_module_perms{$flag}) {
+ $module_flags += 2**$bit;
+ }
+ }
- # construct flags
- my $module_flags = 0;
- my $sth=$dbh->prepare("SELECT bit,flag FROM userflags ORDER BY bit");
- $sth->execute();
- while (my ($bit, $flag) = $sth->fetchrow_array) {
- if (exists $all_module_perms{$flag}) {
- $module_flags += 2**$bit;
- }
- }
-
- $sth = $dbh->prepare("UPDATE borrowers SET flags=? WHERE borrowernumber=?");
- $sth->execute($module_flags, $borrowernumber);
-
- #Error handling checking if the patron was created successfully
- if(!$borrowernumber){
- push @messages, {type=> 'error', code => 'error_on_insert'};
- }else{
- push @messages, {type=> 'message', code => 'success_on_insert'};
- }
- }
+#Set the superlibrarian permission of the newly created patron to superlibrarian
+ $sth = $dbh->prepare("UPDATE borrowers SET flags=? WHERE borrowernumber=?");
+ $sth->execute($module_flags, $borrowernumber);
+
+ #Error handling checking if the patron was created successfully
+ if(!$borrowernumber){
+ push @messages, {type=> 'error', code => 'error_on_insert'};
+ }else{
+ push @messages, {type=> 'message', code => 'success_on_insert'};
+ }
+ }
+ }
}
}elsif ( $step && $step == 4){
my $createitemtype = $input->param('createitemtype');
$template->param('createitemtype'=> $createitemtype );
- my $input = new CGI;
my $itemtype_code = $input->param('itemtype');
my $op = $input->param('op') // 'list';
my $message;
@@ -358,22 +395,18 @@ if ( $start && $start eq 'Start setting up my Koha' ){
}
);
- if($op eq 'add_form'){
- my $itemtype = Koha::ItemTypes->find($itemtype_code);
- $template->param(itemtype=> $itemtype,);
- }elsif($op eq 'add_validate'){
- my $itemtype = Koha::ItemTypes->find($itemtype_code);
+ if($op eq 'add_validate'){
my $description = $input->param('description');
#store the input from the form - only 2 fields
- my $thisitemtype= Koha::ItemType->new(
+ my $itemtype= Koha::ItemType->new(
{ itemtype => $itemtype_code,
description => $description,
}
);
- eval{ $thisitemtype->store; };
+ eval{ $itemtype->store; };
#Error messages
- if($thisitemtype){
+ if($itemtype){
$message = 'success_on_insert';
}else{
$message = 'error_on_insert';
@@ -382,20 +415,21 @@ if ( $start && $start eq 'Start setting up my Koha' ){
$template->param('message' => $message);
}
}elsif ( $step && $step == 5){
-
- #Fetching all the existing categories to display in a drop down box
+ #Find all the existing categories to display in a dropdown box in the template
my $categories;
$categories= Koha::Patron::Categories->search();
$template->param(
categories => $categories,
);
+ #Find all the exisiting item types to display in a dropdown box in the template
my $itemtypes;
$itemtypes= Koha::ItemTypes->search();
$template->param(
itemtypes => $itemtypes,
);
+ #Find all the exisiting libraries to display in a dropdown box in the template
my $libraries = Koha::Libraries->search( {}, { order_by => ['branchcode'] }, );
$template->param(libraries => $libraries,
group_types => [
@@ -412,16 +446,16 @@ if ( $start && $start eq 'Start setting up my Koha' ){
my $dbh = C4::Context->dbh;
my ($template, $loggedinuser, $cookie) = C4::InstallAuth::get_template_and_user({template_name => "/onboarding/onboardingstep5.tt",
- query => $input,
- type => "intranet",
- authnotrequired => 0,
- flagsrequired => {parameters => 'manage_circ_rules'},
- debug => 1,
- });
+ query => $input,
+ type => "intranet",
+ authnotrequired => 0,
+ flagsrequired => {parameters => 'manage_circ_rules'},
+ debug => 1,
+ });
my $branch = $input->param('branch');
- unless ( $branch ) {
- if ( C4::Context->preference('DefaultToLoggedInLibraryCircRules') ) {
+ unless ( $branch ) {
+ if ( C4::Context->preference('DefaultToLoggedInLibraryCircRules') ) {
$branch = Koha::Libraries->search->count() == 1 ? undef : C4::Context::mybranch();
}
else {
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/installer/step3.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/installer/step3.tt
index 732c0a9..8aa7826 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/installer/step3.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/installer/step3.tt
@@ -217,11 +217,11 @@ function Hide(link)
[% END %]
All done!
Installation complete.
-
Click on 'Finish' to complete and load the Koha Staff Interface.
+
Click on 'Continue to onboarding tool' to complete and load the Koha onboarding tool.