Subject:*
<
Name/Email:*
<
Message Icon:*
<
Select*
<
Message:*
<



Click the Preview to see the content in action.
Options:*
<
Confirmation Code*
<
3 - 0 = ?  
Input the result from the expression
Maximum attempts you can try: 10
*
<
     
__construct(); } function __construct($perm_name){ global $xoopsUser; $uid = (is_object($xoopsUser)) ? intval($xoopsUser->uid()): 0; $groups = (is_object($xoopsUser)) ? $xoopsUser->getGroups(): XOOPS_GROUP_ANONYMOUS; $module_handler =& xoops_gethandler('module'); $module =& $module_handler->getByDirname('replay'); $mid = $module->getVar('mid'); $gperm_handler =& xoops_gethandler('groupperm'); $this->isAdmin = $gperm_handler->checkRight('system_admin', $uid, $groups); $this->view = $gperm_handler->checkRight($perm_name, 1 , $groups, $mid); $this->submit = $gperm_handler->checkRight($perm_name, 2 , $groups, $mid); $this->edit = $gperm_handler->checkRight($perm_name, 3 , $groups, $mid); $this->delete = $gperm_handler->checkRight($perm_name, 4 , $groups, $mid); $this->download = $gperm_handler->checkRight($perm_name, 5 , $groups, $mid); $this->vote = $gperm_handler->checkRight($perm_name, 6 , $groups , $mid); $this->edit_others = $gperm_handler->checkRight($perm_name, 7 , $groups, $mid); $this->delete_others = $gperm_handler->checkRight($perm_name, 8 , $groups, $mid); } function isAdmin() { return $this->isAdmin; } function canView() { return $this->view; } function canSubmit() { return $this->submit; } function canEdit() { return $this->edit; } function canDelete() { return $this->delete; } function canDownload() { return $this->download; } function canVote() { return $this->vote; } function canEdit_others() { return $this->edit_others; } function canDelete_others() { return $this->delete_others; } } [/code][/quote]" />

Creating my own permissions class for my module.
by zite83 on 2010/8/13 21:19:38

This is what I found at Adding Group Permissions and starting playing around with it in some of my test modules.


le="color: #000000"><?php $gperm_handler =& xoops_gethandler('groupperm'); $cando = $gperm_handler->checkRight($perm_name, 1, $groups, $mod_id) if ($cando){ echo 'true'; }else{ echo 'false'; }


What I wanted to come up with was a simple class that I could check all permissions for that user through out my module. What I came up with seems to work, but I'm not that great with security and just wanted to know if this is safe way to check my modules permissions or is there another direction I should go.

le="color: #000000"><?php //Create new object while passing what I want to check $replayPermissions = new replayPermissions('replay_permissions'); if ($replayPermissions->canDelete()){ echo 'True'; }else{ echo 'False'; }



Class itself, just to note is only checking one type of permissions "replay_permissions" that is for module wide and not just one specific id or item.

le="color: #000000"><?php if (!defined('XOOPS_ROOT_PATH')) { die("XOOPS root path not defined"); } class replayPermissions { private $isAdmin = false; private $view = false; private $submit = false; private $edit = false; private $delete = false; private $download = false; private $vote = false; private $edit_others = false; private $delete_others = false; function replayPermissions() { $this->__construct(); } function __construct($perm_name){ global $xoopsUser; $uid = (is_object($xoopsUser)) ? intval($xoopsUser->uid()): 0; $groups = (is_object($xoopsUser)) ? $xoopsUser->getGroups(): XOOPS_GROUP_ANONYMOUS; $module_handler =& xoops_gethandler('module'); $module =& $module_handler->getByDirname('replay'); $mid = $module->getVar('mid'); $gperm_handler =& xoops_gethandler('groupperm'); $this->isAdmin = $gperm_handler->checkRight('system_admin', $uid, $groups); $this->view = $gperm_handler->checkRight($perm_name, 1 , $groups, $mid); $this->submit = $gperm_handler->checkRight($perm_name, 2 , $groups, $mid); $this->edit = $gperm_handler->checkRight($perm_name, 3 , $groups, $mid); $this->delete = $gperm_handler->checkRight($perm_name, 4 , $groups, $mid); $this->download = $gperm_handler->checkRight($perm_name, 5 , $groups, $mid); $this->vote = $gperm_handler->checkRight($perm_name, 6 , $groups , $mid); $this->edit_others = $gperm_handler->checkRight($perm_name, 7 , $groups, $mid); $this->delete_others = $gperm_handler->checkRight($perm_name, 8 , $groups, $mid); } function isAdmin() { return $this->isAdmin; } function canView() { return $this->view; } function canSubmit() { return $this->submit; } function canEdit() { return $this->edit; } function canDelete() { return $this->delete; } function canDownload() { return $this->download; } function canVote() { return $this->vote; } function canEdit_others() { return $this->edit_others; } function canDelete_others() { return $this->delete_others; } }

Who's Online

102 user(s) are online (68 user(s) are browsing Support Forums)


Members: 0


Guests: 102


more...

Donat-O-Meter

Stats
Goal: $15.00
Due Date: Jul 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $15.00
Make donations with PayPal!

Latest GitHub Commits