Пример #1
0
 public function can($permissionId, $user)
 {
     $queryObj = CategoryPermission::select(array('category_permission.permission_id', 'category_permission.role_id', 'category_permission.category_id'))->leftJoin('categories as c', function ($join) {
         $join->on('category_permission.category_id', '=', 'c.id');
         //$join->on('category_forum_permission.role_id', '=', 1);
     })->with('role', 'category', 'permission')->where('category_id', '=', $this->id);
     $permissions = $queryObj->get();
     if ($user == null) {
         if (in_array(2, $queryObj->lists('role_id'))) {
             if ($permissionId == 17 || $permissionId == 20) {
                 return true;
             }
         }
         return false;
     }
     if ($user && $user->roles->contains(1)) {
         return true;
     }
     foreach ($permissions as $permission) {
         $permissionById = Permission::find($permissionId);
         if ($permissionById) {
             if ($permission->permission->id == $permissionId) {
                 if ($user && $user->roles->contains($permission->role->id)) {
                     return true;
                 }
                 if (!$user) {
                     return $permission->role->id == 3 || $permission->role->id == 2;
                 }
             }
         }
     }
     return false;
 }
Пример #2
0
 public function install(InstallRequest $request)
 {
     // Surround everything with try/catch, in case something weird happens
     try {
         // STEP 1: Artisan commands
         Artisan::call('migrate', ['--quiet']);
         Artisan::call('vendor:publish', ['--quiet']);
         Artisan::call('clear-compiled', ['--quiet']);
         Artisan::call('cache:clear', ['--quiet']);
         $username = $request->input('username');
         $password = $request->input('password');
         // STEP 2: Create the admin user (confirmed by default)
         $adminUser = $this->user->create(array('name' => $username, 'email' => $request->input('email'), 'password' => Hash::make($password), 'slug' => str_slug($request->input('username')), 'confirmed' => 1));
         // Step 2b: Set up default roles and permissions
         Artisan::call('db:seed', ['--class' => 'RolesTableSeeder']);
         Artisan::call('db:seed', ['--class' => 'PermissionsTableSeeder']);
         // Step 2c: Add the admin role to the admin user
         $role = $this->role->where('name', '=', 'Administrator')->first();
         if ($role) {
             $adminUser->attachRole($role);
         }
         // Step 3: Create categories and channels
         $exampleCategory1 = $this->category->create(array('name' => 'Example Category #1', 'description' => 'An example category.', 'weight' => 1, 'slug' => 'example-category-1'));
         $exampleCategory2 = $this->category->create(array('name' => 'Example Category #2', 'description' => 'Another example category.', 'weight' => 2, 'slug' => 'example-category-2'));
         $exampleChannel1 = $this->channel->create(array('name' => 'Example Channel #1', 'description' => 'An example channel.', 'weight' => 1, 'category_id' => 1, 'slug' => 'example-channel-1'));
         $exampleChannel2 = $this->channel->create(array('name' => 'Example Channel #2', 'description' => 'Another example channel.', 'weight' => 2, 'category_id' => 1, 'slug' => 'example-channel-2'));
         $exampleChannel3 = $this->channel->create(array('name' => 'Example Channel #3', 'description' => 'Yet another example channel.', 'weight' => 1, 'category_id' => 2, 'slug' => 'example-channel-3'));
         $staffSection = $this->category->create(array('name' => 'Staff Section', 'description' => 'Staff only section', 'weight' => 3, 'slug' => 'staff-section'));
         $staffChannel = $this->channel->create(array('name' => 'Staff Channel', 'description' => 'A channel for staff members', 'weight' => 1, 'category_id' => 3, 'slug' => 'staff-channel'));
         $accessStaffSection = [1, 4];
         $createThreads = [1, 4];
         $accessStaffChannel = [1, 4];
         $createThreadsInStaffChannel = [1, 4];
         $postInStaffSection = [1, 4];
         $postInStaffChannel = [1, 4];
         foreach ($accessStaffSection as $id) {
             $perm = CategoryPermission::firstOrCreate(array('permission_id' => 20, 'role_id' => $id, 'category_id' => $staffSection->id));
         }
         foreach ($createThreads as $id) {
             $perm = CategoryPermission::firstOrCreate(array('permission_id' => 1, 'role_id' => $id, 'category_id' => $staffSection->id));
         }
         foreach ($accessStaffChannel as $id) {
             $perm = ChannelPermission::firstOrCreate(array('permission_id' => 21, 'role_id' => $id, 'channel_id' => $staffChannel->id));
         }
         foreach ($createThreadsInStaffChannel as $id) {
             $perm = ChannelPermission::firstOrCreate(array('permission_id' => 1, 'role_id' => $id, 'channel_id' => $staffChannel->id));
         }
         foreach ($postInStaffSection as $id) {
             $perm = CategoryPermission::firstOrCreate(array('permission_id' => 6, 'role_id' => $id, 'category_id' => $staffSection->id));
         }
         foreach ($postInStaffChannel as $id) {
             $perm = ChannelPermission::firstOrCreate(array('permission_id' => 6, 'role_id' => $id, 'channel_id' => $staffChannel->id));
         }
         // Step 4: Create settings
         $data = array(0 => array('name' => 'sitename', 'value' => htmlspecialchars($request->has('forumTitle') ? $request->input('forumTitle') : 'A Fetch404 Site')), 1 => array('name' => 'sitedesc', 'value' => htmlspecialchars($request->has('forumDesc') ? $request->input('forumDesc') : 'This site uses Fetch404.')), 2 => array('name' => 'twitter_url', 'value' => null), 3 => array('name' => 'gplus_url', 'value' => null), 4 => array('name' => 'fb_url', 'value' => null), 5 => array('name' => 'recaptcha', 'value' => 'false'), 6 => array('name' => 'recaptcha_key', 'value' => null), 7 => array('name' => 'twitter_feed_id', 'value' => null), 8 => array('name' => 'bootswatch_theme', 'value' => $request->has('bootswatch_theme') ? $request->get('bootswatch_theme') : 6), 9 => array('name' => 'navbar_style', 'value' => $request->has('inverse_navbar') ? 1 : 0), 10 => array('name' => 'infractions', 'value' => $request->has('enable_infractions') ? 'true' : 'false'), 11 => array('name' => 'outgoing_email', 'value' => $request->input('outgoing_email')));
         try {
             foreach ($data as $setting) {
                 $this->settings->setSetting($data["name"], $data["value"]);
             }
             $adminUser->setSetting("show_what_im_doing", true);
             $adminUser->setSetting("show_if_im_online", true);
             $adminUser->setSetting("show_if_im_online", true);
             $adminUser->setSetting("notify_me_on_thread_reply", true);
             $adminUser->setSetting("notify_me_on_thread_lock", true);
             $adminUser->setSetting("notify_me_on_thread_pin", true);
             $adminUser->setSetting("notify_me_on_thread_move", true);
             $adminUser->setSetting("notify_me_on_new_follower", true);
             $adminUser->setSetting("notify_me_on_post_like", true);
             $adminUser->setSetting("notify_me_on_followed_user_new_post", true);
             $adminUser->setSetting("notify_me_on_profile_post", true);
         } catch (Exception $ex) {
             if ($ex instanceof \PDOException) {
                 return view('core.installer.errors.pdoexception', array('error' => $ex));
             } else {
                 return view('core.installer.errors.exception', array('error' => $ex));
             }
         }
         // Step 5: Send the administrator a "welcome" message
         // This is the final step
         $conversation = $adminUser->threads()->create(array('subject' => 'Welcome to your new Fetch404 installation'));
         $messageBody = 'Hey there, <strong>' . $adminUser->name . '</strong>! Thanks for using Fetch404. Here are a few tips to help you get started.';
         $messageBody .= '<h1>Managing your Forum</h1><hr>';
         $messageBody .= '<p>Managing a large forum can be hard. Luckily, Fetch404\'s admin panel allows you to easily customize almost every part of your forum, including categories, channels, and much more. Just go to the "Forum" section of your admin panel and start setting up your forum!</p><hr>';
         $messageBody .= '<h1>Customizing your Site</h1><hr>';
         $messageBody .= '<p>Bored of the same old bland look? Want some color? You can do that! Go to the "General" section of your admin panel, and from there you can change the theme, and switch the navigation bar color.</p><hr>';
         $messageBody .= '<h1>Configuring your Site</h1><hr>';
         $messageBody .= '<p>Want to prevent spambots? Want to change your site\'s name? Need to disable the login or register feature? You can do all of that from the "General" section of your admin panel.</p><br><small>* Note: You will need to have a <a href="https://www.google.com/recaptcha/intro/index.html">reCAPTCHA</a> key in order to enable the captcha.</small><hr>';
         $messageBody .= '<h1>I need help!</h1><hr>';
         $messageBody .= '<p>Don\'t worry! You can go to our <a href="http://fetch404.com">support forum</a> and receive help with various things.</p><hr><p>We hope you enjoy using Fetch404. Please note that there is a lot more than what is listed here. You may want to turn off registering for a bit until you are sure that your website is ready. Once again, enjoy!</p>';
         $message = $adminUser->messages()->create(array('thread_id' => $conversation->id, 'user_id' => $adminUser->id, 'body' => Purifier::clean($messageBody)));
         $conversation->addParticipants(array($adminUser->id));
         if ($this->auth->attempt(['name' => $username, 'password' => $password])) {
         }
         return view('core.installer.success');
     } catch (\Exception $ex) {
         if ($ex instanceof \PDOException) {
             return view('core.installer.errors.pdoexception', array('error' => $ex));
         } else {
             return view('core.installer.errors.exception', array('error' => $ex));
         }
     }
 }
 /**
  * Update the specified resource in storage.
  *
  * @param UpdateCategoryPermissionsRequest $request
  * @return Response
  */
 public function update(UpdateCategoryPermissionsRequest $request)
 {
     //
     $category = $request->route()->getParameter('category');
     $accessCategory = $request->input('allowed_groups');
     $createThreads = $request->input('create_threads');
     $reply = $request->input('reply_to_threads');
     CategoryPermission::where('category_id', '=', $category->id)->where('permission_id', '=', 20)->orWhere('permission_id', '=', 1)->orWhere('permission_id', '=', 6)->delete();
     $createThreads = collect($createThreads);
     $createThreads = $createThreads->filter(function ($item) {
         return $item != 2;
     });
     $reply = collect($reply);
     $reply = $reply->filter(function ($item) {
         return $item != 2;
     });
     foreach ($accessCategory as $id) {
         $perm = CategoryPermission::firstOrCreate(array('permission_id' => 20, 'role_id' => $id, 'category_id' => $category->id));
     }
     foreach ($createThreads as $id) {
         $create_threads = CategoryPermission::firstOrCreate(array('permission_id' => 1, 'role_id' => $id, 'category_id' => $category->id));
     }
     foreach ($reply as $id) {
         $perm = CategoryPermission::firstOrCreate(array('permission_id' => 6, 'role_id' => $id, 'category_id' => $category->id));
     }
     Flash::success('Updated category permissions!');
     return redirect(route('admin.forum.get.permissions.category.edit', array($category)));
 }