Index: test/unit/RegisterTests.pm
===================================================================
--- test/unit/RegisterTests.pm (Revision 12441)
+++ test/unit/RegisterTests.pm (Arbeitskopie)
@@ -644,6 +644,99 @@
};
}
+
+# Purpose: Test behaviour of duplicate activation (Item3105)
+# Verifies: Most of the things which are verified during normal
+# registration with Verification, plus Oops for
+# duplicate verification
+sub test_duplicateActivation {
+ my $this = shift;
+
+ # Start similar to registration with verification
+ $TWiki::cfg{Register}{NeedVerification} = 1;
+ my $query = CGI->new({'TopicName' => ['TWikiRegistration'],
+ 'Twk1Email' => [$testUserEmail],
+ 'Twk1WikiName' => [$testUserWikiName],
+ 'Twk1Name' => ['Test User'],
+ 'Twk1LoginName' => [$testUserLoginName],
+ 'Twk1FirstName' => ['Test'],
+ 'Twk1LastName' => ['User'],
+ 'action' => ['register'],
+ });
+ $query->path_info( "/$peopleWeb/TWikiRegistration" );
+ my $twiki = TWiki->new($TWiki::cfg{DefaultUserName}, $query);
+ $twiki->{net}->setMailHandler(\&sentMail);
+ try {
+ TWiki::UI::Register::register_cgi($twiki);
+ } catch TWiki::OopsException with {
+ my $e = shift;
+ $this->assert_str_equals("attention", $e->{template},$e->stringify());
+ $this->assert_str_equals("confirm", $e->{def}, $e->stringify());
+ $this->assert_matches(qr/$testUserEmail/, $e->stringify());
+ } catch TWiki::AccessControlException with {
+ my $e = shift;
+ $this->assert(0, $e->stringify);
+ } catch Error::Simple with {
+ $this->assert(0, shift->stringify());
+ } otherwise {
+ $this->assert(0, "expected an oops redirect");
+ };
+ @mails = ();
+ $twiki->finish();
+
+ # For verification process everything including finish(), so don't just
+ # call verifyEmails
+ my $code = shift || $testUserWikiName.".foo";
+ $query = CGI->new ({'code' => [$code],
+ 'action' => ['verify'],
+ });
+ $query->path_info( "/$peopleWeb/TWikiRegistration" );
+ $twiki = TWiki->new($TWiki::cfg{DefaultUserName},$query);
+ $twiki->{net}->setMailHandler(\&sentMail);
+ try {
+ TWiki::UI::Register::register_cgi($twiki);
+ } catch TWiki::OopsException with {
+ my $e = shift;
+ $this->assert_str_equals("attention", $e->{template}, $e->stringify());
+ $this->assert_str_equals("thanks", $e->{def}, $e->stringify());
+ } catch TWiki::AccessControlException with {
+ my $e = shift;
+ $this->assert(0, $e->stringify);
+ } catch Error::Simple with {
+ $this->assert(0, shift->stringify());
+ } otherwise {
+ $this->assert(0, "expected an oops redirect");
+ };
+ @mails = ();
+ $twiki->finish();
+
+ # and now for something completely different: Do it all over again
+ $query = CGI->new ({'code' => [$code],
+ 'action' => ['verify'],
+ });
+ $query->path_info( "/$peopleWeb/TWikiRegistration" );
+ $twiki = TWiki->new($TWiki::cfg{DefaultUserName},$query);
+ $twiki->{net}->setMailHandler(\&sentMail);
+ try {
+ TWiki::UI::Register::register_cgi($twiki);
+ } catch TWiki::OopsException with {
+ my $e = shift;
+ $this->assert_str_equals("attention", $e->{template}, $e->stringify());
+ $this->assert_str_equals("duplicate_activation", $e->{def}, $e->stringify());
+ $this->assert_equals(0, scalar(@mails));
+ } catch TWiki::AccessControlException with {
+ my $e = shift;
+ $this->assert(0, $e->stringify);
+ } catch Error::Simple with {
+ $this->assert(0, shift->stringify());
+ } otherwise {
+ $this->assert(0, "expected an oops redirect");
+ };
+ @mails = ();
+ $twiki->finish();
+}
+
+
################################################################################
################################ RESET PASSWORD TESTS ##########################
@@ -843,8 +936,10 @@
}
=pod
+
Create an incomplete registration, and try to finish it off.
Once complete, try again - the second attempt at completion should fail.
+
=cut
sub test_UnregisteredUser {
@@ -855,7 +950,7 @@
my $result = TWiki::UI::Register::_getRegDetailsByCode($code, $TWiki::cfg{RegistrationApprovals});
$this->assert_equals("homer", $result->{doh} );
- my $result2 = TWiki::UI::Register::_reloadUserContext($code, $TWiki::cfg{RegistrationApprovals});
+ my $result2 = TWiki::UI::Register::_reloadUserContext($session, $code, $TWiki::cfg{RegistrationApprovals});
$this->assert_deep_equals($result2, $regSave);
try {
@@ -1025,8 +1120,11 @@
=pod
+
call this if you want to make spaces and \ns visible
+
=cut
+
sub visible {
return $_[0];
my ($a) = @_;
Index: templates/messages.tmpl
===================================================================
--- templates/messages.tmpl (Revision 12441)
+++ templates/messages.tmpl (Arbeitskopie)
@@ -234,6 +234,12 @@
%MAKETEXT{"Please contact [_1] if you have any questions." args="%WIKIWEBMASTER%"}%
%TMPL:END%
+%TMPL:DEF{"duplicate_activation"}%
+---+++ %MAKETEXT{"You are already registered"}%
+%MAKETEXT{"The name [_1] has already been registered successfully." args="'%PARAM1%'"}%
+
+%MAKETEXT{"Please contact [_1] if you have any questions." args="%WIKIWEBMASTER%"}%
+%TMPL:END%
%TMPL:DEF{"bad_loginname"}%
---+++ %MAKETEXT{"Incorrect [_1]" args="%TWIKIWEB%.LoginName"}%
%MAKETEXT{"'[_1]' is not a valid [_2] " args="%PARAM1%,%TWIKIWEB%.LoginName"}%
Index: lib/TWiki/UI/Register.pm
===================================================================
--- lib/TWiki/UI/Register.pm (Revision 12441)
+++ lib/TWiki/UI/Register.pm (Arbeitskopie)
@@ -729,7 +729,7 @@
unless( $code ) {
throw Error::Simple( 'verifyEmailAddress: no verification code!');
}
- my $data = _reloadUserContext( $code, $tempUserDir );
+ my $data = _reloadUserContext( $session, $code, $tempUserDir );
if (! exists $data->{Email}) {
throw Error::Simple( 'verifyEmailAddress: no email address!');
@@ -770,7 +770,7 @@
my $data;
if ($TWiki::cfg{Register}{NeedVerification}) {
- $data = _reloadUserContext( $code, $tempUserDir );
+ $data = _reloadUserContext( $session, $code, $tempUserDir );
_deleteUserContext( $code, $tempUserDir );
} else {
$data = _getDataFromQuery( $query, $query->param() );
@@ -1217,16 +1217,29 @@
# Dies if loads and does not match.
# Returns the users data hash if succeeded.
# Returns () if not found.
+# Assumptions: In error handling we assume that the verification code
+# starts with the wikiname under consideration, and that the
+# random code does not contain a '.'.
sub _reloadUserContext {
- my( $code, $tmpDir ) = @_;
+ my( $session, $code, $tmpDir ) = @_;
ASSERT($code) if DEBUG;
my $verificationFilename = _verificationCodeFilename( $code, $tmpDir );
unless (-f $verificationFilename){
- throw TWiki::OopsException( 'attention',
- def => 'bad_ver_code',
- params => [ $code, '.' ] );
+ my ($wikiName) = $code =~ /(.*)\./;
+ if ($session->{users}->lookupWikiName($wikiName)) {
+ throw TWiki::OopsException('attention',
+ def => 'duplicate_activation',
+ params => [$wikiName],
+ );
+ }
+ else {
+ throw TWiki::OopsException('attention',
+ def => 'bad_ver_code',
+ params => [ $code, '.' ],
+ );
+ }
}
my $data = _getRegDetailsByCode($code, $tmpDir);