Skip to content

Commit

Permalink
Item9790: Item2266: Add password reset form and summary
Browse files Browse the repository at this point in the history
Hide the detailed registration report. Only include a table of the
registerd users.

Generate a bulk password reset form for any bulk registered users that
didn't have a password set in the input.

Also only show the registration report with the timestamp on the report
is newer than the timestamp on the input.
  • Loading branch information
gac410 committed Mar 3, 2016
1 parent de1b48a commit 0999b82
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 13 deletions.
@@ -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"}%
%{<verbatim class="tml">
===================================================
Expand Down Expand Up @@ -29,18 +29,10 @@ _Be sure to remember to save any table changes!_
</form> "
else="<div class='foswikiAlert'> *Bulk registration is restricted to Administrators.* </div>"}%

%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%%{
===================================================
</verbatim>}%

%META:PREFERENCE{name="VIEW_TEMPLATE" title="VIEW_TEMPLATE" type="Set" value="SkinTemplateView"}%
46 changes: 43 additions & 3 deletions core/lib/Foswiki/UI/Register.pm
Expand Up @@ -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;
}
Expand All @@ -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(
Expand Down Expand Up @@ -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 )
Expand All @@ -511,6 +543,8 @@ sub _registerSingleBulkUser {
}
catch Foswiki::OopsException with {
my $e = shift;
$row->{errors} .= "Validation failed: " . $e->{def};
$row->{FAIL} = 1;
$log .= '<blockquote>' . $e->stringify($session) . "</blockquote>\n";
$tryError = "$b1 Registration failed\n";
};
Expand Down Expand Up @@ -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} );

Expand All @@ -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";
};

Expand All @@ -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;
};
}

Expand Down
28 changes: 28 additions & 0 deletions core/templates/registermessages.tmpl
Expand Up @@ -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"}%
<form action='%SCRIPTURLPATH{"manage"}%/%BASEWEB%/%BASETOPIC%' method='post' />
<input type="hidden" name="action" value="resetPassword" />
<input type="submit" class="foswikiSubmit" value="Reset selected user passwords and send message" />

*This text will be sent to users in their "reset" e-mail.* The login name and password will be filled in automatically.
<textarea class="foswikiInputField" name="Introduction" rows="4" cols="70" style="width:99%;">
Welcome! The site is ready for your use. Please use the login name and password listed below and contact me if you have any questions.
</textarea>
%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 | <input type='checkbox' name='LoginName' $state value='$wikiname' /> | $errors |%TMPL:END%
%{==============================================================================}%
%TMPL:DEF{"bulkreg_summary_foot"}%
%ENDSECTION{type="include"}%
%TMPL:END%

0 comments on commit 0999b82

Please sign in to comment.