diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 5714648c6..85e451f8d 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -2,6 +2,7 @@ - added #9668 extension template variable to attachment loops for the following assets: Article,Post,Event,File,Form::Attachments,Folder - added WaitForUserConfirmation workflow activity + - added new setting - Enable Users after Anonymous Registration? - added the optional WebGUI::Content::PDFGenerator, not enabled by default (see the module's documentation). - fixed #12204: Default forum notification template produces invalid HTML diff --git a/docs/upgrades/upgrade_7.10.20-7.10.21.pl b/docs/upgrades/upgrade_7.10.20-7.10.21.pl index 0d9612b79..fc1bae8a2 100644 --- a/docs/upgrades/upgrade_7.10.20-7.10.21.pl +++ b/docs/upgrades/upgrade_7.10.20-7.10.21.pl @@ -30,6 +30,7 @@ my $quiet; # this line required my $session = start(); # this line required addWaitForConfirmationWorkflow($session); +addCreateUsersEnabledSetting($session); finish($session); # this line required @@ -46,6 +47,17 @@ sub addWaitForConfirmationWorkflow { } } +#---------------------------------------------------------------------------- +sub addCreateUsersEnabledSetting { + my $session = shift; + my $s = $session->setting; + my $name = 'enableUsersAfterAnonymousRegistration'; + return if $s->has($name); + print "Adding $name setting..." unless $quiet; + $s->add($name => 1); + print "Done!\n" unless $quiet; +} + #---------------------------------------------------------------------------- # Describe what our function does #sub exampleFunction { diff --git a/lib/WebGUI/Auth/WebGUI.pm b/lib/WebGUI/Auth/WebGUI.pm index 4def4a10d..2226bf199 100644 --- a/lib/WebGUI/Auth/WebGUI.pm +++ b/lib/WebGUI/Auth/WebGUI.pm @@ -23,6 +23,7 @@ use WebGUI::User; use WebGUI::Utility; use WebGUI::Form::Captcha; use WebGUI::Macro; +use Scope::Guard qw(guard); use Encode (); our @ISA = qw(WebGUI::Auth); @@ -269,12 +270,26 @@ sub createAccountSave { $properties->{ identifier } = $self->hashPassword($password); $properties->{ passwordLastUpdated } = time(); $properties->{ passwordTimeout } = $setting->get("webguiPasswordTimeout"); - $properties->{ status } = 'Deactivated' if ($setting->get("webguiValidateEmail")); my $afterCreateMessage = $self->SUPER::createAccountSave($username,$properties,$password,$profile); + my $sendEmail = $setting->get('webguiValidateEmail'); + + # We need to deactivate the user and log him out if there are additional + # things that need to be done before he should be logged in. + my $cleanupUser; + if ($sendEmail || !$setting->get('enableUsersAfterAnonymousRegistration')) { + $cleanupUser = guard { + $self->user->status('Deactivated'); + $session->var->end($session->var->get('sessionId')); + $session->var->start(1, $session->getId); + my $u = WebGUI::User->new($session, 1); + $self->{user} = $u; + $self->logout; + }; + } # Send validation e-mail if required - if ($setting->get("webguiValidateEmail")) { + if ($sendEmail) { my $key = $session->id->generate; $self->saveParams($self->userId,"WebGUI",{emailValidationKey=>$key}); my $mail = WebGUI::Mail::Send->create($self->session, { @@ -290,12 +305,6 @@ WebGUI::Asset::Template->new($self->session,$self->getSetting('accountActivation $mail->addText($text); $mail->addFooter; $mail->queue; - $self->user->status("Deactivated"); - $session->var->end($session->var->get("sessionId")); - $session->var->start(1,$session->getId); - my $u = WebGUI::User->new($session,1); - $self->{user} = $u; - $self->logout; return $self->displayLogin($i18n->get('check email for validation','AuthWebGUI')); } return $afterCreateMessage; diff --git a/lib/WebGUI/Operation/Settings.pm b/lib/WebGUI/Operation/Settings.pm index 910772929..bc687eaf8 100644 --- a/lib/WebGUI/Operation/Settings.pm +++ b/lib/WebGUI/Operation/Settings.pm @@ -381,6 +381,15 @@ sub definition { hoverHelp=>$i18n->get('118 description'), defaultValue=>$setting->get("anonymousRegistration") }); + push(@fields, { + tab => 'user', + fieldType => 'yesNo', + name => 'enableUsersAfterAnonymousRegistration', + label => $i18n->get('Enable Users after Anonymous Registration?'), + hoverHelp => $i18n->get('enableUsersAfterAnonymousRegistration help'), + defaultValue => $setting->get('enableUsersAfterAnonymousRegistration') + } + ); push(@fields, { tab=>"user", fieldType=>"yesNo", diff --git a/lib/WebGUI/i18n/English/WebGUI.pm b/lib/WebGUI/i18n/English/WebGUI.pm index 5485ada82..98fd2b50a 100644 --- a/lib/WebGUI/i18n/English/WebGUI.pm +++ b/lib/WebGUI/i18n/English/WebGUI.pm @@ -4743,6 +4743,17 @@ Users may override this setting in their profile. context => 'Add, as in to append or add more', }, + 'Enable Users after Anonymous Registration?' => { + message => 'Enable Users after Anonymous Registration?', + lastUpdated => 1311618346, + }, + + 'enableUsersAfterAnonymousRegistration help' => { + message => 'If this is off, ' + . 'users must be manually activated by a workflow or an admin.', + lastUpdated => 1311618419, + }, + }; 1;