From cbf68980daf220aa59c534346689367903c0f9cd Mon Sep 17 00:00:00 2001 From: nyeholt Date: Thu, 19 Aug 2010 21:13:30 +1000 Subject: [PATCH] FEATURE: Added ability for cms users to select whether or not users should 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 --- README.md | 11 ++++++++++- code/MemberProfilePage.php | 34 ++++++++++++++++++++++++++++++++++ lang/en_US.php | 2 ++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7502b4d0..c3d25614 100755 --- a/README.md +++ b/README.md @@ -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) \ No newline at end of file +[Issue Tracker](http://github.com/ajshort/silverstripe-memberprofiles/issues) diff --git a/code/MemberProfilePage.php b/code/MemberProfilePage.php index 118f880b..d9070036 100755 --- a/code/MemberProfilePage.php +++ b/code/MemberProfilePage.php @@ -25,6 +25,7 @@ class MemberProfilePage extends Page implements PermissionProvider { 'AllowRegistration' => 'Boolean', 'AllowProfileEditing' => 'Boolean', 'AllowAdding' => 'Boolean', + 'RegistrationRedirect' => 'Boolean', 'EmailValidation' => 'Boolean', 'EmailFrom' => 'Varchar(255)', @@ -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' ); @@ -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'); @@ -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(); } @@ -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'), diff --git a/lang/en_US.php b/lang/en_US.php index 3204a9ea..380ec543 100644 --- a/lang/en_US.php +++ b/lang/en_US.php @@ -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.';