Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Item14201: Initial commit for PendingRegistrationsReport
  • Loading branch information
gac410 committed Oct 21, 2016
1 parent c3075fc commit fe0585c
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 0 deletions.
11 changes: 11 additions & 0 deletions core/data/Main/PendingRegistrations.txt
@@ -0,0 +1,11 @@
%META:TOPICINFO{author="ProjectContributor" comment="" date="1477007062" format="1.1" version="1"}%
---+ %MAKETEXT{"Pending Registrations"}%
---++ %MAKETEXT{"Registrations awaiting Email verification"}%

%PENDINGREGISTRATIONS{"Verification"}%

---++ %MAKETEXT{"Registrations awaiting approval"}%

%MAKETEXT{"You can use the \"approve\" or \"reject\" links to approve or reject these registrations"}%

%PENDINGREGISTRATIONS{"Approval"}%
28 changes: 28 additions & 0 deletions core/data/System/PendingRegistrationsTemplate.txt
@@ -0,0 +1,28 @@
%META:TOPICINFO{author="ProjectContributor" comment="" date="1476996032" format="1.1" version="1"}%
Copy this topic to %USERSWEB%.PendingRegistrationsTemplate for customized display.

---++ Templates for "Pending Approval" registrations
<verbatim>
%TMPL:DEF{"ApprovalHeader"}%<noautolink>
| *WikiName* | *Email* | *LastName* | *FirstName* | *LoginName* | *Code* | *Action* |
%TMPL:END%

%TMPL:DEF{"Approval"}%| $WikiName | $Email | $LastName | $FirstName | $LoginName | $ApprovalCode |\
[[%SCRIPTURLPATH{"register" action="approve" code="$ApprovalCode" referee="%WIKINAME%"}%][%MAKETEXT{"Approve"}%]] / \
[[%SCRIPTURLPATH{"register" action="disapprove" code="$ApprovalCode" referee="%WIKINAME%"}%][%MAKETEXT{"Reject"}%]] |
%TMPL:END%
</verbatim>

---++ Templates for "Pending Verification" registrations
<verbatim>
%TMPL:DEF{"VerificationHeader"}%<noautolink>
| *WikiName* | *Email* | *LastName* | *FirstName* | *LoginName* | *Code* |
%TMPL:END%

%TMPL:DEF{"Verification"}%| $WikiName | $Email | $LastName | $FirstName | $LoginName | $VerificationCode |%TMPL:END%
</verbatim>

---++ Common templates
<verbatim>
%TMPL:DEF{"accessdenied"}%<div class="foswikiAlert">%MAKETEXT{"Access to pending registrations is restricted to administrators"}%</div>%TMPL:END%
</verbatim>
1 change: 1 addition & 0 deletions core/lib/Foswiki.pm
Expand Up @@ -271,6 +271,7 @@ BEGIN {
META => undef, # deprecated
METASEARCH => undef, # deprecated
NONCE => undef,
PENDINGREGISTRATIONS => undef,
PERLDEPENDENCYREPORT => undef,
NOP =>

Expand Down
3 changes: 3 additions & 0 deletions core/lib/Foswiki/Contrib/core/MANIFEST
Expand Up @@ -36,6 +36,7 @@ data/Main/AdminGroup.txt 0644
data/Main/AdminUser.txt 0644
data/Main/AdminUserLeftBar.txt 0644
data/Main/GroupViewTemplate.txt 0644
data/Main/PendingRegistrations.txt 0644
data/Main/ProjectContributor.txt 0644
data/Main/SitePreferences.txt 0644
data/Main/UnknownUser.txt 0644
Expand Down Expand Up @@ -132,6 +133,7 @@ data/System/ObjectMethod.txt 0644
data/System/PackageForm.txt 0644
data/System/PageCaching.txt 0644
data/System/ParentList.txt 0644
data/System/PendingRegistrationsTemplate.txt 0644
data/System/PerlDependencyReport.txt 0644
data/System/PerlDoc.txt 0644
data/System/PlainSkin.txt 0644
Expand Down Expand Up @@ -559,6 +561,7 @@ lib/Foswiki/Macros/MAKETEXT.pm 0444
lib/Foswiki/Macros/META.pm 0444
lib/Foswiki/Macros/METASEARCH.pm 0444
lib/Foswiki/Macros/NONCE.pm 0444
lib/Foswiki/Macros/PENDINGREGISTRATIONS.pm 0444
lib/Foswiki/Macros/PERLDEPENDENCYREPORT.pm 0444 Configuration
lib/Foswiki/Macros/PUBURL.pm 0444
lib/Foswiki/Macros/PUBURLPATH.pm 0444
Expand Down
113 changes: 113 additions & 0 deletions core/lib/Foswiki/Macros/PENDINGREGISTRATIONS.pm
@@ -0,0 +1,113 @@
# See bottom of file for license and copyright information
package Foswiki;

use strict;
use warnings;

use File::Spec;
use Data::Dumper;
use Foswiki::Func;
use Config;
use Storable;

sub PENDINGREGISTRATIONS {
my ( $this, $params ) = @_;

Foswiki::Func::loadTemplate('PendingRegistrations');

my $report;

if ( ( !defined $params->{_DEFAULT} )
|| lc( $params->{_DEFAULT} ) eq 'approval' )
{
$report .= $this->_checkPendingRegistrations('Approval');
}

if ( ( !defined $params->{_DEFAULT} )
|| lc( $params->{_DEFAULT} ) eq 'verification' )
{
$report .= $this->_checkPendingRegistrations('Verification');
}

return $report;
}

sub _checkAccess {
my $this = shift;

return (
$this->{users}->isAdmin( $this->{user} )
|| ( $Foswiki::cfg{Register}{Approvers}
&& $Foswiki::cfg{Register}{Approvers} =~ m/\b\Q$this->{user}\E\b/ )
);
}

# Check pending registrations for duplicate email, or expiration
sub _checkPendingRegistrations {
my $this = shift;
my $check = shift;
my $report = '';

unless ( $this->_checkAccess() ) {
return Foswiki::Func::expandTemplate('accessdenied');
}

my $dir = "$Foswiki::cfg{WorkingDir}/registration_approvals/";

if ( opendir( my $d, "$dir" ) ) {
foreach my $f ( grep { /^.*\.[0-9]{1,8}$/ } readdir $d ) {
my $regFile = Foswiki::Sandbox::untaintUnchecked("$dir$f");

my $data = retrieve($regFile);
next unless defined $data;
next unless $data->{ $check . 'Code' };
$report .= _reportPending( $data, $check );
}
closedir($d);
}
my $header = '';
if ($report) {
$header = Foswiki::Func::expandTemplate( $check . 'Header' );
}
return $header . $report;
}

sub _reportPending {
my $hashref = shift;
my $check = shift;

my $tmpl = Foswiki::Func::expandTemplate($check);

my $report = '';
foreach my $field ( sort { lc($a) cmp lc($b) } keys %$hashref ) {
next if $field eq 'form';
next if $field eq 'Confirm';
next if $field eq 'Password';
$tmpl =~ s/\$$field/$hashref->{$field}/g;

#$report .= "$field: $hashref->{$field}\n";
}
print STDERR Data::Dumper::Dumper( \$hashref );
return "$tmpl";
}

1;

__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2014-2016 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. For
more details read LICENSE in the root of this distribution.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
As per the GPL, removal of this notice is prohibited.

0 comments on commit fe0585c

Please sign in to comment.