Пример #1
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function postCreate(Request $request)
 {
     // Declare the rules for the form validation
     $rules = array('name' => 'required|unique:roles', 'display_name' => 'required|unique:roles');
     // Validate the inputs
     $validator = Validator::make($request->all(), $rules, ['name.required' => 'A name is required.', 'name.unique' => 'Please use a different name.', 'display_name.required' => 'A display name is required', 'display_name.unique' => 'Please use a different display name.']);
     // Check if the form validates with success
     if ($validator->passes()) {
         // Get the inputs, with some exceptions
         $inputs = $request->except('csrf_token');
         $this->role->name = $request->input('name');
         $this->role->display_name = $request->input('display_name');
         $this->role->is_protected = $request->has('is_protected') ? 1 : 0;
         $this->role->is_superuser = $request->has('is_superuser') ? 1 : 0;
         $this->role->save();
         // Save permissions
         $this->role->perms()->sync($this->permission->preparePermissionsForSave($inputs['permissions']));
         // Was the role created?
         if ($this->role->id) {
             // Redirect to the new role page
             Flash::success('Created role');
             return redirect('admin/roles/' . $this->role->id . '/edit');
         }
         // Redirect to the new role page
         Flash::error('Could not create role');
         return redirect('admin/roles/create');
     }
     // Form validation failed
     return redirect('admin/roles/create')->withInput()->withErrors($validator);
 }
 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     // Inserts the Permissions
     Permission::insert($this->permissions);
     // Creates a root admin role
     $rootadmin = new Role();
     $rootadmin->name = "rootadmin";
     $rootadmin->display_name = "Root Admin";
     $rootadmin->description = "Has Permissions to do everything in the WebPanel";
     $rootadmin->save();
     //Get all permissions
     $ids = Permission::lists('id')->all();
     //Sync them to the rootadmin
     $rootadmin->perms()->sync($ids);
     //Creates an admin user
     $admin = new User();
     $admin->name = 'admin';
     $admin->email = '*****@*****.**';
     $admin->password = bcrypt('password');
     $admin->save();
     $admin->roles()->sync(array($rootadmin->id));
 }
Пример #3
0
 public function run()
 {
     /* Create administrator role */
     $admin = new Role();
     $admin->name = 'Administrator';
     $admin->save();
     /* Create officer role */
     $officer = new Role();
     $officer->name = 'Officer';
     $officer->save();
     /* Create member role */
     $member = new Role();
     $member->name = 'Member';
     $member->save();
     /* Permissions */
     /* Default permission for board members */
     $manageSystem = new Permission();
     $manageSystem->name = 'manage_system';
     $manageSystem->display_name = 'Manage System';
     $manageSystem->save();
     /* Apply permissions */
     $admin->perms()->sync(array($manageSystem->id));
     $officer->perms()->sync(array($manageSystem->id));
 }
 /**
  *  Initialize the user group
  *
  */
 public function setupFounderAndBaseRolesPermission()
 {
     //Create Roles
     $founder = new Role();
     $founder->name = 'Founder';
     $founder->save();
     $admin = new Role();
     $admin->name = 'Admin';
     $admin->save();
     //Create User
     $user = new User();
     $user->name = 'muzhuang';
     $user->email = '*****@*****.**';
     $user->password = Hash::make('secret');
     if (!$user->save()) {
         Log::info('Unabel to create user ' . $user->username, (array) $user->errors());
     } else {
         Log::info('Create user "' . $user->username . '" <' . $user->email . '>');
     }
     //Attach Roles to user
     $user->roles()->attach($founder->id);
     //Create Permissions
     $manageUsers = new Permission();
     $manageUsers->name = 'admin.user';
     $manageUsers->display_name = 'Manage Users';
     $manageUsers->save();
     // Assign Permission to Role
     $founder->perms()->sync([$manageUsers->id]);
     $admin->perms()->sync([$manageUsers->id]);
 }
 private function remove_permissions_from_role(Role $role)
 {
     $role->perms()->sync(array());
 }
Пример #6
0
 /**
  * Get list current permission of Role
  * @var Role $role
  * @return array
  */
 public function currentPerms(Role $role)
 {
     $perms = $role->perms()->lists('id');
     return $perms->toArray();
 }
 /**
  * Sync the Server List
  *
  * @param Role $role
  * @param array $permissions
  */
 private function SyncPermissions(Role $role, $permissions = array())
 {
     if ($permissions == null) {
         $permissions = array();
     }
     $role->perms()->sync($permissions);
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  App\Role $role
  * @return Response
  */
 public function edit($role)
 {
     $current_permissions = array_pluck($role->perms()->get(['permissions.id'])->toArray(), 'id');
     return view('templates.' . \Config::get('webpanel.template') . 'webpanel.panel.roles.edit', compact('role', 'current_permissions'));
 }