Skip to content

Commit

Permalink
Item14199: Use Storable to store/retrieve registration
Browse files Browse the repository at this point in the history
Data::Dumper does not support utf-8, and international names get
corrupted.

Storable preserves the utf-8 data, but is not very portable

Caution:  When this update is applied, any pending registrations
will become invalid.
  • Loading branch information
gac410 committed Oct 12, 2016
1 parent 6afef6b commit e245b22
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
9 changes: 6 additions & 3 deletions UnitTestContrib/test/unit/RegisterTests.pm
Expand Up @@ -1879,9 +1879,12 @@ sub verify_UnregisteredUser {
}; };


my $file = Foswiki::UI::Register::_codeFile( $regSave->{VerificationCode} ); my $file = Foswiki::UI::Register::_codeFile( $regSave->{VerificationCode} );
$this->assert( open( my $F, '>', $file ) ); use Storable;
print $F Data::Dumper->Dump( [ $regSave, undef ], [ 'data', 'form' ] ); store( $regSave, $file );
$this->assert( close $F );
#$this->assert( open( my $F, '>', $file ) );
#print $F Data::Dumper->Dump( [ $regSave, undef ], [ 'data', 'form' ] );
#$this->assert( close $F );


my $result2 = my $result2 =
Foswiki::UI::Register::_loadPendingRegistration( $this->{session}, Foswiki::UI::Register::_loadPendingRegistration( $this->{session},
Expand Down
42 changes: 16 additions & 26 deletions core/lib/Foswiki/UI/Register.pm
Expand Up @@ -14,6 +14,7 @@ use strict;
use warnings; use warnings;
use Assert; use Assert;
use Error qw( :try ); use Error qw( :try );
use Storable;


use Foswiki (); use Foswiki ();
use Foswiki::LoginManager (); use Foswiki::LoginManager ();
Expand Down Expand Up @@ -679,22 +680,8 @@ sub _requireConfirmation {
# SMELL: used for Register unit tests # SMELL: used for Register unit tests
$session->{DebugVerificationCode} = $data->{"${type}Code"}; $session->{DebugVerificationCode} = $data->{"${type}Code"};


require Data::Dumper;

my $file = _codeFile( $data->{"${type}Code"} ); my $file = _codeFile( $data->{"${type}Code"} );
my $F; store( $data, $file );
open( $F, '>', $file )
or throw Error::Simple( 'Failed to open file: ' . $! );
print $F "# $type code\n";

# SMELL: wierd jiggery-pokery required, otherwise Data::Dumper screws
# up the form fields when it saves. Perl bug? Probably to do with
# chucking around arrays, instead of references to them.
my $form = $data->{form};
$data->{form} = undef;
print $F Data::Dumper->Dump( [ $data, $form ], [ 'data', 'form' ] );
$data->{form} = $form;
close($F);


$session->logger->log( $session->logger->log(
{ {
Expand Down Expand Up @@ -2051,15 +2038,19 @@ sub _loadPendingRegistration {
); );
} }


$data = undef; try {
$form = undef; $data = retrieve($file);
do $file; }
$data->{form} = $form if $form; catch Error with {
throw Foswiki::OopsException( my $e = shift;
'register', require Data::Dumper;
def => 'bad_ver_code', print STDERR Data::Dumper::Dumper( \$e );
params => [ $code, 'Bad activation code' ] throw Foswiki::OopsException(
) if $!; 'register',
def => 'internal_error',
params => [ $code, 'Retrieve of stored registration failed' ]
);
};


return $data; return $data;
} }
Expand Down Expand Up @@ -2165,8 +2156,7 @@ sub _checkPendingRegistrations {
} }
if ($check) { if ($check) {
local $data; local $data;
local $form; $data = retrieve($regFile);
eval 'do $regFile';
next unless defined $data; next unless defined $data;
push @pending, $data->{WikiName} . '(pending)' push @pending, $data->{WikiName} . '(pending)'
if ( $check eq $data->{Email} ); if ( $check eq $data->{Email} );
Expand Down
7 changes: 7 additions & 0 deletions core/templates/registermessages.tmpl
Expand Up @@ -87,6 +87,13 @@
%MAKETEXT{"Please contact [_1] if you have any questions." args="<a href='mailto:%WIKIWEBMASTER%'>%WIKIWEBMASTER%</a>"}% %MAKETEXT{"Please contact [_1] if you have any questions." args="<a href='mailto:%WIKIWEBMASTER%'>%WIKIWEBMASTER%</a>"}%
%TMPL:END% %TMPL:END%
%{==============================================================================}% %{==============================================================================}%
%TMPL:DEF{"internal_error"}%
---+++ %MAKETEXT{"Activation Failed"}%
%MAKETEXT{"Activation for code [_1] failed with an internal error." args="'<code>%PARAM1%</code>'"}% %PARAM2%

%MAKETEXT{"This is an internal error. You can try to register again, or contact [_1] to report the error." args="<a href='mailto:%WIKIWEBMASTER%'>%WIKIWEBMASTER%</a>"}%
%TMPL:END%
%{==============================================================================}%
%TMPL:DEF{"registration_mail_failed"}% %TMPL:DEF{"registration_mail_failed"}%
---+++ %MAKETEXT{"Error registering new user"}% ---+++ %MAKETEXT{"Error registering new user"}%


Expand Down

0 comments on commit e245b22

Please sign in to comment.