Skip to content

Commit

Permalink
FEATURE: Added ability for cms users to select whether or not users s…
Browse files Browse the repository at this point in the history
…hould be redirected after they have finished the registration process instead of seeing the generic message. Users can either select a page from the SiteTree, or insert a ?BackURL=/some/url parameter to links to the member profile page
  • Loading branch information
nyeholt committed Aug 19, 2010
1 parent 3f255c1 commit cbf6898
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ account you can do so via the "Security" CMS section - just click on a member
and there will be a dropdown down the bottom allowing you to perform these
actions.

### Template Usage
You can link to the profile page with the optional ?BackURL= parameter
which will set a URL that the user will be redirected to after they complete
registration. This requires the "RegistrationRedirect" property to be set
on the After Registration tab.

If you like, you can manually set a redirection target by setting
Session::set('MemberProfile.REDIRECT') to a URL value.

Known Issues
------------
[Issue Tracker](http://github.com/ajshort/silverstripe-memberprofiles/issues)
[Issue Tracker](http://github.com/ajshort/silverstripe-memberprofiles/issues)
34 changes: 34 additions & 0 deletions code/MemberProfilePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class MemberProfilePage extends Page implements PermissionProvider {
'AllowRegistration' => 'Boolean',
'AllowProfileEditing' => 'Boolean',
'AllowAdding' => 'Boolean',
'RegistrationRedirect' => 'Boolean',

'EmailValidation' => 'Boolean',
'EmailFrom' => 'Varchar(255)',
Expand All @@ -34,6 +35,10 @@ class MemberProfilePage extends Page implements PermissionProvider {
'ConfirmationContent' => 'HTMLText'
);

public static $has_one = array(
'PostRegistrationTarget' => 'SiteTree',
);

public static $has_many = array (
'Fields' => 'MemberProfileField'
);
Expand Down Expand Up @@ -130,6 +135,17 @@ public function getCMSFields() {
);
}

$fields->addFieldToTab(
'Root.Content.AfterRegistration',
new CheckboxField('RegistrationRedirect', _t('MemberProfiles.REDIRECT_AFTER_REG', 'Redirect after registration?')),
'AfterRegistrationContent'
);
$fields->addFieldToTab(
'Root.Content.AfterRegistration',
new TreeDropdownField('PostRegistrationTargetID', _t('MemberProfiles.REDIRECT_TARGET', 'Redirect to page'), 'SiteTree'),
'AfterRegistrationContent'
);

$fields->removeFieldFromTab('Root.Content.Main', 'Title');
$fields->removeFieldFromTab('Root.Content.Main', 'Content');

Expand Down Expand Up @@ -328,6 +344,9 @@ class MemberProfilePage_Controller extends Page_Controller {
* @return array
*/
public function index() {
if (isset($_GET['BackURL'])) {
Session::set('MemberProfile.REDIRECT', $_GET['BackURL']);
}
return Member::currentUser() ? $this->indexProfile() : $this->indexRegister();
}

Expand Down Expand Up @@ -419,6 +438,21 @@ public function register($data, Form $form) {
$member->logIn();
}

if ($this->RegistrationRedirect) {
if ($this->PostRegistrationTargetID) {
$this->redirect($this->PostRegistrationTarget()->Link());
return;
}

if ($sessionTarget = Session::get('MemberProfile.REDIRECT')) {
Session::clear('MemberProfile.REDIRECT');
if (Director::is_site_url($sessionTarget)) {
$this->redirect($sessionTarget);
return;
}
}
}

return array (
'Title' => $this->obj('AfterRegistrationTitle'),
'Content' => $this->obj('AfterRegistrationContent'),
Expand Down
2 changes: 2 additions & 0 deletions lang/en_US.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
'Singular name of the object, used in dropdowns and to generally identify a single object in the interface'
);
$lang['en_US']['MemberProfiles']['AFTERRED'] = 'After Registration';
$lang['en_US']['MemberProfiles']['REDIRECT_AFTER_REG'] = 'Redirect after registration?';
$lang['en_US']['MemberProfiles']['REDIRECT_TARGET'] = 'Redirect to page';
$lang['en_US']['MemberProfiles']['ALLOWREG'] = 'Allow registration via this page';
$lang['en_US']['MemberProfiles']['CANNOTCONFIRMLOGGEDIN'] = 'You cannot confirm account while you are logged in.';
$lang['en_US']['MemberProfiles']['CANNOTREGPLEASELOGIN'] = 'You cannot register on this profile page. Please login to edit your profile.';
Expand Down

0 comments on commit cbf6898

Please sign in to comment.