Skip to content

Commit

Permalink
feat(MemberApprovalController): Add 'redirect_to_admin' config.
Browse files Browse the repository at this point in the history
- Wrap $Content in <p> tags.
- Add fullstop to 'ALREADYAPPROVEDNOTE' text.
- Add LiteralField # anchor. This is to ensure future breakage is unlikely.
- Update README.md to document configuration behaviour.
  • Loading branch information
Jake Bentvelzen committed Feb 1, 2017
1 parent 81bdcfa commit b403d2c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ class MemberExtension extends DataExtension {
}
```

Configuration
------------
```yml
MemberApprovalController:
# Redirect the user to the 'admin/Security' member edit page instead
# of immediately approving after visiting the approve link.
redirect_to_admin: false
```
Known Issues
------------
[Issue Tracker](http://github.com/ajshort/silverstripe-memberprofiles/issues)
27 changes: 24 additions & 3 deletions code/controllers/MemberApprovalController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ class MemberApprovalController extends Page_Controller {
'index'
);

/**
* Redirect the user to the 'admin/Security' member edit page instead
* of immediately approving after visiting the approve link.
*
* @config
* @var boolean
*/
private static $redirect_to_admin = false;

public function index($request) {
$id = $request->param('ID');
$token = $request->getVar('token');
Expand All @@ -31,25 +40,37 @@ public function index($request) {
}

if ($token != $member->ValidationKey) {
$this->httpError(400, 'An invalid token was specified.');
return $this->httpError(400, 'An invalid token was specified.');
}

if (!$member->ValidationKey) {
return $this->httpError(400, 'Not a MemberProfilePage member.');
}

if (!$member->NeedsApproval) {
$title = _t('MemberProfiles.ALREADYAPPROVED', 'Already Approved');
$content = _t('MemberProfiles.ALREADYAPPROVEDNOTE', 'This member has already been approved');
$content = _t('MemberProfiles.ALREADYAPPROVEDNOTE', 'This member has already been approved.');

return $this->render(array(
'Title' => $title,
'Content' => "<p>$content</p>"
));
}

if ($this->config()->redirect_to_admin) {
$controller = singleton('SecurityAdmin');
if (!$controller->canView()) {
return Security::permissionFailure();
}
return $controller->Link('EditForm/field/Members/item/'.$member->ID.'/edit#MemberProfileRegistrationApproval');
}

$member->NeedsApproval = false;
$member->write();

$title = _t('MemberProfiles.MEMBERAPPROVED', 'Member Approved');
$content = _t('MemberProfiles.MEMBERAPPROVEDCONTENT', 'The member "%s" has been approved and can now log in.');
$content = sprintf($content, Convert::raw2xml("$member->Name <$member->Email>"));
$content = '<p>'.sprintf($content, Convert::raw2xml("$member->Name <$member->Email>")).'</p>';

return $this->render(array(
'Title' => $title,
Expand Down
2 changes: 2 additions & 0 deletions code/extensions/MemberProfileExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ public function updateCMSFields(FieldList $fields) {
);

$fields->addFieldsToTab('Root.Main', array(
// ApprovalAnchor is used by MemberApprovalController (2017-02-01)
new LiteralField('ApprovalAnchor', "<div id=\"MemberProfileRegistrationApproval\"></div>"),
new HeaderField('ApprovalHeader', _t('MemberProfiles.REGAPPROVAL', 'Registration Approval')),
new LiteralField('ApprovalNote', "<p>$note</p>"),
new DropdownField('NeedsApproval', '', array(
Expand Down

0 comments on commit b403d2c

Please sign in to comment.