Skip to content

Commit

Permalink
Merge pull request #3 from krve/master
Browse files Browse the repository at this point in the history
Fix html being injected into all responses
  • Loading branch information
viacreativedev authored Mar 23, 2017
2 parents 2c9417f + ecd71a6 commit 082db77
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 59 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
vendor
node_modules
node_modules
.idea/
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ class AppServiceProvider extends ServiceProvider

⚠️ *Warning:* You should not register the provider globally like usual in the `config/app.php` file. View the disclaimer [here](#disclaimer---danger) for more information.

Include the partial in your layout file.

```php
@if (env('APP_DEBUG'))
@include('sudosu::user-selector')
@endif
```

Finally, publish the package's assets (the package won't work without this):

Expand Down
50 changes: 0 additions & 50 deletions src/Middleware/SudoSuMiddleware.php

This file was deleted.

28 changes: 22 additions & 6 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

namespace VIACreative\SudoSu;

use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\View;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Request;
use VIACreative\SudoSu\Middleware\SudoSuMiddleware;
use Illuminate\Support\ServiceProvider as BaseServiceProvider;

class ServiceProvider extends BaseServiceProvider
Expand All @@ -27,12 +29,26 @@ public function boot()
], 'config');

if ($this->configExists() && $this->tldIsAllowed()) {
$this->loadViewsFrom(__DIR__ . '/../resources/views', 'sudosu');

$kernel = $this->app['Illuminate\Contracts\Http\Kernel'];
$kernel->pushMiddleware(SudoSuMiddleware::class);
$this->registerViews();
}
}

protected function registerViews()
{
$this->loadViewsFrom(__DIR__ . '/../resources/views', 'sudosu');

// Add an inline view composer for the user-selector
View::composer('sudosu::user-selector', function ($view) {
$sudosu = App::make(SudoSu::class);

$view->with([
'users' => $sudosu->getUsers(),
'hasSudoed' => $sudosu->hasSudoed(),
'originalUser' => $sudosu->getOriginalUser(),
'currentUser' => Auth::user()
]);
});
}

protected function tldIsAllowed()
{
Expand All @@ -55,4 +71,4 @@ protected function configExists()
{
return is_array(Config::get('sudosu.allowed_tlds'));
}
}
}
4 changes: 2 additions & 2 deletions src/SudoSu.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function hasSudoed()
return $this->session->has('sudosu.has_sudoed');
}

protected function getUsers()
public function getUsers()
{
if ($this->usersCached) {
return $this->usersCached;
Expand All @@ -97,4 +97,4 @@ protected function getUserModel()
$userModel = Config::get('sudosu.user_model');
return $this->app->make($userModel);
}
}
}

0 comments on commit 082db77

Please sign in to comment.