21293 Posts in 5733 Topics by 2602 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1162 Views |
-
How to have payed Members only pages?

31 January 2010 at 11:49pm
I'm really excited about using SilverStripe for my web development projects, but I have one site though which I'm not sure how easy it would be to accomplish in SS.
It is an educational website, where you have to pay a yearly/monthly fee to view most of the pages.
The main aspect I am worried about is how to deal with "members" in SilverStripe. I need the ability:
- for members to register and pay and have immediate access to members only pages
- need to be able to have different categories of membership, some will get it cheaper, some for free etcCan someone please point me in the right direction for how I could accomplish this in SilverStripe? Is it possible without too much extra coding?
Many Thanks!
James -
Re: How to have payed Members only pages?

5 February 2010 at 4:09pm Last edited: 5 February 2010 4:10pm
Hi
Sure you can do this with SS.
- First create a registration form (we will need to create the logic to connect to a online payment gateway, or use payment module).
- Once you sorted payment, you need to create a new member and save it into a group (you can create different groups).
function registerAction($data,$form) { //you call this function when user submit registation form (or after you check payment)
$member=DataObject::get_one('Member',"Email = '" . mysql_real_escape_string($data['Email']) . "'"); //check if the email is in the DB already
if(!$member) { // if email is not in DB create a new member
$member = new Member();
$form->saveInto($member); //insert new member value from the form
$member->RegistrationHash = md5(uniqid(rand(), true));
$member->write(); //save new member
}
$member->Groups()->add('myGroup');- Add a check box to your pages so you can choose if the page is members only.
Page.phpfunction getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.Main", new CheckboxField('MemberOnly', 'For member only?'), 'Content');
...- create a function in Page.php to check if the page is members only and check if the visitor is logged in.
Page.phpfunction canView($member = null) { // this function gets called when you load the page.
if($this->MemberOnly) {
$member = Member::currentUser();
if (!$member) return false;
}
return parent::canView($member);
} -
Re: How to have payed Members only pages?

6 February 2010 at 2:21am
Amazing! I shall give this a go, thank you very much!
| 1162 Views | ||
|
Page:
1
|
Go to Top |

