diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 7016a639f..d28d5e376 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -10,6 +10,7 @@ - add: User profile data table is now a flat table, one column for each field. - add: Posts can now have Metadata (United Knowledge) + - add: Users can now invite others to create an account (United Knowledge) - add: Calendar events now allow attachments - add: Calendar events now allow setting view permissions - add: WebGUI::Paginator now capable of more efficient SQL paginations using diff --git a/docs/upgrades/templates-7.4.0/PBtmpl00000userInvite1.tmpl b/docs/upgrades/templates-7.4.0/PBtmpl00000userInvite1.tmpl new file mode 100644 index 000000000..3d718d195 --- /dev/null +++ b/docs/upgrades/templates-7.4.0/PBtmpl00000userInvite1.tmpl @@ -0,0 +1,47 @@ +#PBtmpl00000userInvite1 +#url: userInviteTemplate +#title:User Invite Template +#menuTitle:Default User Invite Template +#namespace:userInvite +#create +
|
+ |
+
+ |
+
|
+ |
+
+ |
+
|
+ |
+
+ |
+
| + + | +
+ |
+
%s
%s!, + $i18n->get('already a member'), + $session->setting->get('userInvitationsEmailExists'), + $session->url->getBackToSiteURL(), + $i18n->get('493', 'WebGUI'); + return $session->style->userStyle($output); + } + my $myEmailAddress = $session->user->profileField('email'); + my $invitation = WebGUI::Mail::Send->create( + $session, + { + to => $hisEmailAddress, + from => $myEmailAddress, + subject => $subject, + }, + ); + + ##No sneaky attack paths... + $message = WebGUI::HTML::filter($message); + + ##Append the invitation url. + my $inviteId = $session->id->generate(); + my $inviteUrl = $session->url->append($session->url->getSiteURL, 'op=acceptInvite;code='.$inviteId); + $message .= "\n$inviteUrl\n"; + + ##Create the invitation record. + $session->db->setRow( + 'userInvitations', + 'inviteId', + { + userId => $session->user->userId, + dateSent => WebGUI::DateTime->new($session, time)->toMysqlDate, + email => $hisEmailAddress, + }, + $inviteId, + ); + + $invitation->addText($message); + $invitation->send; + + my $output = sprintf qq!%s
%s!, + $i18n->get('invitation sent'), + $session->url->getBackToSiteURL(), + $i18n->get('493', 'WebGUI'); + return $session->style->userStyle($output); + +} + +#------------------------------------------------------------------- + +=head2 www_acceptInvite ( ) + +Validate the invitation code. If valid, send the user over to the +create account page. Otherwise, scourge and flay them. + +=cut + +sub www_acceptInvite { + my $session = shift; + return $session->privilege->insufficient() if ($session->user->isInGroup(2)); + + my $i18n = WebGUI::International->new($session, 'Invite'); + + my $inviteId = $session->form->get('code'); + my ($validInviteId) = $session->db->quickArray('select userId from userInvitations where inviteId=?',[$inviteId]); + + if (!$validInviteId) { + my $output = sprintf qq!%s
%s!, + $i18n->get('invalid invite code'), + $i18n->get('invalid invite code message'), + $session->url->getBackToSiteURL(), + $i18n->get('493', 'WebGUI'); + return $session->style->userStyle($output); + } + ##Everything looks good. Sign them up! + my $auth = WebGUI::Operation::Auth::getInstance($session); + return $session->style->userStyle($auth->createAccount()); +} + +1; diff --git a/lib/WebGUI/Operation/Settings.pm b/lib/WebGUI/Operation/Settings.pm index 7095c76f1..ef569efa9 100644 --- a/lib/WebGUI/Operation/Settings.pm +++ b/lib/WebGUI/Operation/Settings.pm @@ -368,6 +368,22 @@ sub definition { defaultValue=>$session->setting->get("passiveProfilingEnabled"), extras=>'onchange="alert(\''.$i18n->get("Illegal Warning").'\')" ' }); + push(@fields, { + tab=>"user", + fieldType=>"yesNo", + name=>"userInvitationsEnabled", + label=>$i18n->get("Enable user invitations"), + hoverHelp=>$i18n->get("Enable user invitations description"), + defaultValue=>$session->setting->get("userInvitationsEnabled"), + }); + push(@fields, { + tab=>"user", + fieldType=>"textarea", + name=>"userInvitationsEmailExists", + label=>$i18n->get("user invitations email exists"), + hoverHelp=>$i18n->get("user invitations email exists description"), + defaultValue=>$session->setting->get("userInvitationsEmailExists"), + }); # auth settings my $options; foreach (@{$session->config->get("authMethods")}) { diff --git a/lib/WebGUI/Operation/Shared.pm b/lib/WebGUI/Operation/Shared.pm index e761c67a8..2f458abb7 100644 --- a/lib/WebGUI/Operation/Shared.pm +++ b/lib/WebGUI/Operation/Shared.pm @@ -68,6 +68,11 @@ is in group Admin (3). Returns the user to the List Database Links screen. push(@array, {'options.display' => ''.$i18n->get('redeem code', 'Subscription').''}); } + if ($session->setting->get('userInvitationsEnabled')) { + push @array, { + 'options.display' => sprintf('%s', $session->url->page('op=inviteUser'), $i18n->get('invite a friend')), + }; + } my %logout; $logout{'options.display'} = ''.$i18n->get(64).''; push(@array,\%logout); diff --git a/lib/WebGUI/Operation/User.pm b/lib/WebGUI/Operation/User.pm index 88e1e5670..3a7b88be7 100644 --- a/lib/WebGUI/Operation/User.pm +++ b/lib/WebGUI/Operation/User.pm @@ -39,7 +39,7 @@ Operation for creating, deleting, editing and many other user related functions. #------------------------------------------------------------------- -=head2 _submenu ( session, workarea [, title, help] ) +=head2 _submenu ( session, properties ) Internal utility routine for setting up the Admin Console for User functions. diff --git a/lib/WebGUI/ProfileField.pm b/lib/WebGUI/ProfileField.pm index 146859bcd..5096fde69 100644 --- a/lib/WebGUI/ProfileField.pm +++ b/lib/WebGUI/ProfileField.pm @@ -211,6 +211,7 @@ sub formField { my $withWrapper = shift; my $u = shift; my $skipDefault = shift; + my $assignedValue = shift; my $default; if ($skipDefault) { } @@ -231,6 +232,9 @@ sub formField { $default = WebGUI::Operation::Shared::secureEval($self->session,$properties->{dataDefault}); } $properties->{value} = $default; + if (defined $assignedValue) { + $properties->{value} = $assignedValue; + } if ($withWrapper == 1) { return WebGUI::Form::DynamicField->new($self->session,%{$properties})->displayFormWithWrapper; } elsif ($withWrapper == 2) { diff --git a/lib/WebGUI/Session/Url.pm b/lib/WebGUI/Session/Url.pm index a9a23920d..1ab69245f 100644 --- a/lib/WebGUI/Session/Url.pm +++ b/lib/WebGUI/Session/Url.pm @@ -182,6 +182,36 @@ sub gateway { return $url; } +#------------------------------------------------------------------- + +=head2 getBackToSiteURL ( ) + +Tries to return a URL to take the user back to the last page they were at before +using an operation or other function. + +=cut + +sub getBackToSiteURL { + my $self = shift; + my $url; + if (defined $self->session->asset) { + my $importNode = WebGUI::Asset->getImportNode($self->session); + my $importNodeLineage = $importNode->get("lineage"); + my $media = WebGUI::Asset->getMedia($self->session); + my $mediaLineage = $media->get("lineage"); + my $assetLineage = $self->session->asset->get("lineage"); + if ($assetLineage =~ /^$importNodeLineage/ || $assetLineage eq "000001" || $assetLineage =~ /^$mediaLineage/ || ($self->session->asset->get("state") ne "published" && $self->session->asset->get("state") ne "archived")) { + $url = WebGUI::Asset->getDefault($self->session)->getUrl; + } else { + $url = $self->session->asset->getContainer->getUrl; + } + } else { + $url = $self->session->url->page(); + } + return $url; +} + + #------------------------------------------------------------------- =head2 getRefererUrl ( ) diff --git a/lib/WebGUI/i18n/English/Invite.pm b/lib/WebGUI/i18n/English/Invite.pm new file mode 100644 index 000000000..e63a5a8d6 --- /dev/null +++ b/lib/WebGUI/i18n/English/Invite.pm @@ -0,0 +1,128 @@ +package WebGUI::i18n::English::Invite; + +our $I18N = { + + 'invite a friend title' => { + message => q|Invite A Friend|, + lastUpdated => 1181103900, + }, + + 'default invite' => { + message => q|I'm a member of a site that I thought you would find very useful, so I'm sending this invitation hoping you'll join me here. Click on the link below to register.|, + lastUpdated => 1181106351, + }, + + 'missing email' => { + message => q|The invitation cannot be sent because you did not enter an email address.|, + lastUpdated => 1181409056, + }, + + 'missing message' => { + message => q|Your invitiation must have a message.|, + lastUpdated => 1181409432, + }, + + 'missing subject' => { + message => q|Your invitation must have a subject.|, + lastUpdated => 1181409433, + }, + + 'already a member' => { + message => q|Already a member.|, + lastUpdated => 1181410226, + }, + + 'invitation sent' => { + message => q|Your invitation has been sent.|, + lastUpdated => 1181410226, + }, + + 'invalid invite code' => { + message => q|Invalid invitation code|, + lastUpdated => 1181428043, + }, + + 'invalid invite code message' => { + message => q|The invitation code in your URL is invalid.|, + lastUpdated => 1181410226, + }, + + 'already a member message' => { + message => q|The invitation code in your URL is invalid.|, + lastUpdated => 1181410226, + context => q|This message is displayed when someone who is already signed up tries to use an invite code.|, + }, + + 'invite form template title' => { + message => q|User Invitation Form Template|, + lastUpdated => 1181492752, + }, + + 'invite form template body' => { + message => q|This template is used to customize and display the form that users fill out to invite friends to create an account.|, + lastUpdated => 1181492842, + }, + + 'inviteFormError' => { + message => q|Any errors from submitting the form. Error messages are internationalized.|, + lastUpdated => 1181492842, + }, + + 'formHeader' => { + message => q|HTML code for starting the form.|, + lastUpdated => 1181492842, + }, + + 'formFooter' => { + message => q|HTML code for ending the form.|, + lastUpdated => 1181492842, + }, + + 'title' => { + message => q|An internationalized title for the form.|, + lastUpdated => 1181492842, + }, + + 'emailAddressLabel' => { + message => q|An internationalized label for the email address field.|, + lastUpdated => 1181492842, + }, + + 'emailAddressForm' => { + message => q|HTML code for the email address field.|, + lastUpdated => 1181492842, + }, + + 'subjectLabel' => { + message => q|An internationalized label for the subject field.|, + lastUpdated => 1181492842, + }, + + 'subjectForm' => { + message => q|HTML code for the subject field.|, + lastUpdated => 1181492842, + }, + + 'messageLabel' => { + message => q|An internationalized label for the message field.|, + lastUpdated => 1181492842, + }, + + 'messageForm' => { + message => q|HTML code for the message field.|, + lastUpdated => 1181492842, + }, + + 'submitButton' => { + message => q|HTML code for the submit button, with internationalized label.|, + lastUpdated => 1181492842, + }, + + 'topicName' => { + message => q|User Invitations.|, + lastUpdated => 1181493546, + }, + +}; + +1; diff --git a/lib/WebGUI/i18n/English/WebGUI.pm b/lib/WebGUI/i18n/English/WebGUI.pm index a15444f7c..09cc1797a 100644 --- a/lib/WebGUI/i18n/English/WebGUI.pm +++ b/lib/WebGUI/i18n/English/WebGUI.pm @@ -3676,10 +3676,9 @@ and tracked by WebGUI.|, lastUpdated => 1163457062, }, - 'Enable passive profiling description' => { - message => q|Used in conjunction with Metadata, this keeps a record of every wobject viewed by -a user.|, - lastUpdated => 1167189802, + 'Enable user invitations description' => { + message => q|Enable users to send emails to their friends, inviting them to come and create an account on this site.|, + lastUpdated => 1181017746, }, '164 description' => { @@ -3788,6 +3787,17 @@ Select which of the configured LDAP connections to use to authenticate users. lastUpdated => 1089039511 }, + 'Enable passive profiling description' => { + message => q|Used in conjunction with Metadata, this keeps a record of every wobject viewed by +a user.|, + lastUpdated => 1167189802, + }, + + 'Enable user invitations' => { + message => q|Enable user invitations?|, + lastUpdated => 1181017730 + }, + 'Illegal Warning' => { message => q|Enabling this feature is illegal in some countries, like Australia. In addition, some countries require you to add a warning to your site if you use this feature. Consult your local authorities for local laws. Plain Black Corporation is not responsible for your illegal activities, regardless of ignorance or malice.|, lastUpdated => 1089039511 @@ -4077,6 +4087,21 @@ Get a copy of wget and use this:wget -p -r --html-extension -k http://the
lastUpdated => 1161388472,
},
+ 'invite a friend' => {
+ message => q|Invite a friend|,
+ lastUpdated => 1181019679,
+ },
+
+ 'user invitations email exists' => {
+ message => q|Email exists message|,
+ lastUpdated => 1181277915
+ },
+
+ 'user invitations email exists description' => {
+ message => q|This is the message displayed to users who try to invite someone whose email address already exists in the system.|,
+ lastUpdated => 1181277914,
+ },
+
};
1;