diff --git a/TopicUserMappingContrib/data/System/BulkRegistrationInputViewTemplate.txt b/TopicUserMappingContrib/data/System/BulkRegistrationInputViewTemplate.txt index 0d35b77207..0a82c30bbd 100644 --- a/TopicUserMappingContrib/data/System/BulkRegistrationInputViewTemplate.txt +++ b/TopicUserMappingContrib/data/System/BulkRegistrationInputViewTemplate.txt @@ -1,4 +1,4 @@ -%META:TOPICINFO{author="ProjectContributor" date="1456877772" format="1.1" version="1"}% +%META:TOPICINFO{author="ProjectContributor" date="1456982088" format="1.1" version="1"}% %META:TOPICPARENT{name="BulkRegister"}% %{ =================================================== @@ -29,18 +29,10 @@ _Be sure to remember to save any table changes!_ " else="
*Bulk registration is restricted to Administrators.*
"}% -%INCLUDE{"%TOPIC%Log" warn="off"}% +%IF{"'%WEB%.%TOPIC%'/info.date < '%WEB%.%TOPIC%Log'/info.date" then="$percntINCLUDE{\"%TOPIC%Log\" warn=\"off\"}$percnt"}% *Back to:* [[%SYSTEMWEB%.BulkRegistration][Bulk Registration]] ---- *Related Topics:* %FORMFIELD{"RelatedTopics"}%%TMPL:END%%{ ---------------------------------------------------- - Re-define the form DEFinition to be empty; the contents of the from data - have already been displayed above so it wouldn't make much sense to show all - that again at the bottom of each [[FAQForm]] topic ---------------------------------------------------- -}%%TMPL:DEF{"form"}%%TMPL:END%%{ ===================================================
}% - -%META:PREFERENCE{name="VIEW_TEMPLATE" title="VIEW_TEMPLATE" type="Set" value="SkinTemplateView"}% diff --git a/core/lib/Foswiki/UI/Register.pm b/core/lib/Foswiki/UI/Register.pm index 5f6e4ef8b8..8d57d09b8c 100755 --- a/core/lib/Foswiki/UI/Register.pm +++ b/core/lib/Foswiki/UI/Register.pm @@ -416,19 +416,23 @@ sub bulkRegister { } } - my $log = "---+ Report for Bulk Register\n"; + my $log = "---+ Report for Bulk Register\n%TOC%\n"; # TODO: should check that the header row actually contains the # required fields. # TODO: and consider using MAKETEXT to enable translated tables. - #-- Process each row, generate a log as we go + my $genReset; # Flag set if any rows don't have a password + #-- Process each row, generate a log as we go for ( my $n = 0 ; $n < scalar(@data) ; $n++ ) { my $row = $data[$n]; + $row->{errors} = ''; $row->{webName} = $userweb; unless ( $row->{WikiName} ) { + $row->{errors} .= " Not registered: WikiName not entered."; + $row->{FAIL} = 1; $log .= "---++ Failed to register user on row $n: no !WikiName\n"; next; } @@ -451,9 +455,34 @@ sub bulkRegister { #$row->{LoginName} = $row->{WikiName} unless $row->{LoginName}; $log .= _registerSingleBulkUser( $session, \@fields, $row, $settings ); + $genReset = 1 unless ( $row->{Password} || $row->{FAIL} ); } - $log .= "----\n"; + my $tmpl = $session->templates->readTemplate('registermessages'); + $log .= $session->templates->expandTemplate('bulkreg_summary'); + + # If no passwords require reset, then don't generate the reset form. + if ($genReset) { + $log .= $session->templates->expandTemplate('bulkreg_pwreset_form'); + } + + $log .= $session->templates->expandTemplate('bulkreg_summary_head'); + + my $rowtmpl = $session->templates->expandTemplate('bulkreg_summary_row'); + + foreach my $row (@data) { + my $ifield = $rowtmpl; + my $icon = + ( $row->{FAIL} ? '%X%' : ( $row->{WARN} ? '%ICON{alert}%' : '%Y%' ) ); + my $state = + ( $row->{FAIL} ) ? 'disabled' : ( $row->{Password} ) ? '' : 'checked'; + $ifield =~ s/\$state/$state/; + $ifield =~ s/\$flag/$icon/; + $ifield =~ s/\$wikiname/$row->{WikiName}/g; + $ifield =~ s/\$errors/$row->{errors}/; + $log .= $ifield; + } + $log .= $session->templates->expandTemplate('bulkreg_summary_foot'); my $logWeb; my $logTopic = Foswiki::Sandbox::untaint( @@ -489,6 +518,9 @@ sub _registerSingleBulkUser { #-- Ensure every required field exists # NB. LoginName is OPTIONAL if ( _missingElements( $fieldNames, \@requiredFields ) ) { + $row->{errors} .= " Rejected: missing fields: " + . join( ' ', map { $_ . ' : ' . $row->{$_} } @$fieldNames ); + $row->{FAIL} = 1; $log .= $b1 . join( ' ', map { $_ . ' : ' . $row->{$_} } @$fieldNames ) @@ -511,6 +543,8 @@ sub _registerSingleBulkUser { } catch Foswiki::OopsException with { my $e = shift; + $row->{errors} .= "Validation failed: " . $e->{def}; + $row->{FAIL} = 1; $log .= '
' . $e->stringify($session) . "
\n"; $tryError = "$b1 Registration failed\n"; }; @@ -543,6 +577,8 @@ sub _registerSingleBulkUser { } else { $log .= "$b1 Not writing user topic $row->{WikiName}\n"; + $row->{errors} .= " User topic not written!"; + $row->{WARN} = 1; } $users->setEmails( $cUID, $row->{Email} ); @@ -562,6 +598,8 @@ sub _registerSingleBulkUser { } catch Error with { my $e = shift; + $row->{errors} = " Failed to create user topic! " . $e->{def}; + $row->{FAIL} = 1; $log .= "$b1 Failed to add user: " . $e->stringify() . "\n"; }; @@ -579,6 +617,8 @@ sub _registerSingleBulkUser { "Registration: Failure adding $cUID to $groupName in BulkRegister" ); $log .= " * Failed to add $cUID to $groupName: $err\n"; + $row->{errors} .= " Failed to add $cUID to $groupName: $err"; + $row->{WARN} = 1; }; } diff --git a/core/templates/registermessages.tmpl b/core/templates/registermessages.tmpl index 7e6c212004..ea96225fd9 100644 --- a/core/templates/registermessages.tmpl +++ b/core/templates/registermessages.tmpl @@ -445,3 +445,31 @@ %MAKETEXT{"[_1] removed from the [_2] group." args="%PARAM1%, %PARAM2%"}% %MAKETEXT{"See %MAINWEB%.WikiGroups to see the result."}%%TMPL:END% +%{==============================================================================}% +%TMPL:DEF{"bulkreg_pwreset_form"}% +
+ + + +*This text will be sent to users in their "reset" e-mail.* The login name and password will be filled in automatically. + +%TMPL:END% +%{==============================================================================}% +%TMPL:DEF{"bulkreg_summary_head"}% +| *ok* | *WikiName* | *Reset Password* | *Results* |%TMPL:END% +%{==============================================================================}% +%TMPL:DEF{"bulkreg_summary"}% +%STARTSECTION{type="include"}% +---++ Summary of Registrations +Registration run by %REVINFO{format="$wikiusername at =$date-$time="}%. See [[%TOPIC%]] for more detailed information. + +%TMPL:END% +%{==============================================================================}% +%TMPL:DEF{"bulkreg_summary_row"}% +| $flag | $wikiname | | $errors |%TMPL:END% +%{==============================================================================}% +%TMPL:DEF{"bulkreg_summary_foot"}% +%ENDSECTION{type="include"}% +%TMPL:END%