Esempio n. 1
0
 public function postStore()
 {
     $sid = Input::get('id');
     $rules = array('name' => 'required', 'permission-inherit' => 'regex:/^[a-z,0-9._\\-?]+$/i', 'permission-allow' => 'regex:/^[a-z,0-9._\\-?]+$/i', 'permission-deny' => 'regex:/^[a-z,0-9._\\-?]+$/i');
     $messages = array('permission-inherit.regex' => 'The permission inherit format is invalid. Try using the Permission Builder.', 'permission-allow.regex' => 'The permission allow format is invalid. Try using the Permission Builder.', 'permission-deny.regex' => 'The permission deny format is invalid. Try using the Permission Builder.');
     $validation = Validator::make(Input::all(), $rules, $messages);
     if (isset($sid)) {
         $redirect_url = 'admin/groups/edit/' . $sid;
         $group = Group::find($sid);
     } else {
         $redirect_url = 'admin/groups/create';
         $group = new Group();
     }
     if ($validation->fails()) {
         return redirect($redirect_url)->withErrors($validation)->withInput();
     }
     $permissions = $this->populatePermission(Input::get('permission-inherit'), Input::get('permission-allow'), Input::get('permission-deny'));
     if ($group == null) {
         $errors = new MessageBag();
         $errors->add('editError', trans('redminportal::messages.group_error_edit_no_group_found'));
         return redirect('admin/groups')->withErrors($errors);
     }
     try {
         // Save the group details
         $group->name = Input::get('name');
         $group->permissions = json_encode($permissions);
         $group->save();
     } catch (\Exception $exp) {
         // There was a problem saving it
         $errors = new MessageBag();
         $errors->add('editError', trans('redminportal::messages.group_error_edit_cannot_save'));
         return redirect($redirect_url)->withErrors($errors)->withInput();
     }
     return redirect('admin/groups');
 }
Esempio n. 2
0
 public function run()
 {
     DB::table('users')->delete();
     DB::table('groups')->delete();
     DB::table('users_groups')->delete();
     $user = new User();
     $user->email = '*****@*****.**';
     $user->password = \Hash::make("admin");
     $user->first_name = 'System';
     $user->last_name = 'Admin';
     $user->activated = 1;
     $user->save();
     $admin_group = new Group();
     $admin_group->name = 'Admin';
     $admin_group->permissions = json_encode(array('admin.view' => 1, 'admin.create' => 1, 'admin.delete' => 1, 'admin.update' => 1));
     $admin_group->save();
     $user_group = new Group();
     $user_group->name = 'User';
     $user_group->permissions = json_encode(array('admin.view' => 0, 'admin.create' => 0, 'admin.delete' => 0, 'admin.update' => 0));
     $user_group->save();
     // Assign user permissions
     $user->groups()->save($admin_group);
 }
 public function postStore()
 {
     $sid = \Input::get('id');
     $rules = array('name' => 'required');
     $validation = \Validator::make(\Input::all(), $rules);
     if ($validation->fails()) {
         if (isset($sid)) {
             return redirect('admin/groups/edit/' . $sid)->withErrors($validation)->withInput();
         } else {
             return redirect('admin/groups/create')->withErrors($validation)->withInput();
         }
     }
     // Validation passes
     $name = \Input::get('name');
     $view = \Input::get('view') == '' ? false : true;
     $create = \Input::get('create') == '' ? false : true;
     $delete = \Input::get('delete') == '' ? false : true;
     $update = \Input::get('update') == '' ? false : true;
     $permissions = json_encode(array('admin.view' => $view, 'admin.create' => $create, 'admin.delete' => $delete, 'admin.update' => $update));
     if (isset($sid)) {
         $group = Group::find($sid);
         if ($group == null) {
             $errors = new \Illuminate\Support\MessageBag();
             $errors->add('editError', "The group cannot be found because it does not exist or may have been deleted.");
             return redirect('/admin/groups')->withErrors($errors);
         }
         // Update the group details
         $group->name = $name;
         $group->permissions = $permissions;
         // Update the group
         if ($group->save()) {
             return redirect('admin/groups');
         } else {
             $errors = new \Illuminate\Support\MessageBag();
             $errors->add('editError', "The group cannot be updated due to some problem. Please try again.");
             return redirect('admin/groups/edit/' . $sid)->withErrors($errors)->withInput();
         }
     } else {
         // Create the group
         $group = new Group();
         $group->name = $name;
         $group->permissions = $permissions;
         try {
             $group->save();
         } catch (\Exception $exp) {
             $errors = new \Illuminate\Support\MessageBag();
             $errors->add('editError', "The group cannot be created due to some problem. Please try again.");
             return redirect('admin/groups/create')->withErrors($errors)->withInput();
         }
     }
     return redirect('admin/groups');
 }