当前位置: 首页>>代码示例>>PHP>>正文


PHP Role类代码示例

本文整理汇总了PHP中Role的典型用法代码示例。如果您正苦于以下问题:PHP Role类的具体用法?PHP Role怎么用?PHP Role使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Role类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setupFoundorAndBaseRolsPermission

 public function setupFoundorAndBaseRolsPermission()
 {
     // Create Roles
     $founder = new Role();
     $founder->name = 'Founder';
     $founder->save();
     $admin = new Role();
     $admin->name = 'Admin';
     $admin->save();
     // Create User
     $user = User::create(['github_id' => 324764, 'github_url' => 'https://github.com/summerblue', 'name' => 'summerblue']);
     // Attach Roles to user
     $user->roles()->attach($founder->id);
     // Create Permissions
     $manageTopics = new Permission();
     $manageTopics->name = 'manage_topics';
     $manageTopics->display_name = 'Manage Topics';
     $manageTopics->save();
     $manageUsers = new Permission();
     $manageUsers->name = 'manage_users';
     $manageUsers->display_name = 'Manage Users';
     $manageUsers->save();
     // Assign Permission to Role
     $founder->perms()->sync([$manageTopics->id, $manageUsers->id]);
     $admin->perms()->sync([$manageTopics->id]);
 }
开发者ID:bobken,项目名称:phphub,代码行数:26,代码来源:2014_08_13_130603_entrust_setup_tables.php

示例2: run

 public function run()
 {
     DB::table('roles')->truncate();
     $faker = Faker\Factory::create();
     $adminRole = new Role();
     $adminRole->name = 'admin';
     $adminRole->save();
     $moderatorRole = new Role();
     $moderatorRole->name = 'moderator';
     $moderatorRole->save();
     $authorRole = new Role();
     $authorRole->name = 'author';
     $authorRole->save();
     $user = User::where('username', '=', 'ad_user')->first();
     $user->attachRole($adminRole);
     //        $user = User::where('username','=','ad_user1')->first();
     //        $user->attachRole( $adminRole );
     $m = User::where('username', '=', 'moderator')->first();
     $m->attachRole($moderatorRole);
     //        $m = User::where('username','=','mo_user1')->first();
     //        $m->attachRole($moderatorRole);
     $a = User::where('username', '=', 'author')->first();
     $a->attachRole($authorRole);
     //        $a  = User::where('username','=','au_user1')->first();
     //        $a->attachRole($authorRole);
 }
开发者ID:christiannwamba,项目名称:laravel-site,代码行数:26,代码来源:RolesTableSeeder.php

示例3: getMostApplyingRule

 /**
  * Returns the rule, that applies most to $role and $resource
  *
  * @param \gatekeeper\Role $role Role to search for
  * @param \gatekeeper\Resource $resource Resource to search for
  * @return \gatekeeper\Rule
  * @throws \gatekeeper\ThereIsNoApplyingRuleException if the is no applying
  *		rule
  */
 public function getMostApplyingRule(Role $role, Resource $resource)
 {
     do {
         $roleId = $role->getRoleId();
         foreach ($this->getRules() as $rule) {
             if ($rule->getRoleId() !== $roleId) {
                 continue;
             }
             $tmpResource = $resource;
             do {
                 /// Perhaps breadth first search?!
                 $resourceId = $tmpResource->getResourceId();
                 if ($rule->getResourceId() === $resourceId) {
                     return $rule;
                 }
                 try {
                     $tmpResource = $tmpResource->getParentResource();
                 } catch (HasNoParentResourceException $e) {
                     $tmpResource = null;
                 }
             } while ($tmpResource !== null);
         }
         try {
             $role = $role->getParentRole();
         } catch (HasNoParentRoleException $e) {
             $role = null;
         }
     } while ($role !== null);
     throw new ThereIsNoApplyingRuleException();
 }
开发者ID:heho,项目名称:gatekeeper,代码行数:39,代码来源:RuleRepository.php

示例4: run

 public function run()
 {
     $adminEmail = Config::get('madison.seeder.admin_email');
     $admin = new Role();
     $admin->name = 'Admin';
     $admin->save();
     $independent_sponsor = new Role();
     $independent_sponsor->name = 'Independent Sponsor';
     $independent_sponsor->save();
     $permIds = array();
     foreach ($this->adminPermissions as $permClass => $data) {
         $perm = new Permission();
         foreach ($data as $key => $val) {
             $perm->{$key} = $val;
         }
         $perm->save();
         $permIds[] = $perm->id;
     }
     $admin->perms()->sync($permIds);
     $user = User::where('email', '=', $adminEmail)->first();
     $user->attachRole($admin);
     $createDocPerm = new Permission();
     $createDocPerm->name = "independent_sponsor_create_doc";
     $createDocPerm->display_name = "Independent Sponsoring";
     $createDocPerm->save();
     $independent_sponsor->perms()->sync(array($createDocPerm->id));
 }
开发者ID:krues8dr,项目名称:madison,代码行数:27,代码来源:RbacSeeder.php

示例5: fire

 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     if ($this->argument('name')) {
         $name = trim($this->argument('name'));
         $role = Role::where('name', '=', $name)->first();
         if ($role) {
             $this->info("Role '{$name}' already exists.");
             exit;
         }
         $role = new Role();
         $role->name = $name;
         $role->save();
         $this->info('Role saved successfully.');
     } else {
         $roles = Role::all();
         $this->info('Existing Roles:');
         foreach ($roles as $role) {
             $this->info($role->name);
         }
         $continue = $this->ask("Would you still like to add a new role? (yes/no)");
         if ('yes' === trim(strtolower($continue))) {
             $name = $this->ask("What's the new role's name?");
             $role = new Role();
             $role->name = trim($name);
             $role->save();
             $this->info('Role saved successfully.');
         }
     }
 }
开发者ID:krues8dr,项目名称:madison,代码行数:34,代码来源:CreateRole.php

示例6: setupDatabases

 public function setupDatabases()
 {
     $name = $this->call('migrate', array('--path' => 'app/database/migrations/setup/'));
     $name = $this->call('migrate');
     // create the roles
     $roles = ['Admin', 'Writer', 'Reader'];
     foreach ($roles as $r) {
         $role = Role::whereName($r)->first();
         if ($role == null) {
             $role = new Role();
             $role->name = $r;
             $role->display_name = $r;
             $role->save();
             $this->info("{$role->id} Creating Role:{$r}");
         }
     }
     foreach (User::all() as $u) {
         $this->info("{$u->id} : user: {$u->username}");
     }
     // add core assets
     $m = Asset::findFromTag('missing-user-image');
     if ($m == NULL) {
         $m = new Asset();
         $m->path = "assets/content/uploads";
         $m->saveLocalFile(public_path('assets/content/common/missing/profile-default.png'), 'profile-default.png');
         $m->tag = 'missing-user-image';
         $m->shared = 1;
         $m->type = Asset::ASSET_TYPE_IMAGE;
         $m->save();
     }
     $this->comment("****\tAll Databases for Halp have been setup :-) \t****");
     return;
 }
开发者ID:vanderlin,项目名称:halp,代码行数:33,代码来源:CreateDatabases.php

示例7: fire

 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     //1.  Create Independent Sponsor role
     $sponsorRole = Role::where('name', '=', 'Independent Sponsor')->first();
     if (!$sponsorRole) {
         $sponsorRole = new Role();
         $sponsorRole->name = "Independent Sponsor";
         $sponsorRole->save();
         $this->info("Independent Sponsor role created.");
     } else {
         $this->info("Independent Sponsor role exists.");
     }
     //2. Add Independent Sponsor role to all Admins
     $adminRole = Role::where('name', 'Admin')->first();
     $admins = $adminRole->users()->get();
     foreach ($admins as $admin) {
         $this->info('--------------------------------------------------');
         if ($admin->hasRole($sponsorRole->name)) {
             $this->info($admin->email . " already set as Independent Sponsor");
         } else {
             $admin->attachRole($sponsorRole);
             $this->info($admin->email . " set as " . $sponsorRole->name);
         }
         //3.  Remove Admin role from non-admin users
         $stayAdmin = strtolower(trim($this->ask("Keep " . $admin->email . " as an Admin? (yes/no)")));
         if ($stayAdmin != 'yes') {
             $admin->detachRole($adminRole);
             $this->info("Removed Admin role from " . $admin->email);
         } else {
             $this->info($admin->email . " still set as an Admin.");
         }
     }
 }
开发者ID:DCgov,项目名称:dc-madison,代码行数:38,代码来源:dbUpdateGroups.php

示例8: become

 /**
  * Become a given role.
  */
 function become($args)
 {
     parent::validate(true, true);
     $user =& Request::getUser();
     if (!$user) {
         Request::redirect(null, null, 'index');
     }
     switch (array_shift($args)) {
         case 'submitter':
             $roleId = ROLE_ID_SUBMITTER;
             $setting = 'enableSubmit';
             $deniedKey = 'user.noRoles.enableSubmitClosed';
             break;
         default:
             Request::redirect('index');
     }
     $site =& Request::getSite();
     if ($site->getSetting($setting)) {
         $role = new Role();
         $role->setRoleId($roleId);
         $role->setUserId($user->getId());
         $roleDao =& DAORegistry::getDAO('RoleDAO');
         $roleDao->insertRole($role);
         Request::redirectUrl(Request::getUserVar('source'));
     } else {
         $templateMgr =& TemplateManager::getManager();
         $templateMgr->assign('message', $deniedKey);
         return $templateMgr->display('common/message.tpl');
     }
 }
开发者ID:jalperin,项目名称:harvester,代码行数:33,代码来源:UserHandler.inc.php

示例9: run

 public function run()
 {
     // create default user asset
     $asset = Asset::where('filename', '=', 'default.png')->first();
     if ($asset == NULL) {
         $asset = new Asset();
         $asset->filename = 'default.png';
         $asset->path = 'assets/content/users';
         $asset->save();
     }
     $admin = Role::where('name', '=', 'Admin')->first();
     // create default roles
     if ($admin == NULL) {
         $admin = new Role();
         $admin->name = 'Admin';
         $admin->save();
     }
     $adminUser = User::where('username', '=', 'admin')->first();
     if ($adminUser != NULL) {
         echo "Admin User Already Exsit";
     } else {
         $adminUser = new User();
         $adminUser->username = 'admin';
         $adminUser->email = 'admin@admin.com';
         $adminUser->password = 'admin';
         $adminUser->password_confirmation = 'admin';
         $adminUser->confirmation_code = md5(uniqid(mt_rand(), true));
         if ($adminUser->save()) {
             $adminUser->attachRole($admin);
             echo "Admin User Created";
         }
     }
 }
开发者ID:vanderlin,项目名称:Gear2,代码行数:33,代码来源:UserTableSeeder.php

示例10: run

 public function run()
 {
     if (file_exists(app_path() . '/config/creds.yml')) {
         $creds = yaml_parse_file(app_path() . '/config/creds.yml');
     } else {
         $creds = array('admin_email' => 'admin@example.com');
     }
     $admin = new Role();
     $admin->name = 'Admin';
     $admin->save();
     $independent_sponsor = new Role();
     $independent_sponsor->name = 'Independent Sponsor';
     $independent_sponsor->save();
     $permIds = array();
     foreach ($this->adminPermissions as $permClass => $data) {
         $perm = new Permission();
         foreach ($data as $key => $val) {
             $perm->{$key} = $val;
         }
         $perm->save();
         $permIds[] = $perm->id;
     }
     $admin->perms()->sync($permIds);
     $user = User::where('email', '=', $creds['admin_email'])->first();
     $user->attachRole($admin);
     $createDocPerm = new Permission();
     $createDocPerm->name = "independent_sponsor_create_doc";
     $createDocPerm->display_name = "Independent Sponsoring";
     $createDocPerm->save();
     $independent_sponsor->perms()->sync(array($createDocPerm->id));
 }
开发者ID:iaincollins,项目名称:madison,代码行数:31,代码来源:RbacSeeder.php

示例11: setupFoundorAndBaseRolsPermission

 public function setupFoundorAndBaseRolsPermission()
 {
     // Create Roles
     $founder = new Role();
     $founder->name = 'Founder';
     $founder->save();
     $admin = new Role();
     $admin->name = 'Admin';
     $admin->save();
     // Create User
     $user = User::create(['id' => 1, 'username' => 'zhanglei', 'password' => Hash::make('zhanglei'), 'email' => 'fcode520@gmail.com']);
     // Attach Roles to user
     $user->roles()->attach($founder->id);
     // Create Permissions
     $manageTopics = new Permission();
     $manageTopics->name = 'manage_topics';
     $manageTopics->display_name = 'Manage Topics';
     $manageTopics->save();
     $manageUsers = new Permission();
     $manageUsers->name = 'manage_users';
     $manageUsers->display_name = 'Manage Users';
     $manageUsers->save();
     // Assign Permission to Role
     $founder->perms()->sync([$manageTopics->id, $manageUsers->id]);
     $admin->perms()->sync([$manageTopics->id]);
 }
开发者ID:xiao-hu00,项目名称:phphub,代码行数:26,代码来源:2014_08_13_130603_entrust_setup_tables.php

示例12: run

 public function run()
 {
     /**
      *  $userModel = User::find(1);
      *  $userModel->detachRoles($userModel->roles);
      */
     DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     DB::table('roles')->truncate();
     DB::table('roles')->delete();
     DB::table('assigned_roles')->truncate();
     DB::table('assigned_roles')->delete();
     DB::table('users')->truncate();
     DB::table('users')->delete();
     User::create(array('firstname' => 'Администратор', 'email' => 'admin@treadtrack.net', 'password' => Hash::make('123456')));
     User::create(array('firstname' => 'Богдан', 'email' => 'ukrtvsat@ukr.net', 'password' => Hash::make('123456')));
     $role = new Role();
     $role->name = 'Customer';
     $role->save();
     $role = new Role();
     $role->name = 'Admin';
     $role->save();
     $admin = User::where('firstname', '=', 'Администратор')->first();
     $admin->attachRole($role);
     $user = User::where('firstname', '=', 'Богдан')->first();
     $user->attachRole($role);
     DB::statement('SET FOREIGN_KEY_CHECKS=1;');
 }
开发者ID:Rotron,项目名称:shop,代码行数:27,代码来源:UserTableSeeder.php

示例13: OnPageLoad

    function OnPageLoad()
    {
        if (is_object($this->data_object)) {
            echo new XhtmlElement('h1', Html::Encode('Delete role: ' . $this->data_object->getRoleName()));
        } else {
            echo new XhtmlElement('h1', 'Delete role');
            $this->deleted = true;
        }
        if ($this->deleted) {
            ?>
			<p>The role has been deleted.</p>
			<p><a href="roles.php">View all roles</a></p>
			<?php 
        } else {
            ?>
				<p>Deleting a role cannot be undone.</p>
				<p>Are you sure you want to delete this role?</p>
				<form method="post" class="deleteButtons">
				<div>
				<input type="submit" value="Delete role" name="delete" />
				<input type="submit" value="Cancel" name="cancel" />
				</div>
				</form>
				<?php 
            $this->AddSeparator();
            require_once 'stoolball/user-edit-panel.class.php';
            $panel = new UserEditPanel($this->GetSettings(), 'this role');
            $panel->AddLink('edit this role', "role.php?item=" . $this->data_object->getRoleId());
            echo $panel;
        }
    }
开发者ID:stoolball-england,项目名称:stoolball-england-website,代码行数:31,代码来源:roledelete.php

示例14: display

 public function display()
 {
     $rolelist = new Template();
     $rolelist->load("role_list");
     $actions = ActionList::get("rolelist");
     if (isset($_POST['insert'])) {
         $role = new Role();
         $role->name = $_POST['insert'];
         $role->insert();
     }
     if (isset($_GET['delete'])) {
         $role = new Role();
         $role->ID = $_GET['delete'];
         $role->delete();
     }
     $table = new Table();
     $id = new TableColumn("id", Language::DirectTranslate("ID"));
     $id->autoWidth = true;
     $name = new TableColumn("name", Language::DirectTranslate("NAME"));
     $table->columns->add($id);
     $table->columns->add($name);
     $table->name = "{'dbprefix'}roles";
     $table->actions = "rolelist";
     $table->orderBy = "name";
     $table->cacheName = "rolelist";
     $rolelist->assign_var("TABLE", $table->getCode());
     $rolelist->output();
 }
开发者ID:srueegger,项目名称:1zu12bB,代码行数:28,代码来源:rolelist.php

示例15: run

 public function run()
 {
     $user = new User();
     $user->email = 'danny_kent@mail.ru';
     $user->username = 'danny-admin';
     $user->password = Hash::make('secret');
     $user->password_confirmation = $user->password;
     $user->confirmation_code = md5(uniqid(mt_rand(), true));
     $user->confirmed = 1;
     if (!$user->save()) {
         Log::info('Unable to create user ' . $user->email, (array) $user->errors());
     } else {
         Log::info('Created user "' . $user->email . '" <' . $user->email . '>');
     }
     $admin = new Role();
     $admin->name = 'Admin';
     $admin->save();
     $user = new User();
     $user->email = 'somovlife@gmail.com';
     $user->username = 'ivan-admin';
     $user->password = Hash::make('secret');
     $user->password_confirmation = $user->password;
     $user->confirmation_code = md5(uniqid(mt_rand(), true));
     $user->confirmed = 1;
     if (!$user->save()) {
         Log::info('Unable to create user ' . $user->email, (array) $user->errors());
     } else {
         Log::info('Created user "' . $user->email . '" <' . $user->email . '>');
     }
     $user = User::where('username', $user->username)->firstOrFail();
     $user->attachRole($admin);
 }
开发者ID:VerticalHorizon,项目名称:Bumagi,代码行数:32,代码来源:UsersTableSeeder.php


注:本文中的Role类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。