From: David Thompson Date: Thu, 6 Nov 2014 21:22:34 +0000 (-0500) Subject: benefits: Don't allow non-members to access benefits page. X-Git-Tag: v0.1~23 X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=7d701e338ec70d30f307e9c92fcbf1e37447d8fd;p=org.fsf.memberdashboard.git benefits: Don't allow non-members to access benefits page. * CRM/Memberdashboard/Page/Benefits.php (CRM_Memberdashboard_Page_Benefits) [hasValidMembership]: New method. [postProcess]: Restrict POST actions to members only. [run]: Pass 'hasValidMembership' variable to smarty template. * templates/CRM/Memberdashboard/Page/Benefits.tpl: Display an access denied page if the user is a non-member. --- diff --git a/CRM/Memberdashboard/Page/Benefits.php b/CRM/Memberdashboard/Page/Benefits.php index fc84c96..7d968f8 100644 --- a/CRM/Memberdashboard/Page/Benefits.php +++ b/CRM/Memberdashboard/Page/Benefits.php @@ -27,17 +27,38 @@ class CRM_Memberdashboard_Page_Benefits extends CRM_Memberdashboard_Page { return CRM_Memberdashboard_BAO_EmailAlias::allForContact($this->contact['id']); } + function hasValidMembership() { + // Since we don't currently shut off an expired member's benefits, + // we only test that they have a membership, not that it is current. + $params = array( + 'contact_id' => $this->contact['id'] + ); + + try { + $result = civicrm_api3('membership', 'get', $params); + return $result['count'] > 0; + } catch (CiviCRM_API3_Exception $e) { + return false; + } + } + function postProcess() { $action = $_REQUEST['action']; - switch($action) { - case 'add': - $this->add(); - break; + // Short-circuit if user doesn't have a membership. + if($this->hasValidMembership()) { + switch($action) { + case 'add': + $this->add(); + break; - case 'edit': - $this->edit(); - break; + case 'edit': + $this->edit(); + break; + } + } else { + CRM_Core_Session::setStatus('Only members can have email aliases', + 'Error', 'error'); } } @@ -135,6 +156,7 @@ class CRM_Memberdashboard_Page_Benefits extends CRM_Memberdashboard_Page { $this->assign('user', $user); $this->assign('emailAliases', $emailAliases); + $this->assign('hasValidMembership', $this->hasValidMembership()); parent::run(); } diff --git a/templates/CRM/Memberdashboard/Page/Benefits.tpl b/templates/CRM/Memberdashboard/Page/Benefits.tpl index 8cfa196..607324f 100644 --- a/templates/CRM/Memberdashboard/Page/Benefits.tpl +++ b/templates/CRM/Memberdashboard/Page/Benefits.tpl @@ -1,117 +1,126 @@ -
Shop Discount
- -

- Enjoy 20% off all merchandise at the - FSF shop - using promotional code ASSOC -

- -
LibrePlanet
- - - LibrePlanet - - -

- Associate members get gratis admission to - LibrePlanet, - the FSF's annual conference. -

- -

- Use your FSF account to join a - - local free software group at LibrePlanet. +{if $hasValidMembership} +

Shop Discount
+ +

+ Enjoy 20% off all merchandise at the + FSF shop + using promotional code ASSOC +

+ +
LibrePlanet
+ + + LibrePlanet -

- -
Jabber/XMPP
- -

- Your Jabber/XMPP account is: {$user->name}@member.fsf.org -

- -

Instructions

- -

- Use your FSF username as the jabber username, and member.fsf.org as - the domain if your XMPP client supports server discovery via a DNS - SRV record lookup. Most XMPP clients support this. If your client - does not, you can use jabber.member.fsf.org as the server name. Make - sure to enable encryption: we support TLS on port 5222 only. Your - password is the same as your FSF member password. (Please report - any problems you might encounter to - sysadmin@gnu.org.) -

- -
Email Forwarding
- -

- You may maintain up to five email aliases. Each localpart name - exists in the member.fsf.org domain name and can forward to one - email address. The localpart you request might not be available. -

- -

- For example, a localpart of "yyz" with a forward to value of - "xyzzy@example.com" would cause mail sent to "yyz@member.fsf.org" to - be forwarded to "xyzzy@example.com". -

- -

- Please note that it may take up to a half hour for new forwards to - take effect. -

- -{if !empty($emailAliases)} -
- - - - - - - - - - {foreach from=$emailAliases item=alias} + +

+ Associate members get gratis admission to + LibrePlanet, + the FSF's annual conference. +

+ +

+ Use your FSF account to join a + + local free software group at LibrePlanet. + +

+ +
Jabber/XMPP
+ +

+ Your Jabber/XMPP account is: {$user->name}@member.fsf.org +

+ +

Instructions

+ +

+ Use your FSF username as the jabber username, and member.fsf.org as + the domain if your XMPP client supports server discovery via a DNS + SRV record lookup. Most XMPP clients support this. If your client + does not, you can use jabber.member.fsf.org as the server name. Make + sure to enable encryption: we support TLS on port 5222 only. Your + password is the same as your FSF member password. (Please report + any problems you might encounter to + sysadmin@gnu.org.) +

+ +
Email Forwarding
+ +

+ You may maintain up to five email aliases. Each localpart name + exists in the member.fsf.org domain name and can forward to one + email address. The localpart you request might not be available. +

+ +

+ For example, a localpart of "yyz" with a forward to value of + "xyzzy@example.com" would cause mail sent to "yyz@member.fsf.org" to + be forwarded to "xyzzy@example.com". +

+ +

+ Please note that it may take up to a half hour for new forwards to + take effect. +

+ + {if !empty($emailAliases)} + +
DeleteLocal PartForward
+ - - - + + + - {/foreach} - -
- - - - - - - DeleteLocal PartForward
+ + + {foreach from=$emailAliases item=alias} + + + + + + + + + + + + + {/foreach} + + + + +
+ {/if} + +

Add New Alias

- +
+ + + + +
-{/if} - -

Add New Alias

- -
- - - - - -
-
Member Forums
- -

- Post and participate in our - - Members-Only Forums - -

+
Member Forums
+ +

+ Post and participate in our + + Members-Only Forums + +

+{else} +
Members Only
+ +

+ Only FSF Associate Members can access this page. + Become an FSF Associate Member today! +

+{/if}