Skip to content

Commit

Permalink
fixed api token
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdulici committed Nov 1, 2017
1 parent d67b5e7 commit dfac921
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 47 deletions.
14 changes: 14 additions & 0 deletions app/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,18 @@ public function countRelationships($model, $relationships)

return $counter;
}

/**
* Check for api token and redirect if empty.
*
* @return mixed
*/
public function checkApiToken()
{
if (setting('general.api_token')) {
return;
}

redirect('apps/token/create')->send();
}
}
16 changes: 2 additions & 14 deletions app/Http/Controllers/Modules/Home.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,15 @@ class Home extends Controller
{
use Modules;

/**
* Instantiate a new controller instance.
*
* @param Route $route
*/
public function __construct(Route $route)
{
if (!setting('general.api_token')) {
return redirect('apps/token/create')->send();
}

parent::__construct($route);
}

/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
$this->checkApiToken();

$paid = $this->getPaidModules();
$new = $this->getNewModules();
$free = $this->getFreeModules();
Expand Down
38 changes: 21 additions & 17 deletions app/Http/Controllers/Modules/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,6 @@ class Item extends Controller
{
use Modules;

/**
* Instantiate a new controller instance.
*
* @param Route $route
*/
public function __construct(Route $route)
{
if (!setting('general.api_token')) {
return redirect('apps/token/create')->send();
}

parent::__construct($route);
}

/**
* Show the form for viewing the specified resource.
*
Expand All @@ -38,6 +24,8 @@ public function __construct(Route $route)
*/
public function show($alias)
{
$this->checkApiToken();

$installed = false;
$enable = false;

Expand All @@ -59,12 +47,14 @@ public function show($alias)
/**
* Show the form for viewing the specified resource.
*
* @param $path
* @param $request
*
* @return Response
*/
public function steps(Request $request)
{
$this->checkApiToken();

$json = array();
$json['step'] = array();

Expand Down Expand Up @@ -95,12 +85,14 @@ public function steps(Request $request)
/**
* Show the form for viewing the specified resource.
*
* @param $path
* @param $request
*
* @return Response
*/
public function download(Request $request)
{
$this->checkApiToken();

$path = $request['path'];

$version = $request['version'];
Expand All @@ -115,12 +107,14 @@ public function download(Request $request)
/**
* Show the form for viewing the specified resource.
*
* @param $path
* @param $request
*
* @return Response
*/
public function unzip(Request $request)
{
$this->checkApiToken();

$path = $request['path'];

$json = $this->unzipModule($path);
Expand All @@ -137,6 +131,8 @@ public function unzip(Request $request)
*/
public function install(Request $request)
{
$this->checkApiToken();

$path = $request['path'];

$json = $this->installModule($path);
Expand All @@ -154,6 +150,8 @@ public function install(Request $request)

public function uninstall($alias)
{
$this->checkApiToken();

$json = $this->uninstallModule($alias);

$module = Module::where('alias', $alias)->first();
Expand All @@ -179,6 +177,8 @@ public function uninstall($alias)

public function update($alias)
{
$this->checkApiToken();

$json = $this->updateModule($alias);

$module = Module::where('alias', $alias)->first();
Expand All @@ -202,6 +202,8 @@ public function update($alias)

public function enable($alias)
{
$this->checkApiToken();

$json = $this->enableModule($alias);

$module = Module::where('alias', $alias)->first();
Expand Down Expand Up @@ -229,6 +231,8 @@ public function enable($alias)

public function disable($alias)
{
$this->checkApiToken();

$json = $this->disableModule($alias);

$module = Module::where('alias', $alias)->first();
Expand Down
22 changes: 8 additions & 14 deletions app/Http/Controllers/Modules/Tiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,6 @@ class Tiles extends Controller
{
use Modules;

/**
* Instantiate a new controller instance.
*
* @param Route $route
*/
public function __construct(Route $route)
{
if (!setting('general.api_token')) {
return redirect('apps/token/create')->send();
}

parent::__construct($route);
}

/**
* Show the form for viewing the specified resource.
*
Expand All @@ -33,6 +19,8 @@ public function __construct(Route $route)
*/
public function category($alias)
{
$this->checkApiToken();

$data = $this->getModulesByCategory($alias);

$title = $data->category->name;
Expand All @@ -48,6 +36,8 @@ public function category($alias)
*/
public function paid()
{
$this->checkApiToken();

$title = trans('modules.top_paid');
$modules = $this->getPaidModules();

Expand All @@ -61,6 +51,8 @@ public function paid()
*/
public function new()
{
$this->checkApiToken();

$title = trans('modules.new');
$modules = $this->getNewModules();

Expand All @@ -74,6 +66,8 @@ public function new()
*/
public function free()
{
$this->checkApiToken();

$title = trans('modules.top_free');
$modules = $this->getFreeModules();

Expand Down
1 change: 1 addition & 0 deletions app/Http/Middleware/LoadSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function handle($request, Closure $next)

// Set the active company settings
setting()->setExtraColumns(['company_id' => $company_id]);
setting()->load(true);

// Timezone
config(['app.timezone' => setting('general.timezone', 'UTC')]);
Expand Down
8 changes: 6 additions & 2 deletions app/Http/ViewComposers/Modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ public function compose(View $view)
return collect($this->getCategories())->pluck('name', 'slug')
->prepend(trans('general.all_type', ['type' => trans_choice('general.categories', 2)]), '');
});

$view->with(['categories' => $categories]);
} else {
$categories = collect([
'' => trans('general.all_type', ['type' => trans_choice('general.categories', 2)]),
]);
}

$view->with(['categories' => $categories]);
}
}

0 comments on commit dfac921

Please sign in to comment.