public function get_index() { $all_rules = Authorized::rules(); /* Auth::login(1); $user = Auth::user(); echo Authorized::can('demo', 'delete') ? 'I can' : 'I cannot'; */ for ($i = 1; $i <= 4; $i++) { $user = User::find($i); echo '<h2>' . $user->name . ' (' . implode(', ', $user->roles_list) . ')</h2>'; foreach ($all_rules as $group => $actions) { echo '<ul>'; foreach ($actions as $action) { $ability = Authorized::can($group, $action, $user) ? '<span style="color:green;">can</span>' : '<span style="color:red;">cannot</span>'; echo '<li>I ' . $ability . ' access <strong>' . $group . '</strong> to <strong>' . $action . '</strong></li>'; } echo '</ul>'; } } }
<?php /** * Authorized for Laravel * * @package Bundles * @subpackage Zend_Acl * @author Teepluss <*****@*****.**> * * @see http://framework.zend.com/manual/1.12/en/zend.acl.html */ /** * Check zend acl component. */ if (!class_exists('Zend_Acl')) { throw new Exception('This bundle required Zend installed.'); } /** * Autoload Authorized. */ Autoloader::map(array('Authorized' => __DIR__ . DS . 'authorized' . EXT)); /** * Start using Authorized with authenticated user. */ Authorized::initialize(Auth::user()); /** * Auto route example to url /acl_examples. */ Route::any('acl_examples/(:any?)', array('as' => 'acl_examples', 'uses' => 'authorized::examples@(:1)', 'defaults' => 'index'));
// Add rules to access list, then give permisstion to role // $acl->add_rule($rule->group, $rule->action); // $acl->allow($role->name, $rule->group, $rule->action); // This is a short way to do things above $acl->allow($role->name, $rule->group, $rule->action, true); } } // Set current auth user to access list Authorized::as_user($user); // This is mean you allow "Unauthorized" user to access all the things. // $acl->allow('Guest', null, null); }), 'as_user' => function ($user) { // Get user roles $user_roles = $user->roles_list; // Set user roles to access list Authorized::set_user_roles($user_roles); // Hard code some role to allow/deny somewhere for some user if ($user->id == 1 and in_array('Father', $user_roles)) { // Force allow group "massage" acion "go" to the role "Father" $acl->allow('Father', 'massage', 'go'); // Force deny group "massage" acion "follow" to the role "Mother" $acl->deny('Mother', 'massage', 'follow'); } // Allow any rule to some user if ($user->email == '*****@*****.**') { return true; } // Deny any rule for some user if ($user->email == '*****@*****.**') { return false; }