Membership Plugin - problem with creating access to sections
4 posts by 2 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: January 21, 2014 (RSS)
By JeffC - January 20, 2014
I would like to use the membership plugin to allow users to create a cms account and create one page in a section on my website. The table name is 'friends' and they should have access to create and edit one page only.
The user is created but access is not granted in the cms. When I look at the user accounts area of cms the section access is set as 'none'. If I manually change that to 'by section' I can see that the friends table is set to 'Author' and the max records is set to '1' but how do I automatically set this up so that section access is set to 'by section' when the new account is added?
Furthermore when a new account is set up via the membership plugin no expiry date is set. I would like the check box to be set as 'account never expires'
This is the code I am using:
// set access rights for CMS so new users can access some CMS sections
$setAccessRights = true; // set to true and set access tables below to use this
if ($setAccessRights && accountsTable() == "accounts") { // this is only relevant if you're adding users to the CMS accounts table
// NOTE: You can repeat this block to grant access to multiple sections
mysql_insert('_accesslist', array(
'userNum' => $userNum,
'tableName' => 'friends', // insert tablename you want to grant access to, or 'all' for all sections
'accessLevel' => '6', // access level allowed: 0=none, 6=author, 9=editor
'maxRecords' => '1', // max listings allowed (leave blank for unlimited)
'randomSaveId' => '123456789', // ignore - for internal use
));
Note, when I first installed the membership plugin I hadn't realised I was running cms 2.51 and it requires min 2.52. I have now upgraded cms to 2.53 but still experiencing the problem.
By Chris - January 20, 2014 - edited: January 20, 2014
Hi Jeffncou,
I looked at the rows that CMS Builder creates when you set a user up with Access = By Section and one of the section's to Author with Max Records = 1. It seems that there's a row with tableName = 'all' and accessLevel = '1', so I'd recommend inserting that row to see if that clears up the problem. Add this first _accesslist mysql_insert above your existing _accesslist mysql_insert (which I have not changed). New code in red:
// Access = By Section
mysql_insert('_accesslist', array(
'userNum' => $userNum,
'tableName' => 'all', // insert tablename you want to grant access to, or 'all' for all sections
'accessLevel' => '1', // access level allowed: 0=none, 6=author, 9=editor
'maxRecords' => '', // max listings allowed (leave blank for unlimited)
'randomSaveId' => '123456789', // ignore - for internal use
));
// friends = Author (max records = 1)
mysql_insert('_accesslist', array(
'userNum' => $userNum,
'tableName' => 'friends', // insert tablename you want to grant access to, or 'all' for all sections
'accessLevel' => '6', // access level allowed: 0=none, 6=author, 9=editor
'maxRecords' => '1', // max listings allowed (leave blank for unlimited)
'randomSaveId' => '123456789', // ignore - for internal use
));
You can set the Never Expires checkbox for new users by adding a line of code before the account record is inserted in the accounts table. There's only one new line of code here, but I'm showing the nearby lines of code for context. New code in red:
$colsToValues['password'] = $passwordHash;
// ... add more form fields here by copying the above line!
$colsToValues['neverExpires'] = '1';
$userNum = mysql_insert(accountsTable(), $colsToValues, true);
Please let me know if this helps!
Chris
By JeffC - January 21, 2014 - edited: January 21, 2014
Hi Chris
The 'Never Expires' part of the problem has been solved - thank you
The Access By Section solution that you provided hasn't fixed my problem. After creating a new user using user-signup.php the access granted is still 'none' in the cms. Any other ideas?
Thanks
Jeff
CORRECTION: Your solution to my 'Access By Section' problem does work with a small amendment. In your supplied code below change maxRecords from blank to 1
// Access = By Section
mysql_insert('_accesslist', array(
'userNum' => $userNum,
'tableName' => 'all', // insert tablename you want to grant access to, or 'all' for all sections
'accessLevel' => '1', // access level allowed: 0=none, 6=author, 9=editor
'maxRecords' => '1', // max listings allowed (leave blank for unlimited)
'randomSaveId' => '123456789', // ignore - for internal use
));
Thanks for your help.
By Chris - January 21, 2014
Hi Jeff,
Great to hear! Let us know if you have any more questions! :)
Chris