Skip to content

Commit

Permalink
Item12329: Add {Register}{ExpireAfter} setting
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk@16331 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
GeorgeClark authored and GeorgeClark committed Jan 5, 2013
1 parent 6d1eb2f commit 2267cbc
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 15 deletions.
14 changes: 10 additions & 4 deletions UnitTestContrib/test/unit/RegisterTests.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@ sub verify_rejectDuplicatePendingEmail {
my $this = shift;
$Foswiki::cfg{Register}{NeedVerification} = 1;
$Foswiki::cfg{Register}{UniqueEmail} = 1;
$Foswiki::cfg{Sessions}{ExpireAfter} = '-23600';
$Foswiki::cfg{Register}{ExpireAfter} = '-23600';

#$Foswiki::cfg{PasswordManager} = 'Foswiki::Users::HtPasswdUser';
$Foswiki::cfg{Register}{AllowLoginName} = 0;
Expand Down Expand Up @@ -1130,7 +1130,10 @@ sub verify_rejectDuplicatePendingEmail {
$this->{session}->net->setMailHandler( \&FoswikiFnTestCase::sentMail );
$Foswiki::cfg{Register}{NeedVerification} = 1;
$Foswiki::cfg{Register}{UniqueEmail} = 1;
$Foswiki::cfg{Sessions}{ExpireAfter} = '-23600';

# Should use Sessions expiration if Registration is not defined.
$Foswiki::cfg{Register}{ExpireAfter} = undef;
$Foswiki::cfg{Sessions}{ExpireAfter} = '-23600';

try {
$this->captureWithKey( register => $REG_UI_FN, $this->{session} );
Expand Down Expand Up @@ -1954,7 +1957,7 @@ sub test_PendingRegistrationManualCleanup {
$Foswiki::cfg{Register}{NeedVerification} = 1;
$Foswiki::cfg{Register}{EnableNewUserRegistration} = 1;
$Foswiki::cfg{Register}{UniqueEmail} = 0;
$Foswiki::cfg{Sessions}{ExpireAfter} = '-600';
$Foswiki::cfg{Register}{ExpireAfter} = '-600';
$Foswiki::cfg{LoginManager} = 'Foswiki::LoginManager::TemplateLogin';
$Foswiki::cfg{PasswordManager} = 'Foswiki::Users::HtPasswdUser';
my $query = Unit::Request->new(
Expand Down Expand Up @@ -2019,7 +2022,10 @@ sub test_PendingRegistrationAutoCleanup {
$Foswiki::cfg{Register}{NeedVerification} = 1;
$Foswiki::cfg{Register}{EnableNewUserRegistration} = 1;
$Foswiki::cfg{Register}{UniqueEmail} = 0;
$Foswiki::cfg{Sessions}{ExpireAfter} = 600;

# Should use Sessions expiration if Registration is not defined.
$Foswiki::cfg{Register}{ExpireAfter} = undef;
$Foswiki::cfg{Sessions}{ExpireAfter} = 600;
$Foswiki::cfg{LoginManager} = 'Foswiki::LoginManager::TemplateLogin';
$Foswiki::cfg{PasswordManager} = 'Foswiki::Users::HtPasswdUser';
my $query = Unit::Request->new(
Expand Down
19 changes: 17 additions & 2 deletions core/lib/Foswiki.spec
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ $Foswiki::cfg{DetailedOS} = '';
# cons of using persistent sessions.</p>
$Foswiki::cfg{UseClientSessions} = 1;

# **NUMBER FEEDBACK=AUTO 20 EXPERT DISPLAY_IF {UseClientSessions}**
# **NUMBER FEEDBACK=AUTO 20 DISPLAY_IF {UseClientSessions}**
# Set the session timeout, in seconds. The session will be cleared after this
# amount of time without the session being accessed. The default is 6 hours
# (21600 seconds).<p />
Expand All @@ -305,7 +305,7 @@ $Foswiki::cfg{UseClientSessions} = 1;
# job to clean up expired sessions. The standard maintenance cron script
# <tt>tools/tick_foswiki.pl</tt> includes this function.
# <p> Session files are stored in the <tt>{WorkingDir}/tmp</tt> directory.</p>
# <p> This setting is also used to set a lifetime for registration requests.</p>
# <p> This setting is also used to set a lifetime for passthru redirect requests.</p>
$Foswiki::cfg{Sessions}{ExpireAfter} = 21600;

# **NUMBER FEEDBACK=AUTO EXPERT DISPLAY_IF {UseClientSessions} && {LoginManager}=='Foswiki::LoginManager::TemplateLogin'**
Expand Down Expand Up @@ -719,6 +719,21 @@ $Foswiki::cfg{Register}{NeedApproval} = $FALSE;
# administrator.
$Foswiki::cfg{Register}{Approvers} = '';
# **NUMBER FEEDBACK=AUTO 20 DISPLAY_IF {Register}{NeedVerification} || {Register}{NeedApproval}**
# Set the pending registration timeout, in seconds. The pending registration
# will be cleared after this amount of time. The default is 6 hours
# (21600 seconds).<p />
# <b>Note</b> By default, registration expiry is done "on the fly"
# during the registration process. For best performance, you can set {Register}{ExpireAfter}
# to a negative number, which will mean that Foswiki won't try to clean
# up expired registrations durning registration. Instead you should use a cron
# job to clean up expired sessions. The standard maintenance cron script
# <tt>tools/tick_foswiki.pl</tt> includes this function.
# <p><b>Note</b> that if you are using registration approval by 3rd party reviewers,
# this timer should most likely be significantly increased. 24 hours = 86400, 3 days = 259200.</p>
# <p> Pending registration requests are stored in the <tt>{WorkingDir}/registration_approvals</tt> directory.</p>
$Foswiki::cfg{Register}{ExpireAfter} = 21600;
# **BOOLEAN EXPERT**
# Controls whether the user password has to be entered twice on the
# registration page or not. The default is to require confirmation, in which
Expand Down
55 changes: 55 additions & 0 deletions core/lib/Foswiki/Configure/Checkers/Register/ExpireAfter.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# See bottom of file for license and copyright information
package Foswiki::Configure::Checkers::Register::ExpireAfter;

use strict;
use warnings;

require Foswiki::Configure::Checkers::NUMBER;
our @ISA = ('Foswiki::Configure::Checkers::NUMBER');

sub check {
my $this = shift;

return ''
unless ( $Foswiki::cfg{Register}{NeedVerification}
|| $Foswiki::cfg{Register}{NeedApproval} );

my $e = '';
$e .= $this->SUPER::check(@_);
return $e if ( $e =~ /Error:/ );

if ( $Foswiki::cfg{Register}{ExpireAfter} < 0 ) {
$e .= $this->WARN(<<'MESSAGE');
Foswiki will *not* clean up pending registrations automatically. Make sure you
have a cron job running the <tt>tools/tick_foswiki.pl</tt> script.
MESSAGE
}
return $e;
}

1;
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2008-2010 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
Additional copyrights apply to some or all of the code in this
file as follows:
Copyright (C) 2000-2006 TWiki Contributors. All Rights Reserved.
TWiki 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.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ sub check {
if ( $Foswiki::cfg{Sessions}{ExpireAfter} < 0 ) {
$e .= $this->WARN(<<'MESSAGE');
Foswiki will *not* clean up sessions automatically. Make sure you
have a cron job running.
have a cron job running the <tt>tools/tick_foswiki.pl</tt> script.
MESSAGE
}
return $e;
Expand Down
1 change: 1 addition & 0 deletions core/lib/Foswiki/Contrib/core/MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ lib/Foswiki/Configure/Checkers/RCS/unlockCmd.pm 0444
lib/Foswiki/Configure/Checkers/REGEX.pm 0444
lib/Foswiki/Configure/Checkers/Register/AllowLoginName.pm 0444
lib/Foswiki/Configure/Checkers/Register/EmailFilter.pm 0444
lib/Foswiki/Configure/Checkers/Register/ExpireAfter.pm 0444
lib/Foswiki/Configure/Checkers/Register/NeedVerification.pm 0444
lib/Foswiki/Configure/Checkers/RegistrationApprovals.pm 0444
lib/Foswiki/Configure/Checkers/SMTP/MAILHOST.pm 0444
Expand Down
26 changes: 19 additions & 7 deletions core/lib/Foswiki/UI/Register.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1526,14 +1526,23 @@ sub _buildConfirmationEmail {
sub _validateRegistration {
my ( $session, $data, $requireForm ) = @_;

# Set the registration timeout. If it's not configured
# Use the session timeout, and if that's not configure
# then default to 10 hours.
my $exp =
( defined $Foswiki::cfg{Register}{ExpireAfter} )
? $Foswiki::cfg{Register}{ExpireAfter}
: ( defined $Foswiki::cfg{Sessions}{ExpireAfter} )
? $Foswiki::cfg{Sessions}{ExpireAfter}
: 36000; # 10 hours

# Expire stale registrations, but if email addresses are being
# checked for duplicate registrations, then let that code
# read all the pending registration files. Don't do it twice.
# Also don't do it if ExpireAfter is negative. Use tick_foswiki instead.
unless ( $Foswiki::cfg{Register}{UniqueEmail} ) {
if ( $Foswiki::cfg{Sessions}{ExpireAfter} > 1 ) {
_checkPendingRegistrations( undef,
$Foswiki::cfg{Sessions}{ExpireAfter} );
if ( $exp > 1 ) {
_checkPendingRegistrations( undef, $exp );
}
}

Expand Down Expand Up @@ -1736,9 +1745,7 @@ sub _validateRegistration {
if ( $Foswiki::cfg{Register}{UniqueEmail} ) {
my @existingNames = Foswiki::Func::emailToWikiNames( $data->{Email} );
if ( $Foswiki::cfg{Register}{NeedVerification} ) {
my @pending =
_checkPendingRegistrations( $data->{Email},
$Foswiki::cfg{Sessions}{ExpireAfter} );
my @pending = _checkPendingRegistrations( $data->{Email}, $exp );
push @existingNames, @pending if scalar @pending;
}
if ( scalar(@existingNames) ) {
Expand Down Expand Up @@ -2044,7 +2051,12 @@ tick_foswiki to expire stale registrations.
=cut

sub expirePendingRegistrations {
my $exp = $Foswiki::cfg{Sessions}{ExpireAfter} || 36000; # 10 hours
my $exp =
( defined $Foswiki::cfg{Register}{ExpireAfter} )
? $Foswiki::cfg{Register}{ExpireAfter}
: ( defined $Foswiki::cfg{Sessions}{ExpireAfter} )
? $Foswiki::cfg{Sessions}{ExpireAfter}
: 36000; # 10 hours

$exp = -$exp if $exp < 0;
_checkPendingRegistrations( undef, $exp );
Expand Down
2 changes: 1 addition & 1 deletion core/tools/tick_foswiki.pl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ BEGIN
Foswiki::LoginManager::expireDeadSessions();

# This will expire pending registrations that have not been used for
# |{Sessions}{ExpireAfter}| seconds i.e. if you set {Sessions}{ExpireAfter}
# |{Register}{ExpireAfter}| seconds i.e. if you set {Register}{ExpireAfter}
# to -36000 or 36000 it will expire registrations that have not been verified for
# more than 10 hours,

Expand Down

0 comments on commit 2267cbc

Please sign in to comment.