fixed api token

This commit is contained in:
denisdulici 2017-11-02 02:00:54 +03:00
parent d67b5e7746
commit dfac921e97
6 changed files with 52 additions and 47 deletions

View File

@ -57,4 +57,18 @@ class Controller extends BaseController
return $counter; 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();
}
} }

View File

@ -10,20 +10,6 @@ class Home extends Controller
{ {
use Modules; 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. * Display a listing of the resource.
* *
@ -31,6 +17,8 @@ class Home extends Controller
*/ */
public function index() public function index()
{ {
$this->checkApiToken();
$paid = $this->getPaidModules(); $paid = $this->getPaidModules();
$new = $this->getNewModules(); $new = $this->getNewModules();
$free = $this->getFreeModules(); $free = $this->getFreeModules();

View File

@ -15,20 +15,6 @@ class Item extends Controller
{ {
use Modules; 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. * Show the form for viewing the specified resource.
* *
@ -38,6 +24,8 @@ class Item extends Controller
*/ */
public function show($alias) public function show($alias)
{ {
$this->checkApiToken();
$installed = false; $installed = false;
$enable = false; $enable = false;
@ -59,12 +47,14 @@ class Item extends Controller
/** /**
* Show the form for viewing the specified resource. * Show the form for viewing the specified resource.
* *
* @param $path * @param $request
* *
* @return Response * @return Response
*/ */
public function steps(Request $request) public function steps(Request $request)
{ {
$this->checkApiToken();
$json = array(); $json = array();
$json['step'] = array(); $json['step'] = array();
@ -95,12 +85,14 @@ class Item extends Controller
/** /**
* Show the form for viewing the specified resource. * Show the form for viewing the specified resource.
* *
* @param $path * @param $request
* *
* @return Response * @return Response
*/ */
public function download(Request $request) public function download(Request $request)
{ {
$this->checkApiToken();
$path = $request['path']; $path = $request['path'];
$version = $request['version']; $version = $request['version'];
@ -115,12 +107,14 @@ class Item extends Controller
/** /**
* Show the form for viewing the specified resource. * Show the form for viewing the specified resource.
* *
* @param $path * @param $request
* *
* @return Response * @return Response
*/ */
public function unzip(Request $request) public function unzip(Request $request)
{ {
$this->checkApiToken();
$path = $request['path']; $path = $request['path'];
$json = $this->unzipModule($path); $json = $this->unzipModule($path);
@ -137,6 +131,8 @@ class Item extends Controller
*/ */
public function install(Request $request) public function install(Request $request)
{ {
$this->checkApiToken();
$path = $request['path']; $path = $request['path'];
$json = $this->installModule($path); $json = $this->installModule($path);
@ -154,6 +150,8 @@ class Item extends Controller
public function uninstall($alias) public function uninstall($alias)
{ {
$this->checkApiToken();
$json = $this->uninstallModule($alias); $json = $this->uninstallModule($alias);
$module = Module::where('alias', $alias)->first(); $module = Module::where('alias', $alias)->first();
@ -179,6 +177,8 @@ class Item extends Controller
public function update($alias) public function update($alias)
{ {
$this->checkApiToken();
$json = $this->updateModule($alias); $json = $this->updateModule($alias);
$module = Module::where('alias', $alias)->first(); $module = Module::where('alias', $alias)->first();
@ -202,6 +202,8 @@ class Item extends Controller
public function enable($alias) public function enable($alias)
{ {
$this->checkApiToken();
$json = $this->enableModule($alias); $json = $this->enableModule($alias);
$module = Module::where('alias', $alias)->first(); $module = Module::where('alias', $alias)->first();
@ -229,6 +231,8 @@ class Item extends Controller
public function disable($alias) public function disable($alias)
{ {
$this->checkApiToken();
$json = $this->disableModule($alias); $json = $this->disableModule($alias);
$module = Module::where('alias', $alias)->first(); $module = Module::where('alias', $alias)->first();

View File

@ -10,20 +10,6 @@ class Tiles extends Controller
{ {
use Modules; 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. * Show the form for viewing the specified resource.
* *
@ -33,6 +19,8 @@ class Tiles extends Controller
*/ */
public function category($alias) public function category($alias)
{ {
$this->checkApiToken();
$data = $this->getModulesByCategory($alias); $data = $this->getModulesByCategory($alias);
$title = $data->category->name; $title = $data->category->name;
@ -48,6 +36,8 @@ class Tiles extends Controller
*/ */
public function paid() public function paid()
{ {
$this->checkApiToken();
$title = trans('modules.top_paid'); $title = trans('modules.top_paid');
$modules = $this->getPaidModules(); $modules = $this->getPaidModules();
@ -61,6 +51,8 @@ class Tiles extends Controller
*/ */
public function new() public function new()
{ {
$this->checkApiToken();
$title = trans('modules.new'); $title = trans('modules.new');
$modules = $this->getNewModules(); $modules = $this->getNewModules();
@ -74,6 +66,8 @@ class Tiles extends Controller
*/ */
public function free() public function free()
{ {
$this->checkApiToken();
$title = trans('modules.top_free'); $title = trans('modules.top_free');
$modules = $this->getFreeModules(); $modules = $this->getFreeModules();

View File

@ -23,6 +23,7 @@ class LoadSettings
// Set the active company settings // Set the active company settings
setting()->setExtraColumns(['company_id' => $company_id]); setting()->setExtraColumns(['company_id' => $company_id]);
setting()->load(true);
// Timezone // Timezone
config(['app.timezone' => setting('general.timezone', 'UTC')]); config(['app.timezone' => setting('general.timezone', 'UTC')]);

View File

@ -25,8 +25,12 @@ class Modules
return collect($this->getCategories())->pluck('name', 'slug') return collect($this->getCategories())->pluck('name', 'slug')
->prepend(trans('general.all_type', ['type' => trans_choice('general.categories', 2)]), ''); ->prepend(trans('general.all_type', ['type' => trans_choice('general.categories', 2)]), '');
}); });
} else {
$view->with(['categories' => $categories]); $categories = collect([
'' => trans('general.all_type', ['type' => trans_choice('general.categories', 2)]),
]);
} }
$view->with(['categories' => $categories]);
} }
} }