@@ -5,37 +5,37 @@ |
||
5 | 5 | |
6 | 6 | abstract class AbstractRepositoryContainer implements RepositoryContainerInterface |
7 | 7 | { |
8 | - /** |
|
9 | - * Construct the repository class name based on |
|
10 | - * the method name called, search in the |
|
11 | - * given namespaces for the class and |
|
12 | - * return an instance. |
|
13 | - * |
|
14 | - * @param string $name the called method name |
|
15 | - * @param array $arguments the method arguments |
|
16 | - * @return object |
|
17 | - */ |
|
18 | - public function __call($name, $arguments) |
|
19 | - { |
|
20 | - foreach ($this->getRepoNameSpace() as $repoNameSpace) { |
|
21 | - $class = rtrim($repoNameSpace, '\\').'\\'.ucfirst(Str::singular($name)).'Repository'; |
|
22 | - if (class_exists($class)) { |
|
23 | - \App::singleton($class, function ($app) use ($class) { |
|
8 | + /** |
|
9 | + * Construct the repository class name based on |
|
10 | + * the method name called, search in the |
|
11 | + * given namespaces for the class and |
|
12 | + * return an instance. |
|
13 | + * |
|
14 | + * @param string $name the called method name |
|
15 | + * @param array $arguments the method arguments |
|
16 | + * @return object |
|
17 | + */ |
|
18 | + public function __call($name, $arguments) |
|
19 | + { |
|
20 | + foreach ($this->getRepoNameSpace() as $repoNameSpace) { |
|
21 | + $class = rtrim($repoNameSpace, '\\').'\\'.ucfirst(Str::singular($name)).'Repository'; |
|
22 | + if (class_exists($class)) { |
|
23 | + \App::singleton($class, function ($app) use ($class) { |
|
24 | 24 | |
25 | - return new \App\Modules\Core\Decorators\CachingDecorator(new $class, $app['cache.store']); |
|
26 | - }); |
|
25 | + return new \App\Modules\Core\Decorators\CachingDecorator(new $class, $app['cache.store']); |
|
26 | + }); |
|
27 | 27 | |
28 | - return \App::make($class); |
|
29 | - } |
|
30 | - } |
|
31 | - } |
|
28 | + return \App::make($class); |
|
29 | + } |
|
30 | + } |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * Abstract methods that return the necessary |
|
35 | - * information (repositories namespaces) |
|
36 | - * needed to preform the previous actions. |
|
37 | - * |
|
38 | - * @return array |
|
39 | - */ |
|
40 | - abstract protected function getRepoNameSpace(); |
|
33 | + /** |
|
34 | + * Abstract methods that return the necessary |
|
35 | + * information (repositories namespaces) |
|
36 | + * needed to preform the previous actions. |
|
37 | + * |
|
38 | + * @return array |
|
39 | + */ |
|
40 | + abstract protected function getRepoNameSpace(); |
|
41 | 41 | } |
@@ -20,7 +20,7 @@ |
||
20 | 20 | foreach ($this->getRepoNameSpace() as $repoNameSpace) { |
21 | 21 | $class = rtrim($repoNameSpace, '\\').'\\'.ucfirst(Str::singular($name)).'Repository'; |
22 | 22 | if (class_exists($class)) { |
23 | - \App::singleton($class, function ($app) use ($class) { |
|
23 | + \App::singleton($class, function($app) use ($class) { |
|
24 | 24 | |
25 | 25 | return new \App\Modules\Core\Decorators\CachingDecorator(new $class, $app['cache.store']); |
26 | 26 | }); |
@@ -2,46 +2,46 @@ |
||
2 | 2 | |
3 | 3 | trait Translatable |
4 | 4 | { |
5 | - /** |
|
6 | - * Create a new model instance that is existing. |
|
7 | - * |
|
8 | - * @param array $attributes |
|
9 | - * @param string|null $connection |
|
10 | - * @return static |
|
11 | - */ |
|
12 | - public function newFromBuilder($attributes = [], $connection = null) |
|
13 | - { |
|
14 | - $model = parent::newFromBuilder($attributes, $connection); |
|
5 | + /** |
|
6 | + * Create a new model instance that is existing. |
|
7 | + * |
|
8 | + * @param array $attributes |
|
9 | + * @param string|null $connection |
|
10 | + * @return static |
|
11 | + */ |
|
12 | + public function newFromBuilder($attributes = [], $connection = null) |
|
13 | + { |
|
14 | + $model = parent::newFromBuilder($attributes, $connection); |
|
15 | 15 | |
16 | - foreach ($model->attributes as $key => $value) { |
|
17 | - if (isset($this->translatable) && in_array($key, $this->translatable)) { |
|
18 | - $model->$key = $this->getTranslatedAttribute($value); |
|
19 | - } |
|
20 | - } |
|
16 | + foreach ($model->attributes as $key => $value) { |
|
17 | + if (isset($this->translatable) && in_array($key, $this->translatable)) { |
|
18 | + $model->$key = $this->getTranslatedAttribute($value); |
|
19 | + } |
|
20 | + } |
|
21 | 21 | |
22 | - return $model; |
|
23 | - } |
|
22 | + return $model; |
|
23 | + } |
|
24 | 24 | |
25 | - /** |
|
26 | - * Returns a translatable model attribute based on the application's locale settings. |
|
27 | - * |
|
28 | - * @param $values |
|
29 | - * @return string |
|
30 | - */ |
|
31 | - protected function getTranslatedAttribute($values) |
|
32 | - { |
|
33 | - $values = json_decode($values); |
|
34 | - $primaryLocale = \Session::get('locale'); |
|
35 | - $fallbackLocale = 'en'; |
|
25 | + /** |
|
26 | + * Returns a translatable model attribute based on the application's locale settings. |
|
27 | + * |
|
28 | + * @param $values |
|
29 | + * @return string |
|
30 | + */ |
|
31 | + protected function getTranslatedAttribute($values) |
|
32 | + { |
|
33 | + $values = json_decode($values); |
|
34 | + $primaryLocale = \Session::get('locale'); |
|
35 | + $fallbackLocale = 'en'; |
|
36 | 36 | |
37 | - if ($primaryLocale == 'all') { |
|
38 | - return $values; |
|
39 | - } |
|
37 | + if ($primaryLocale == 'all') { |
|
38 | + return $values; |
|
39 | + } |
|
40 | 40 | |
41 | - if (! $primaryLocale || ! is_object($values) || ! property_exists($values, $primaryLocale)) { |
|
42 | - return $values ? isset($values->$fallbackLocale) ? $values->$fallbackLocale : $values : ''; |
|
43 | - } |
|
41 | + if (! $primaryLocale || ! is_object($values) || ! property_exists($values, $primaryLocale)) { |
|
42 | + return $values ? isset($values->$fallbackLocale) ? $values->$fallbackLocale : $values : ''; |
|
43 | + } |
|
44 | 44 | |
45 | - return $primaryLocale == 'all' ? $values : $values->$primaryLocale; |
|
46 | - } |
|
45 | + return $primaryLocale == 'all' ? $values : $values->$primaryLocale; |
|
46 | + } |
|
47 | 47 | } |
@@ -38,7 +38,7 @@ |
||
38 | 38 | return $values; |
39 | 39 | } |
40 | 40 | |
41 | - if (! $primaryLocale || ! is_object($values) || ! property_exists($values, $primaryLocale)) { |
|
41 | + if ( ! $primaryLocale || ! is_object($values) || ! property_exists($values, $primaryLocale)) { |
|
42 | 42 | return $values ? isset($values->$fallbackLocale) ? $values->$fallbackLocale : $values : ''; |
43 | 43 | } |
44 | 44 |
@@ -22,7 +22,7 @@ |
||
22 | 22 | */ |
23 | 23 | public function saveMany(array $data) |
24 | 24 | { |
25 | - \DB::transaction(function () use ($data) { |
|
25 | + \DB::transaction(function() use ($data) { |
|
26 | 26 | foreach ($data as $value) { |
27 | 27 | $this->save($value); |
28 | 28 | } |
@@ -4,28 +4,28 @@ |
||
4 | 4 | |
5 | 5 | class SettingRepository extends AbstractRepository |
6 | 6 | { |
7 | - /** |
|
8 | - * Return the model full namespace. |
|
9 | - * |
|
10 | - * @return string |
|
11 | - */ |
|
12 | - protected function getModel() |
|
13 | - { |
|
14 | - return 'App\Modules\Core\Setting'; |
|
15 | - } |
|
7 | + /** |
|
8 | + * Return the model full namespace. |
|
9 | + * |
|
10 | + * @return string |
|
11 | + */ |
|
12 | + protected function getModel() |
|
13 | + { |
|
14 | + return 'App\Modules\Core\Setting'; |
|
15 | + } |
|
16 | 16 | |
17 | - /** |
|
18 | - * Save list of settings. |
|
19 | - * |
|
20 | - * @param array $data |
|
21 | - * @return void |
|
22 | - */ |
|
23 | - public function saveMany(array $data) |
|
24 | - { |
|
25 | - \DB::transaction(function () use ($data) { |
|
26 | - foreach ($data as $value) { |
|
27 | - $this->save($value); |
|
28 | - } |
|
29 | - }); |
|
30 | - } |
|
17 | + /** |
|
18 | + * Save list of settings. |
|
19 | + * |
|
20 | + * @param array $data |
|
21 | + * @return void |
|
22 | + */ |
|
23 | + public function saveMany(array $data) |
|
24 | + { |
|
25 | + \DB::transaction(function () use ($data) { |
|
26 | + foreach ($data as $value) { |
|
27 | + $this->save($value); |
|
28 | + } |
|
29 | + }); |
|
30 | + } |
|
31 | 31 | } |
@@ -2,8 +2,8 @@ |
||
2 | 2 | |
3 | 3 | return [ |
4 | 4 | |
5 | - /** |
|
6 | - * Here goes your notification messages. |
|
7 | - */ |
|
5 | + /** |
|
6 | + * Here goes your notification messages. |
|
7 | + */ |
|
8 | 8 | |
9 | 9 | ]; |
@@ -6,53 +6,53 @@ |
||
6 | 6 | |
7 | 7 | class ModuleServiceProvider extends ServiceProvider |
8 | 8 | { |
9 | - /** |
|
10 | - * Bootstrap the module services. |
|
11 | - * |
|
12 | - * @return void |
|
13 | - */ |
|
14 | - public function boot() |
|
15 | - { |
|
16 | - $this->loadTranslationsFrom(__DIR__.'/../Resources/Lang', 'core'); |
|
17 | - $this->loadViewsFrom(__DIR__.'/../Resources/Views', 'core'); |
|
18 | - |
|
19 | - $factory = app('Illuminate\Database\Eloquent\Factory'); |
|
20 | - $factory->load(__DIR__.'/../Database/Factories'); |
|
21 | - } |
|
22 | - |
|
23 | - /** |
|
24 | - * Register the module services. |
|
25 | - * |
|
26 | - * @return void |
|
27 | - */ |
|
28 | - public function register() |
|
29 | - { |
|
30 | - //Bind Core Facade to the IoC Container |
|
31 | - \App::bind('Core', function () { |
|
32 | - return new \App\Modules\Core\Core; |
|
33 | - }); |
|
34 | - |
|
35 | - //Bind ErrorHandler Facade to the IoC Container |
|
36 | - \App::bind('ErrorHandler', function () { |
|
37 | - return new \App\Modules\Core\Utl\ErrorHandler; |
|
38 | - }); |
|
39 | - |
|
40 | - //Bind CoreConfig Facade to the IoC Container |
|
41 | - \App::bind('CoreConfig', function () { |
|
42 | - return new \App\Modules\Core\Utl\CoreConfig; |
|
43 | - }); |
|
44 | - |
|
45 | - //Bind Mpgs Facade to the IoC Container |
|
46 | - \App::bind('Media', function () { |
|
47 | - return new \App\Modules\Core\Utl\Media; |
|
48 | - }); |
|
49 | - |
|
50 | - //Bind Mpgs Facade to the IoC Container |
|
51 | - \App::bind('ApiConsumer', function () { |
|
52 | - $app = app(); |
|
53 | - return new \App\Modules\Core\Utl\ApiConsumer($app, $app['request'], $app['router']); |
|
54 | - }); |
|
9 | + /** |
|
10 | + * Bootstrap the module services. |
|
11 | + * |
|
12 | + * @return void |
|
13 | + */ |
|
14 | + public function boot() |
|
15 | + { |
|
16 | + $this->loadTranslationsFrom(__DIR__.'/../Resources/Lang', 'core'); |
|
17 | + $this->loadViewsFrom(__DIR__.'/../Resources/Views', 'core'); |
|
18 | + |
|
19 | + $factory = app('Illuminate\Database\Eloquent\Factory'); |
|
20 | + $factory->load(__DIR__.'/../Database/Factories'); |
|
21 | + } |
|
22 | + |
|
23 | + /** |
|
24 | + * Register the module services. |
|
25 | + * |
|
26 | + * @return void |
|
27 | + */ |
|
28 | + public function register() |
|
29 | + { |
|
30 | + //Bind Core Facade to the IoC Container |
|
31 | + \App::bind('Core', function () { |
|
32 | + return new \App\Modules\Core\Core; |
|
33 | + }); |
|
34 | + |
|
35 | + //Bind ErrorHandler Facade to the IoC Container |
|
36 | + \App::bind('ErrorHandler', function () { |
|
37 | + return new \App\Modules\Core\Utl\ErrorHandler; |
|
38 | + }); |
|
39 | + |
|
40 | + //Bind CoreConfig Facade to the IoC Container |
|
41 | + \App::bind('CoreConfig', function () { |
|
42 | + return new \App\Modules\Core\Utl\CoreConfig; |
|
43 | + }); |
|
44 | + |
|
45 | + //Bind Mpgs Facade to the IoC Container |
|
46 | + \App::bind('Media', function () { |
|
47 | + return new \App\Modules\Core\Utl\Media; |
|
48 | + }); |
|
49 | + |
|
50 | + //Bind Mpgs Facade to the IoC Container |
|
51 | + \App::bind('ApiConsumer', function () { |
|
52 | + $app = app(); |
|
53 | + return new \App\Modules\Core\Utl\ApiConsumer($app, $app['request'], $app['router']); |
|
54 | + }); |
|
55 | 55 | |
56 | - $this->app->register(RouteServiceProvider::class); |
|
57 | - } |
|
56 | + $this->app->register(RouteServiceProvider::class); |
|
57 | + } |
|
58 | 58 | } |
@@ -28,27 +28,27 @@ |
||
28 | 28 | public function register() |
29 | 29 | { |
30 | 30 | //Bind Core Facade to the IoC Container |
31 | - \App::bind('Core', function () { |
|
31 | + \App::bind('Core', function() { |
|
32 | 32 | return new \App\Modules\Core\Core; |
33 | 33 | }); |
34 | 34 | |
35 | 35 | //Bind ErrorHandler Facade to the IoC Container |
36 | - \App::bind('ErrorHandler', function () { |
|
36 | + \App::bind('ErrorHandler', function() { |
|
37 | 37 | return new \App\Modules\Core\Utl\ErrorHandler; |
38 | 38 | }); |
39 | 39 | |
40 | 40 | //Bind CoreConfig Facade to the IoC Container |
41 | - \App::bind('CoreConfig', function () { |
|
41 | + \App::bind('CoreConfig', function() { |
|
42 | 42 | return new \App\Modules\Core\Utl\CoreConfig; |
43 | 43 | }); |
44 | 44 | |
45 | 45 | //Bind Mpgs Facade to the IoC Container |
46 | - \App::bind('Media', function () { |
|
46 | + \App::bind('Media', function() { |
|
47 | 47 | return new \App\Modules\Core\Utl\Media; |
48 | 48 | }); |
49 | 49 | |
50 | 50 | //Bind Mpgs Facade to the IoC Container |
51 | - \App::bind('ApiConsumer', function () { |
|
51 | + \App::bind('ApiConsumer', function() { |
|
52 | 52 | $app = app(); |
53 | 53 | return new \App\Modules\Core\Utl\ApiConsumer($app, $app['request'], $app['router']); |
54 | 54 | }); |
@@ -6,41 +6,41 @@ |
||
6 | 6 | |
7 | 7 | class ApiSkeletonServiceProvider extends ServiceProvider |
8 | 8 | { |
9 | - /** |
|
10 | - * Perform post-registration booting of services. |
|
11 | - * |
|
12 | - * @return void |
|
13 | - */ |
|
14 | - public function boot() |
|
15 | - { |
|
16 | - $this->publishes([ |
|
17 | - __DIR__.'/Modules' => app_path('Modules'), |
|
18 | - __DIR__.'/Modules/Core/Resources/Assets' => base_path('public/doc/assets'), |
|
19 | - __DIR__.'/../lang' => base_path('resources/lang'), |
|
20 | - __DIR__.'/../files/Handler.php' => app_path('Exceptions/Handler.php'), |
|
21 | - __DIR__.'/../files/AuthServiceProvider.php' => app_path('Providers/AuthServiceProvider.php'), |
|
22 | - __DIR__.'/../files/BroadcastServiceProvider.php' => app_path('Providers/BroadcastServiceProvider.php'), |
|
23 | - __DIR__.'/../files/Kernel.php' => app_path('Console/Kernel.php'), |
|
24 | - __DIR__.'/../files/channels.php' => app_path('routes/channels.php'), |
|
25 | - __DIR__.'/../phpcs.xml' => base_path('/phpcs.xml'), |
|
26 | - ]); |
|
9 | + /** |
|
10 | + * Perform post-registration booting of services. |
|
11 | + * |
|
12 | + * @return void |
|
13 | + */ |
|
14 | + public function boot() |
|
15 | + { |
|
16 | + $this->publishes([ |
|
17 | + __DIR__.'/Modules' => app_path('Modules'), |
|
18 | + __DIR__.'/Modules/Core/Resources/Assets' => base_path('public/doc/assets'), |
|
19 | + __DIR__.'/../lang' => base_path('resources/lang'), |
|
20 | + __DIR__.'/../files/Handler.php' => app_path('Exceptions/Handler.php'), |
|
21 | + __DIR__.'/../files/AuthServiceProvider.php' => app_path('Providers/AuthServiceProvider.php'), |
|
22 | + __DIR__.'/../files/BroadcastServiceProvider.php' => app_path('Providers/BroadcastServiceProvider.php'), |
|
23 | + __DIR__.'/../files/Kernel.php' => app_path('Console/Kernel.php'), |
|
24 | + __DIR__.'/../files/channels.php' => app_path('routes/channels.php'), |
|
25 | + __DIR__.'/../phpcs.xml' => base_path('/phpcs.xml'), |
|
26 | + ]); |
|
27 | 27 | |
28 | - $this->publishes([ |
|
29 | - __DIR__.'/../config/skeleton.php' => config_path('skeleton.php'), |
|
30 | - __DIR__.'/../files/auth.php' => config_path('auth.php'), |
|
31 | - ], 'config'); |
|
32 | - } |
|
28 | + $this->publishes([ |
|
29 | + __DIR__.'/../config/skeleton.php' => config_path('skeleton.php'), |
|
30 | + __DIR__.'/../files/auth.php' => config_path('auth.php'), |
|
31 | + ], 'config'); |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * Register any package services. |
|
36 | - * |
|
37 | - * @return void |
|
38 | - */ |
|
39 | - public function register() |
|
40 | - { |
|
41 | - $this->mergeConfigFrom( |
|
42 | - __DIR__.'/../config/skeleton.php', |
|
43 | - 'skeleton' |
|
44 | - ); |
|
45 | - } |
|
34 | + /** |
|
35 | + * Register any package services. |
|
36 | + * |
|
37 | + * @return void |
|
38 | + */ |
|
39 | + public function register() |
|
40 | + { |
|
41 | + $this->mergeConfigFrom( |
|
42 | + __DIR__.'/../config/skeleton.php', |
|
43 | + 'skeleton' |
|
44 | + ); |
|
45 | + } |
|
46 | 46 | } |
@@ -268,7 +268,7 @@ |
||
268 | 268 | * @param string $groupName The name of the requested group. |
269 | 269 | * @param integer $perPage Number of rows per page default 15. |
270 | 270 | * @param string $sortBy The name of the column to sort by. |
271 | - * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
271 | + * @param integer $desc Sort ascending or descinding (1: desc, 0: asc). |
|
272 | 272 | * @return \Illuminate\Http\Response |
273 | 273 | */ |
274 | 274 | public function group(Request $request, $groupName, $perPage = false, $sortBy = 'created_at', $desc = 1) |
@@ -11,285 +11,285 @@ |
||
11 | 11 | |
12 | 12 | class UsersController extends BaseApiController |
13 | 13 | { |
14 | - /** |
|
15 | - * List of all route actions that the base api controller |
|
16 | - * will skip permissions check for them. |
|
17 | - * @var array |
|
18 | - */ |
|
19 | - protected $skipPermissionCheck = ['account', 'logout', 'changePassword', 'saveProfile', 'account']; |
|
20 | - |
|
21 | - /** |
|
22 | - * List of all route actions that the base api controller |
|
23 | - * will skip login check for them. |
|
24 | - * @var array |
|
25 | - */ |
|
26 | - protected $skipLoginCheck = ['login', 'loginSocial', 'register', 'sendreset', 'resetpassword', 'refreshtoken', 'confirmEmail', 'resendEmailConfirmation']; |
|
27 | - |
|
28 | - /** |
|
29 | - * The validations rules used by the base api controller |
|
30 | - * to check before add. |
|
31 | - * @var array |
|
32 | - */ |
|
33 | - protected $validationRules = [ |
|
34 | - 'name' => 'nullable|string', |
|
35 | - 'email' => 'required|email|unique:users,email,{id}', |
|
36 | - 'password' => 'nullable|min:6' |
|
37 | - ]; |
|
38 | - |
|
39 | - /** |
|
40 | - * The loginProxy implementation. |
|
41 | - * |
|
42 | - * @var \App\Modules\Acl\Proxy\LoginProxy |
|
43 | - */ |
|
44 | - protected $loginProxy; |
|
45 | - |
|
46 | - /** |
|
47 | - * Init new object. |
|
48 | - * |
|
49 | - * @param LoginProxy $loginProxy |
|
50 | - * @param UserRepository $repo |
|
51 | - * @param CoreConfig $config |
|
52 | - * @return void |
|
53 | - */ |
|
54 | - public function __construct(LoginProxy $loginProxy, UserRepository $repo, CoreConfig $config) |
|
55 | - { |
|
56 | - $this->loginProxy = $loginProxy; |
|
57 | - parent::__construct($repo, $config, 'App\Modules\Acl\Http\Resources\AclUser'); |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Return the logged in user account. |
|
62 | - * |
|
63 | - * @return \Illuminate\Http\Response |
|
64 | - */ |
|
65 | - public function account() |
|
66 | - { |
|
67 | - return new $this->modelResource($this->repo->account($this->relations)); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Block the user. |
|
72 | - * |
|
73 | - * @param integer $id Id of the user. |
|
74 | - * @return \Illuminate\Http\Response |
|
75 | - */ |
|
76 | - public function block($id) |
|
77 | - { |
|
78 | - return new $this->modelResource($this->repo->block($id)); |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * Unblock the user. |
|
83 | - * |
|
84 | - * @param integer $id Id of the user. |
|
85 | - * @return \Illuminate\Http\Response |
|
86 | - */ |
|
87 | - public function unblock($id) |
|
88 | - { |
|
89 | - return new $this->modelResource($this->repo->unblock($id)); |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Logout the user. |
|
94 | - * |
|
95 | - * @return \Illuminate\Http\Response |
|
96 | - */ |
|
97 | - public function logout() |
|
98 | - { |
|
99 | - return new GeneralResource($this->loginProxy->logout()); |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Handle a registration request. |
|
104 | - * |
|
105 | - * @param \Illuminate\Http\Request $request |
|
106 | - * @return \Illuminate\Http\Response |
|
107 | - */ |
|
108 | - public function register(Request $request) |
|
109 | - { |
|
110 | - $this->validate($request, [ |
|
111 | - 'name' => 'nullable|string', |
|
112 | - 'email' => 'required|email|unique:users,email,{id}', |
|
113 | - 'password' => 'required|min:6' |
|
114 | - ]); |
|
115 | - |
|
116 | - return new $this->modelResource($this->repo->register($request->only('name', 'email', 'password'))); |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Handle a login request to the application. |
|
121 | - * |
|
122 | - * @param \Illuminate\Http\Request $request |
|
123 | - * @return \Illuminate\Http\Response |
|
124 | - */ |
|
125 | - public function login(Request $request) |
|
126 | - { |
|
127 | - $this->validate($request, [ |
|
128 | - 'email' => 'required|email', |
|
129 | - 'password' => 'required|min:6', |
|
130 | - 'admin' => 'nullable|boolean' |
|
131 | - ]); |
|
14 | + /** |
|
15 | + * List of all route actions that the base api controller |
|
16 | + * will skip permissions check for them. |
|
17 | + * @var array |
|
18 | + */ |
|
19 | + protected $skipPermissionCheck = ['account', 'logout', 'changePassword', 'saveProfile', 'account']; |
|
20 | + |
|
21 | + /** |
|
22 | + * List of all route actions that the base api controller |
|
23 | + * will skip login check for them. |
|
24 | + * @var array |
|
25 | + */ |
|
26 | + protected $skipLoginCheck = ['login', 'loginSocial', 'register', 'sendreset', 'resetpassword', 'refreshtoken', 'confirmEmail', 'resendEmailConfirmation']; |
|
27 | + |
|
28 | + /** |
|
29 | + * The validations rules used by the base api controller |
|
30 | + * to check before add. |
|
31 | + * @var array |
|
32 | + */ |
|
33 | + protected $validationRules = [ |
|
34 | + 'name' => 'nullable|string', |
|
35 | + 'email' => 'required|email|unique:users,email,{id}', |
|
36 | + 'password' => 'nullable|min:6' |
|
37 | + ]; |
|
38 | + |
|
39 | + /** |
|
40 | + * The loginProxy implementation. |
|
41 | + * |
|
42 | + * @var \App\Modules\Acl\Proxy\LoginProxy |
|
43 | + */ |
|
44 | + protected $loginProxy; |
|
45 | + |
|
46 | + /** |
|
47 | + * Init new object. |
|
48 | + * |
|
49 | + * @param LoginProxy $loginProxy |
|
50 | + * @param UserRepository $repo |
|
51 | + * @param CoreConfig $config |
|
52 | + * @return void |
|
53 | + */ |
|
54 | + public function __construct(LoginProxy $loginProxy, UserRepository $repo, CoreConfig $config) |
|
55 | + { |
|
56 | + $this->loginProxy = $loginProxy; |
|
57 | + parent::__construct($repo, $config, 'App\Modules\Acl\Http\Resources\AclUser'); |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Return the logged in user account. |
|
62 | + * |
|
63 | + * @return \Illuminate\Http\Response |
|
64 | + */ |
|
65 | + public function account() |
|
66 | + { |
|
67 | + return new $this->modelResource($this->repo->account($this->relations)); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Block the user. |
|
72 | + * |
|
73 | + * @param integer $id Id of the user. |
|
74 | + * @return \Illuminate\Http\Response |
|
75 | + */ |
|
76 | + public function block($id) |
|
77 | + { |
|
78 | + return new $this->modelResource($this->repo->block($id)); |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * Unblock the user. |
|
83 | + * |
|
84 | + * @param integer $id Id of the user. |
|
85 | + * @return \Illuminate\Http\Response |
|
86 | + */ |
|
87 | + public function unblock($id) |
|
88 | + { |
|
89 | + return new $this->modelResource($this->repo->unblock($id)); |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Logout the user. |
|
94 | + * |
|
95 | + * @return \Illuminate\Http\Response |
|
96 | + */ |
|
97 | + public function logout() |
|
98 | + { |
|
99 | + return new GeneralResource($this->loginProxy->logout()); |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Handle a registration request. |
|
104 | + * |
|
105 | + * @param \Illuminate\Http\Request $request |
|
106 | + * @return \Illuminate\Http\Response |
|
107 | + */ |
|
108 | + public function register(Request $request) |
|
109 | + { |
|
110 | + $this->validate($request, [ |
|
111 | + 'name' => 'nullable|string', |
|
112 | + 'email' => 'required|email|unique:users,email,{id}', |
|
113 | + 'password' => 'required|min:6' |
|
114 | + ]); |
|
115 | + |
|
116 | + return new $this->modelResource($this->repo->register($request->only('name', 'email', 'password'))); |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Handle a login request to the application. |
|
121 | + * |
|
122 | + * @param \Illuminate\Http\Request $request |
|
123 | + * @return \Illuminate\Http\Response |
|
124 | + */ |
|
125 | + public function login(Request $request) |
|
126 | + { |
|
127 | + $this->validate($request, [ |
|
128 | + 'email' => 'required|email', |
|
129 | + 'password' => 'required|min:6', |
|
130 | + 'admin' => 'nullable|boolean' |
|
131 | + ]); |
|
132 | 132 | |
133 | - $result = $this->loginProxy->login($request->only('email', 'password'), $request->get('admin')); |
|
134 | - return (new $this->modelResource($result['user']))->additional(['meta' => $result['tokens']]); |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * Handle a social login request of the none admin to the application. |
|
139 | - * |
|
140 | - * @param \Illuminate\Http\Request $request |
|
141 | - * @return \Illuminate\Http\Response |
|
142 | - */ |
|
143 | - public function loginSocial(Request $request) |
|
144 | - { |
|
145 | - $this->validate($request, [ |
|
146 | - 'auth_code' => 'required_without:access_token', |
|
147 | - 'access_token' => 'required_without:auth_code', |
|
148 | - 'type' => 'required|in:facebook,google' |
|
149 | - ]); |
|
150 | - |
|
151 | - $result = $this->repo->loginSocial($request->get('auth_code'), $request->get('access_token'), $request->get('type')); |
|
152 | - return (new $this->modelResource($result['user']))->additional(['meta' => $result['tokens']]); |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * Assign the given groups to the given user. |
|
157 | - * |
|
158 | - * @param \Illuminate\Http\Request $request |
|
159 | - * @return \Illuminate\Http\Response |
|
160 | - */ |
|
161 | - public function assigngroups(Request $request) |
|
162 | - { |
|
163 | - $this->validate($request, [ |
|
164 | - 'group_ids' => 'required|exists:groups,id', |
|
165 | - 'user_id' => 'required|exists:users,id' |
|
166 | - ]); |
|
167 | - |
|
168 | - return new $this->modelResource($this->repo->assignGroups($request->get('user_id'), $request->get('group_ids'))); |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * Send a reset link to the given user. |
|
173 | - * |
|
174 | - * @param \Illuminate\Http\Request $request |
|
175 | - * @return \Illuminate\Http\Response |
|
176 | - */ |
|
177 | - public function sendreset(Request $request) |
|
178 | - { |
|
179 | - $this->validate($request, ['email' => 'required|email']); |
|
180 | - |
|
181 | - return new GeneralResource($this->repo->sendReset($request->get('email'))); |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * Reset the given user's password. |
|
186 | - * |
|
187 | - * @param \Illuminate\Http\Request $request |
|
188 | - * @return \Illuminate\Http\Response |
|
189 | - */ |
|
190 | - public function resetpassword(Request $request) |
|
191 | - { |
|
192 | - $this->validate($request, [ |
|
193 | - 'token' => 'required', |
|
194 | - 'email' => 'required|email', |
|
195 | - 'password' => 'required|confirmed|min:6', |
|
196 | - 'password_confirmation' => 'required', |
|
197 | - ]); |
|
198 | - |
|
199 | - return new GeneralResource($this->repo->resetPassword($request->only('email', 'password', 'password_confirmation', 'token'))); |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * Change the logged in user password. |
|
204 | - * |
|
205 | - * @param \Illuminate\Http\Request $request |
|
206 | - * @return \Illuminate\Http\Response |
|
207 | - */ |
|
208 | - public function changePassword(Request $request) |
|
209 | - { |
|
210 | - $this->validate($request, [ |
|
211 | - 'old_password' => 'required', |
|
212 | - 'password' => 'required|confirmed|min:6', |
|
213 | - 'password_confirmation' => 'required', |
|
214 | - ]); |
|
215 | - |
|
216 | - return new GeneralResource($this->repo->changePassword($request->only('old_password', 'password', 'password_confirmation'))); |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * Confirm email using the confirmation code. |
|
221 | - * |
|
222 | - * @param \Illuminate\Http\Request $request |
|
223 | - * @return \Illuminate\Http\Response |
|
224 | - */ |
|
225 | - public function confirmEmail(Request $request) |
|
226 | - { |
|
227 | - $this->validate($request, [ |
|
228 | - 'confirmation_code' => 'required|string' |
|
229 | - ]); |
|
230 | - |
|
231 | - return new GeneralResource($this->repo->confirmEmail($request->only('confirmation_code'))); |
|
232 | - } |
|
233 | - |
|
234 | - /** |
|
235 | - * Resend the email confirmation mail. |
|
236 | - * |
|
237 | - * @param \Illuminate\Http\Request $request |
|
238 | - * @return \Illuminate\Http\Response |
|
239 | - */ |
|
240 | - public function resendEmailConfirmation(Request $request) |
|
241 | - { |
|
242 | - $this->validate($request, [ |
|
243 | - 'email' => 'required|exists:users,email' |
|
244 | - ]); |
|
245 | - |
|
246 | - return new GeneralResource($this->repo->sendConfirmationEmail($request->get('email'))); |
|
247 | - } |
|
248 | - |
|
249 | - /** |
|
250 | - * Refresh the expired login token. |
|
251 | - * |
|
252 | - * @param \Illuminate\Http\Request $request |
|
253 | - * @return \Illuminate\Http\Response |
|
254 | - */ |
|
255 | - public function refreshtoken(Request $request) |
|
256 | - { |
|
257 | - $this->validate($request, [ |
|
258 | - 'refreshtoken' => 'required', |
|
259 | - ]); |
|
260 | - |
|
261 | - return new GeneralResource($this->loginProxy->refreshtoken($request->get('refreshtoken'))); |
|
262 | - } |
|
263 | - |
|
264 | - /** |
|
265 | - * Paginate all users with in the given group. |
|
266 | - * |
|
267 | - * @param \Illuminate\Http\Request $request |
|
268 | - * @param string $groupName The name of the requested group. |
|
269 | - * @param integer $perPage Number of rows per page default 15. |
|
270 | - * @param string $sortBy The name of the column to sort by. |
|
271 | - * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
272 | - * @return \Illuminate\Http\Response |
|
273 | - */ |
|
274 | - public function group(Request $request, $groupName, $perPage = false, $sortBy = 'created_at', $desc = 1) |
|
275 | - { |
|
276 | - return $this->modelResource::collection($this->repo->group($request->all(), $groupName, $this->relations, $perPage, $sortBy, $desc)); |
|
277 | - } |
|
278 | - |
|
279 | - /** |
|
280 | - * Save the given data to the logged in user. |
|
281 | - * |
|
282 | - * @param \Illuminate\Http\Request $request |
|
283 | - * @return \Illuminate\Http\Response |
|
284 | - */ |
|
285 | - public function saveProfile(Request $request) |
|
286 | - { |
|
287 | - $this->validate($request, [ |
|
288 | - 'profile_picture' => 'nullable|string', |
|
289 | - 'name' => 'nullable|string', |
|
290 | - 'email' => 'required|email|unique:users,email,'.\Auth::id() |
|
291 | - ]); |
|
292 | - |
|
293 | - return new $this->modelResource($this->repo->saveProfile($request->only('name', 'email', 'profile_picture'))); |
|
294 | - } |
|
133 | + $result = $this->loginProxy->login($request->only('email', 'password'), $request->get('admin')); |
|
134 | + return (new $this->modelResource($result['user']))->additional(['meta' => $result['tokens']]); |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * Handle a social login request of the none admin to the application. |
|
139 | + * |
|
140 | + * @param \Illuminate\Http\Request $request |
|
141 | + * @return \Illuminate\Http\Response |
|
142 | + */ |
|
143 | + public function loginSocial(Request $request) |
|
144 | + { |
|
145 | + $this->validate($request, [ |
|
146 | + 'auth_code' => 'required_without:access_token', |
|
147 | + 'access_token' => 'required_without:auth_code', |
|
148 | + 'type' => 'required|in:facebook,google' |
|
149 | + ]); |
|
150 | + |
|
151 | + $result = $this->repo->loginSocial($request->get('auth_code'), $request->get('access_token'), $request->get('type')); |
|
152 | + return (new $this->modelResource($result['user']))->additional(['meta' => $result['tokens']]); |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * Assign the given groups to the given user. |
|
157 | + * |
|
158 | + * @param \Illuminate\Http\Request $request |
|
159 | + * @return \Illuminate\Http\Response |
|
160 | + */ |
|
161 | + public function assigngroups(Request $request) |
|
162 | + { |
|
163 | + $this->validate($request, [ |
|
164 | + 'group_ids' => 'required|exists:groups,id', |
|
165 | + 'user_id' => 'required|exists:users,id' |
|
166 | + ]); |
|
167 | + |
|
168 | + return new $this->modelResource($this->repo->assignGroups($request->get('user_id'), $request->get('group_ids'))); |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * Send a reset link to the given user. |
|
173 | + * |
|
174 | + * @param \Illuminate\Http\Request $request |
|
175 | + * @return \Illuminate\Http\Response |
|
176 | + */ |
|
177 | + public function sendreset(Request $request) |
|
178 | + { |
|
179 | + $this->validate($request, ['email' => 'required|email']); |
|
180 | + |
|
181 | + return new GeneralResource($this->repo->sendReset($request->get('email'))); |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * Reset the given user's password. |
|
186 | + * |
|
187 | + * @param \Illuminate\Http\Request $request |
|
188 | + * @return \Illuminate\Http\Response |
|
189 | + */ |
|
190 | + public function resetpassword(Request $request) |
|
191 | + { |
|
192 | + $this->validate($request, [ |
|
193 | + 'token' => 'required', |
|
194 | + 'email' => 'required|email', |
|
195 | + 'password' => 'required|confirmed|min:6', |
|
196 | + 'password_confirmation' => 'required', |
|
197 | + ]); |
|
198 | + |
|
199 | + return new GeneralResource($this->repo->resetPassword($request->only('email', 'password', 'password_confirmation', 'token'))); |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * Change the logged in user password. |
|
204 | + * |
|
205 | + * @param \Illuminate\Http\Request $request |
|
206 | + * @return \Illuminate\Http\Response |
|
207 | + */ |
|
208 | + public function changePassword(Request $request) |
|
209 | + { |
|
210 | + $this->validate($request, [ |
|
211 | + 'old_password' => 'required', |
|
212 | + 'password' => 'required|confirmed|min:6', |
|
213 | + 'password_confirmation' => 'required', |
|
214 | + ]); |
|
215 | + |
|
216 | + return new GeneralResource($this->repo->changePassword($request->only('old_password', 'password', 'password_confirmation'))); |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * Confirm email using the confirmation code. |
|
221 | + * |
|
222 | + * @param \Illuminate\Http\Request $request |
|
223 | + * @return \Illuminate\Http\Response |
|
224 | + */ |
|
225 | + public function confirmEmail(Request $request) |
|
226 | + { |
|
227 | + $this->validate($request, [ |
|
228 | + 'confirmation_code' => 'required|string' |
|
229 | + ]); |
|
230 | + |
|
231 | + return new GeneralResource($this->repo->confirmEmail($request->only('confirmation_code'))); |
|
232 | + } |
|
233 | + |
|
234 | + /** |
|
235 | + * Resend the email confirmation mail. |
|
236 | + * |
|
237 | + * @param \Illuminate\Http\Request $request |
|
238 | + * @return \Illuminate\Http\Response |
|
239 | + */ |
|
240 | + public function resendEmailConfirmation(Request $request) |
|
241 | + { |
|
242 | + $this->validate($request, [ |
|
243 | + 'email' => 'required|exists:users,email' |
|
244 | + ]); |
|
245 | + |
|
246 | + return new GeneralResource($this->repo->sendConfirmationEmail($request->get('email'))); |
|
247 | + } |
|
248 | + |
|
249 | + /** |
|
250 | + * Refresh the expired login token. |
|
251 | + * |
|
252 | + * @param \Illuminate\Http\Request $request |
|
253 | + * @return \Illuminate\Http\Response |
|
254 | + */ |
|
255 | + public function refreshtoken(Request $request) |
|
256 | + { |
|
257 | + $this->validate($request, [ |
|
258 | + 'refreshtoken' => 'required', |
|
259 | + ]); |
|
260 | + |
|
261 | + return new GeneralResource($this->loginProxy->refreshtoken($request->get('refreshtoken'))); |
|
262 | + } |
|
263 | + |
|
264 | + /** |
|
265 | + * Paginate all users with in the given group. |
|
266 | + * |
|
267 | + * @param \Illuminate\Http\Request $request |
|
268 | + * @param string $groupName The name of the requested group. |
|
269 | + * @param integer $perPage Number of rows per page default 15. |
|
270 | + * @param string $sortBy The name of the column to sort by. |
|
271 | + * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
272 | + * @return \Illuminate\Http\Response |
|
273 | + */ |
|
274 | + public function group(Request $request, $groupName, $perPage = false, $sortBy = 'created_at', $desc = 1) |
|
275 | + { |
|
276 | + return $this->modelResource::collection($this->repo->group($request->all(), $groupName, $this->relations, $perPage, $sortBy, $desc)); |
|
277 | + } |
|
278 | + |
|
279 | + /** |
|
280 | + * Save the given data to the logged in user. |
|
281 | + * |
|
282 | + * @param \Illuminate\Http\Request $request |
|
283 | + * @return \Illuminate\Http\Response |
|
284 | + */ |
|
285 | + public function saveProfile(Request $request) |
|
286 | + { |
|
287 | + $this->validate($request, [ |
|
288 | + 'profile_picture' => 'nullable|string', |
|
289 | + 'name' => 'nullable|string', |
|
290 | + 'email' => 'required|email|unique:users,email,'.\Auth::id() |
|
291 | + ]); |
|
292 | + |
|
293 | + return new $this->modelResource($this->repo->saveProfile($request->only('name', 'email', 'profile_picture'))); |
|
294 | + } |
|
295 | 295 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * Init new object. |
35 | 35 | * |
36 | 36 | * @param mixed $repo |
37 | - * @param CoreConfig $config |
|
37 | + * @param \App\Modules\Core\Utl\CoreConfig $config |
|
38 | 38 | * @param string $modelResource |
39 | 39 | * @return void |
40 | 40 | */ |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | * Fetch all records with relations from storage. |
60 | 60 | * |
61 | 61 | * @param string $sortBy The name of the column to sort by. |
62 | - * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
62 | + * @param integer $desc Sort ascending or descinding (1: desc, 0: asc). |
|
63 | 63 | * @return \Illuminate\Http\Response |
64 | 64 | */ |
65 | 65 | public function index($sortBy = 'created_at', $desc = 1) |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | * @param string $query The search text. |
86 | 86 | * @param integer $perPage Number of rows per page default 15. |
87 | 87 | * @param string $sortBy The name of the column to sort by. |
88 | - * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
88 | + * @param integer $desc Sort ascending or descinding (1: desc, 0: asc). |
|
89 | 89 | * @return \Illuminate\Http\Response |
90 | 90 | */ |
91 | 91 | public function search($query = '', $perPage = 15, $sortBy = 'created_at', $desc = 1) |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | * |
100 | 100 | * @param \Illuminate\Http\Request $request |
101 | 101 | * @param string $sortBy The name of the column to sort by. |
102 | - * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
102 | + * @param integer $desc Sort ascending or descinding (1: desc, 0: asc). |
|
103 | 103 | * @return \Illuminate\Http\Response |
104 | 104 | */ |
105 | 105 | public function findby(Request $request, $sortBy = 'created_at', $desc = 1) |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | * |
125 | 125 | * @param integer $perPage Number of rows per page default 15. |
126 | 126 | * @param string $sortBy The name of the column to sort by. |
127 | - * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
127 | + * @param integer $desc Sort ascending or descinding (1: desc, 0: asc). |
|
128 | 128 | * @return \Illuminate\Http\Response |
129 | 129 | */ |
130 | 130 | public function paginate($perPage = 15, $sortBy = 'created_at', $desc = 1) |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | * @param \Illuminate\Http\Request $request |
140 | 140 | * @param integer $perPage Number of rows per page default 15. |
141 | 141 | * @param string $sortBy The name of the column to sort by. |
142 | - * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
142 | + * @param integer $desc Sort ascending or descinding (1: desc, 0: asc). |
|
143 | 143 | * @return \Illuminate\Http\Response |
144 | 144 | */ |
145 | 145 | public function paginateby(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | * @param \Illuminate\Http\Request $request |
190 | 190 | * @param integer $perPage Number of rows per page default 15. |
191 | 191 | * @param string $sortBy The name of the column to sort by. |
192 | - * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
192 | + * @param integer $desc Sort ascending or descinding (1: desc, 0: asc). |
|
193 | 193 | * @return \Illuminate\Http\Response |
194 | 194 | */ |
195 | 195 | public function deleted(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) |
@@ -9,303 +9,303 @@ |
||
9 | 9 | |
10 | 10 | class BaseApiController extends Controller |
11 | 11 | { |
12 | - /** |
|
13 | - * The config implementation. |
|
14 | - * |
|
15 | - * @var array |
|
16 | - */ |
|
17 | - protected $config; |
|
18 | - |
|
19 | - /** |
|
20 | - * The relations implementation. |
|
21 | - * |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected $relations; |
|
25 | - |
|
26 | - /** |
|
27 | - * The repo implementation. |
|
28 | - * |
|
29 | - * @var object |
|
30 | - */ |
|
31 | - protected $repo; |
|
32 | - |
|
33 | - /** |
|
34 | - * Init new object. |
|
35 | - * |
|
36 | - * @param mixed $repo |
|
37 | - * @param CoreConfig $config |
|
38 | - * @param string $modelResource |
|
39 | - * @return void |
|
40 | - */ |
|
41 | - public function __construct($repo, $config, $modelResource) |
|
42 | - { |
|
43 | - $this->repo = $repo; |
|
44 | - $this->modelResource = $modelResource; |
|
45 | - $this->config = $config->getConfig(); |
|
46 | - $this->modelName = explode('\\', get_called_class()); |
|
47 | - $this->modelName = lcfirst(str_replace('Controller', '', end($this->modelName))); |
|
48 | - $this->validationRules = property_exists($this, 'validationRules') ? $this->validationRules : false; |
|
49 | - $this->skipPermissionCheck = property_exists($this, 'skipPermissionCheck') ? $this->skipPermissionCheck : []; |
|
50 | - $this->skipLoginCheck = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : []; |
|
51 | - $route = explode('@', \Route::currentRouteAction())[1]; |
|
52 | - |
|
53 | - $this->setSessions(); |
|
54 | - $this->checkPermission($route); |
|
55 | - $this->setRelations($route); |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * Fetch all records with relations from storage. |
|
60 | - * |
|
61 | - * @param string $sortBy The name of the column to sort by. |
|
62 | - * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
63 | - * @return \Illuminate\Http\Response |
|
64 | - */ |
|
65 | - public function index($sortBy = 'created_at', $desc = 1) |
|
66 | - { |
|
67 | - return $this->modelResource::collection($this->repo->all($this->relations, $sortBy, $desc)); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Fetch the single object with relations from storage. |
|
72 | - * |
|
73 | - * @param integer $id Id of the requested model. |
|
74 | - * @return \Illuminate\Http\Response |
|
75 | - */ |
|
76 | - public function find($id) |
|
77 | - { |
|
78 | - return new $this->modelResource($this->repo->find($id, $this->relations)); |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * Paginate all records with relations from storage |
|
83 | - * that matche the given query. |
|
84 | - * |
|
85 | - * @param string $query The search text. |
|
86 | - * @param integer $perPage Number of rows per page default 15. |
|
87 | - * @param string $sortBy The name of the column to sort by. |
|
88 | - * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
89 | - * @return \Illuminate\Http\Response |
|
90 | - */ |
|
91 | - public function search($query = '', $perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
92 | - { |
|
93 | - return $this->modelResource::collection($this->repo->search($query, $perPage, $this->relations, $sortBy, $desc)); |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Fetch records from the storage based on the given |
|
98 | - * condition. |
|
99 | - * |
|
100 | - * @param \Illuminate\Http\Request $request |
|
101 | - * @param string $sortBy The name of the column to sort by. |
|
102 | - * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
103 | - * @return \Illuminate\Http\Response |
|
104 | - */ |
|
105 | - public function findby(Request $request, $sortBy = 'created_at', $desc = 1) |
|
106 | - { |
|
107 | - return $this->modelResource::collection($this->repo->findBy($request->all(), $this->relations, $sortBy, $desc)); |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Fetch the first record from the storage based on the given |
|
112 | - * condition. |
|
113 | - * |
|
114 | - * @param \Illuminate\Http\Request $request |
|
115 | - * @return \Illuminate\Http\Response |
|
116 | - */ |
|
117 | - public function first(Request $request) |
|
118 | - { |
|
119 | - return new $this->modelResource($this->repo->first($request->all(), $this->relations)); |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Paginate all records with relations from storage. |
|
124 | - * |
|
125 | - * @param integer $perPage Number of rows per page default 15. |
|
126 | - * @param string $sortBy The name of the column to sort by. |
|
127 | - * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
128 | - * @return \Illuminate\Http\Response |
|
129 | - */ |
|
130 | - public function paginate($perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
131 | - { |
|
132 | - return $this->modelResource::collection($this->repo->paginate($perPage, $this->relations, $sortBy, $desc)); |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * Fetch all records with relations based on |
|
137 | - * the given condition from storage in pages. |
|
138 | - * |
|
139 | - * @param \Illuminate\Http\Request $request |
|
140 | - * @param integer $perPage Number of rows per page default 15. |
|
141 | - * @param string $sortBy The name of the column to sort by. |
|
142 | - * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
143 | - * @return \Illuminate\Http\Response |
|
144 | - */ |
|
145 | - public function paginateby(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
146 | - { |
|
147 | - return $this->modelResource::collection($this->repo->paginateBy($request->all(), $perPage, $this->relations, $sortBy, $desc)); |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * Save the given model to storage. |
|
152 | - * |
|
153 | - * @param \Illuminate\Http\Request $request |
|
154 | - * @return \Illuminate\Http\Response |
|
155 | - */ |
|
156 | - public function save(Request $request) |
|
157 | - { |
|
158 | - foreach ($this->validationRules as &$rule) { |
|
159 | - if (strpos($rule, 'exists') && ! strpos($rule, 'deleted_at,NULL')) { |
|
160 | - $rule .= ',deleted_at,NULL'; |
|
161 | - } |
|
162 | - |
|
163 | - if ($request->has('id')) { |
|
164 | - $rule = str_replace('{id}', $request->get('id'), $rule); |
|
165 | - } else { |
|
166 | - $rule = str_replace(',{id}', '', $rule); |
|
167 | - } |
|
168 | - } |
|
12 | + /** |
|
13 | + * The config implementation. |
|
14 | + * |
|
15 | + * @var array |
|
16 | + */ |
|
17 | + protected $config; |
|
18 | + |
|
19 | + /** |
|
20 | + * The relations implementation. |
|
21 | + * |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + protected $relations; |
|
25 | + |
|
26 | + /** |
|
27 | + * The repo implementation. |
|
28 | + * |
|
29 | + * @var object |
|
30 | + */ |
|
31 | + protected $repo; |
|
32 | + |
|
33 | + /** |
|
34 | + * Init new object. |
|
35 | + * |
|
36 | + * @param mixed $repo |
|
37 | + * @param CoreConfig $config |
|
38 | + * @param string $modelResource |
|
39 | + * @return void |
|
40 | + */ |
|
41 | + public function __construct($repo, $config, $modelResource) |
|
42 | + { |
|
43 | + $this->repo = $repo; |
|
44 | + $this->modelResource = $modelResource; |
|
45 | + $this->config = $config->getConfig(); |
|
46 | + $this->modelName = explode('\\', get_called_class()); |
|
47 | + $this->modelName = lcfirst(str_replace('Controller', '', end($this->modelName))); |
|
48 | + $this->validationRules = property_exists($this, 'validationRules') ? $this->validationRules : false; |
|
49 | + $this->skipPermissionCheck = property_exists($this, 'skipPermissionCheck') ? $this->skipPermissionCheck : []; |
|
50 | + $this->skipLoginCheck = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : []; |
|
51 | + $route = explode('@', \Route::currentRouteAction())[1]; |
|
52 | + |
|
53 | + $this->setSessions(); |
|
54 | + $this->checkPermission($route); |
|
55 | + $this->setRelations($route); |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * Fetch all records with relations from storage. |
|
60 | + * |
|
61 | + * @param string $sortBy The name of the column to sort by. |
|
62 | + * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
63 | + * @return \Illuminate\Http\Response |
|
64 | + */ |
|
65 | + public function index($sortBy = 'created_at', $desc = 1) |
|
66 | + { |
|
67 | + return $this->modelResource::collection($this->repo->all($this->relations, $sortBy, $desc)); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Fetch the single object with relations from storage. |
|
72 | + * |
|
73 | + * @param integer $id Id of the requested model. |
|
74 | + * @return \Illuminate\Http\Response |
|
75 | + */ |
|
76 | + public function find($id) |
|
77 | + { |
|
78 | + return new $this->modelResource($this->repo->find($id, $this->relations)); |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * Paginate all records with relations from storage |
|
83 | + * that matche the given query. |
|
84 | + * |
|
85 | + * @param string $query The search text. |
|
86 | + * @param integer $perPage Number of rows per page default 15. |
|
87 | + * @param string $sortBy The name of the column to sort by. |
|
88 | + * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
89 | + * @return \Illuminate\Http\Response |
|
90 | + */ |
|
91 | + public function search($query = '', $perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
92 | + { |
|
93 | + return $this->modelResource::collection($this->repo->search($query, $perPage, $this->relations, $sortBy, $desc)); |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Fetch records from the storage based on the given |
|
98 | + * condition. |
|
99 | + * |
|
100 | + * @param \Illuminate\Http\Request $request |
|
101 | + * @param string $sortBy The name of the column to sort by. |
|
102 | + * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
103 | + * @return \Illuminate\Http\Response |
|
104 | + */ |
|
105 | + public function findby(Request $request, $sortBy = 'created_at', $desc = 1) |
|
106 | + { |
|
107 | + return $this->modelResource::collection($this->repo->findBy($request->all(), $this->relations, $sortBy, $desc)); |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Fetch the first record from the storage based on the given |
|
112 | + * condition. |
|
113 | + * |
|
114 | + * @param \Illuminate\Http\Request $request |
|
115 | + * @return \Illuminate\Http\Response |
|
116 | + */ |
|
117 | + public function first(Request $request) |
|
118 | + { |
|
119 | + return new $this->modelResource($this->repo->first($request->all(), $this->relations)); |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Paginate all records with relations from storage. |
|
124 | + * |
|
125 | + * @param integer $perPage Number of rows per page default 15. |
|
126 | + * @param string $sortBy The name of the column to sort by. |
|
127 | + * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
128 | + * @return \Illuminate\Http\Response |
|
129 | + */ |
|
130 | + public function paginate($perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
131 | + { |
|
132 | + return $this->modelResource::collection($this->repo->paginate($perPage, $this->relations, $sortBy, $desc)); |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * Fetch all records with relations based on |
|
137 | + * the given condition from storage in pages. |
|
138 | + * |
|
139 | + * @param \Illuminate\Http\Request $request |
|
140 | + * @param integer $perPage Number of rows per page default 15. |
|
141 | + * @param string $sortBy The name of the column to sort by. |
|
142 | + * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
143 | + * @return \Illuminate\Http\Response |
|
144 | + */ |
|
145 | + public function paginateby(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
146 | + { |
|
147 | + return $this->modelResource::collection($this->repo->paginateBy($request->all(), $perPage, $this->relations, $sortBy, $desc)); |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * Save the given model to storage. |
|
152 | + * |
|
153 | + * @param \Illuminate\Http\Request $request |
|
154 | + * @return \Illuminate\Http\Response |
|
155 | + */ |
|
156 | + public function save(Request $request) |
|
157 | + { |
|
158 | + foreach ($this->validationRules as &$rule) { |
|
159 | + if (strpos($rule, 'exists') && ! strpos($rule, 'deleted_at,NULL')) { |
|
160 | + $rule .= ',deleted_at,NULL'; |
|
161 | + } |
|
162 | + |
|
163 | + if ($request->has('id')) { |
|
164 | + $rule = str_replace('{id}', $request->get('id'), $rule); |
|
165 | + } else { |
|
166 | + $rule = str_replace(',{id}', '', $rule); |
|
167 | + } |
|
168 | + } |
|
169 | 169 | |
170 | - $this->validate($request, $this->validationRules); |
|
171 | - |
|
172 | - return $this->modelResource::collection($this->repo->save($request->all())); |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * Delete by the given id from storage. |
|
177 | - * |
|
178 | - * @param integer $id Id of the deleted model. |
|
179 | - * @return \Illuminate\Http\Response |
|
180 | - */ |
|
181 | - public function delete($id) |
|
182 | - { |
|
183 | - return new GeneralResource($this->repo->delete($id)); |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * Return the deleted models in pages based on the given conditions. |
|
188 | - * |
|
189 | - * @param \Illuminate\Http\Request $request |
|
190 | - * @param integer $perPage Number of rows per page default 15. |
|
191 | - * @param string $sortBy The name of the column to sort by. |
|
192 | - * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
193 | - * @return \Illuminate\Http\Response |
|
194 | - */ |
|
195 | - public function deleted(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
196 | - { |
|
197 | - return $this->modelResource::collection($this->repo->deleted($request->all(), $perPage, $sortBy, $desc)); |
|
198 | - } |
|
199 | - |
|
200 | - /** |
|
201 | - * Restore the deleted model. |
|
202 | - * |
|
203 | - * @param integer $id Id of the restored model. |
|
204 | - * @return \Illuminate\Http\Response |
|
205 | - */ |
|
206 | - public function restore($id) |
|
207 | - { |
|
208 | - return new GeneralResource($this->repo->restore($id)); |
|
209 | - } |
|
210 | - |
|
211 | - /** |
|
212 | - * Check if the logged in user can do the given permission. |
|
213 | - * |
|
214 | - * @param string $permission |
|
215 | - * @return void |
|
216 | - */ |
|
217 | - private function checkPermission($permission) |
|
218 | - { |
|
219 | - \Auth::shouldUse('api'); |
|
220 | - $this->middleware('auth:api', ['except' => $this->skipLoginCheck]); |
|
170 | + $this->validate($request, $this->validationRules); |
|
171 | + |
|
172 | + return $this->modelResource::collection($this->repo->save($request->all())); |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * Delete by the given id from storage. |
|
177 | + * |
|
178 | + * @param integer $id Id of the deleted model. |
|
179 | + * @return \Illuminate\Http\Response |
|
180 | + */ |
|
181 | + public function delete($id) |
|
182 | + { |
|
183 | + return new GeneralResource($this->repo->delete($id)); |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * Return the deleted models in pages based on the given conditions. |
|
188 | + * |
|
189 | + * @param \Illuminate\Http\Request $request |
|
190 | + * @param integer $perPage Number of rows per page default 15. |
|
191 | + * @param string $sortBy The name of the column to sort by. |
|
192 | + * @param boolean $desc Sort ascending or descinding (1: desc, 0: asc). |
|
193 | + * @return \Illuminate\Http\Response |
|
194 | + */ |
|
195 | + public function deleted(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
196 | + { |
|
197 | + return $this->modelResource::collection($this->repo->deleted($request->all(), $perPage, $sortBy, $desc)); |
|
198 | + } |
|
199 | + |
|
200 | + /** |
|
201 | + * Restore the deleted model. |
|
202 | + * |
|
203 | + * @param integer $id Id of the restored model. |
|
204 | + * @return \Illuminate\Http\Response |
|
205 | + */ |
|
206 | + public function restore($id) |
|
207 | + { |
|
208 | + return new GeneralResource($this->repo->restore($id)); |
|
209 | + } |
|
210 | + |
|
211 | + /** |
|
212 | + * Check if the logged in user can do the given permission. |
|
213 | + * |
|
214 | + * @param string $permission |
|
215 | + * @return void |
|
216 | + */ |
|
217 | + private function checkPermission($permission) |
|
218 | + { |
|
219 | + \Auth::shouldUse('api'); |
|
220 | + $this->middleware('auth:api', ['except' => $this->skipLoginCheck]); |
|
221 | 221 | |
222 | - if (! in_array($permission, $this->skipLoginCheck) && $user = \Auth::user()) { |
|
223 | - $user = \Auth::user(); |
|
224 | - $permission = $permission !== 'index' ? $permission : 'list'; |
|
225 | - $isPasswordClient = $user->token()->client->password_client; |
|
226 | - $this->updateLocaleAndTimezone($user); |
|
227 | - |
|
228 | - if ($user->blocked) { |
|
229 | - \ErrorHandler::userIsBlocked(); |
|
230 | - } |
|
231 | - |
|
232 | - if ($isPasswordClient && (in_array($permission, $this->skipPermissionCheck) || \Core::users()->can($permission, $this->modelName))) { |
|
233 | - } elseif (! $isPasswordClient && $user->tokenCan($this->modelName.'-'.$permission)) { |
|
234 | - } else { |
|
235 | - \ErrorHandler::noPermissions(); |
|
236 | - } |
|
237 | - } |
|
238 | - } |
|
239 | - |
|
240 | - /** |
|
241 | - * Set sessions based on the given headers in the request. |
|
242 | - * |
|
243 | - * @return void |
|
244 | - */ |
|
245 | - private function setSessions() |
|
246 | - { |
|
247 | - \Session::put('time-zone', \Request::header('time-zone') ?: 0); |
|
248 | - |
|
249 | - $locale = \Request::header('locale'); |
|
250 | - switch ($locale) { |
|
251 | - case 'en': |
|
252 | - \App::setLocale('en'); |
|
253 | - \Session::put('locale', 'en'); |
|
254 | - break; |
|
255 | - |
|
256 | - case 'ar': |
|
257 | - \App::setLocale('ar'); |
|
258 | - \Session::put('locale', 'ar'); |
|
259 | - break; |
|
260 | - |
|
261 | - case 'all': |
|
262 | - \App::setLocale('en'); |
|
263 | - \Session::put('locale', 'all'); |
|
264 | - break; |
|
265 | - |
|
266 | - default: |
|
267 | - \App::setLocale('en'); |
|
268 | - \Session::put('locale', 'en'); |
|
269 | - break; |
|
270 | - } |
|
271 | - } |
|
272 | - |
|
273 | - /** |
|
274 | - * Set relation based on the called api. |
|
275 | - * |
|
276 | - * @param string $route |
|
277 | - * @return void |
|
278 | - */ |
|
279 | - private function setRelations($route) |
|
280 | - { |
|
281 | - $route = $route !== 'index' ? $route : 'list'; |
|
282 | - $relations = Arr::get($this->config['relations'], $this->modelName, false); |
|
283 | - $this->relations = $relations && isset($relations[$route]) ? $relations[$route] : []; |
|
284 | - } |
|
285 | - |
|
286 | - /** |
|
287 | - * Update the logged in user locale and time zone. |
|
288 | - * |
|
289 | - * @param object $user |
|
290 | - * @return void |
|
291 | - */ |
|
292 | - private function updateLocaleAndTimezone($user) |
|
293 | - { |
|
294 | - $update = false; |
|
295 | - $locale = \Session::get('locale'); |
|
296 | - $timezone = \Session::get('time-zone'); |
|
297 | - if ($locale && $locale !== 'all' && $locale !== $user->locale) { |
|
298 | - $user->locale = $locale; |
|
299 | - $update = true; |
|
300 | - } |
|
301 | - |
|
302 | - if ($timezone && $timezone !== $user->timezone) { |
|
303 | - $user->timezone = $timezone; |
|
304 | - $update = true; |
|
305 | - } |
|
306 | - |
|
307 | - if ($update) { |
|
308 | - $user->save(); |
|
309 | - } |
|
310 | - } |
|
222 | + if (! in_array($permission, $this->skipLoginCheck) && $user = \Auth::user()) { |
|
223 | + $user = \Auth::user(); |
|
224 | + $permission = $permission !== 'index' ? $permission : 'list'; |
|
225 | + $isPasswordClient = $user->token()->client->password_client; |
|
226 | + $this->updateLocaleAndTimezone($user); |
|
227 | + |
|
228 | + if ($user->blocked) { |
|
229 | + \ErrorHandler::userIsBlocked(); |
|
230 | + } |
|
231 | + |
|
232 | + if ($isPasswordClient && (in_array($permission, $this->skipPermissionCheck) || \Core::users()->can($permission, $this->modelName))) { |
|
233 | + } elseif (! $isPasswordClient && $user->tokenCan($this->modelName.'-'.$permission)) { |
|
234 | + } else { |
|
235 | + \ErrorHandler::noPermissions(); |
|
236 | + } |
|
237 | + } |
|
238 | + } |
|
239 | + |
|
240 | + /** |
|
241 | + * Set sessions based on the given headers in the request. |
|
242 | + * |
|
243 | + * @return void |
|
244 | + */ |
|
245 | + private function setSessions() |
|
246 | + { |
|
247 | + \Session::put('time-zone', \Request::header('time-zone') ?: 0); |
|
248 | + |
|
249 | + $locale = \Request::header('locale'); |
|
250 | + switch ($locale) { |
|
251 | + case 'en': |
|
252 | + \App::setLocale('en'); |
|
253 | + \Session::put('locale', 'en'); |
|
254 | + break; |
|
255 | + |
|
256 | + case 'ar': |
|
257 | + \App::setLocale('ar'); |
|
258 | + \Session::put('locale', 'ar'); |
|
259 | + break; |
|
260 | + |
|
261 | + case 'all': |
|
262 | + \App::setLocale('en'); |
|
263 | + \Session::put('locale', 'all'); |
|
264 | + break; |
|
265 | + |
|
266 | + default: |
|
267 | + \App::setLocale('en'); |
|
268 | + \Session::put('locale', 'en'); |
|
269 | + break; |
|
270 | + } |
|
271 | + } |
|
272 | + |
|
273 | + /** |
|
274 | + * Set relation based on the called api. |
|
275 | + * |
|
276 | + * @param string $route |
|
277 | + * @return void |
|
278 | + */ |
|
279 | + private function setRelations($route) |
|
280 | + { |
|
281 | + $route = $route !== 'index' ? $route : 'list'; |
|
282 | + $relations = Arr::get($this->config['relations'], $this->modelName, false); |
|
283 | + $this->relations = $relations && isset($relations[$route]) ? $relations[$route] : []; |
|
284 | + } |
|
285 | + |
|
286 | + /** |
|
287 | + * Update the logged in user locale and time zone. |
|
288 | + * |
|
289 | + * @param object $user |
|
290 | + * @return void |
|
291 | + */ |
|
292 | + private function updateLocaleAndTimezone($user) |
|
293 | + { |
|
294 | + $update = false; |
|
295 | + $locale = \Session::get('locale'); |
|
296 | + $timezone = \Session::get('time-zone'); |
|
297 | + if ($locale && $locale !== 'all' && $locale !== $user->locale) { |
|
298 | + $user->locale = $locale; |
|
299 | + $update = true; |
|
300 | + } |
|
301 | + |
|
302 | + if ($timezone && $timezone !== $user->timezone) { |
|
303 | + $user->timezone = $timezone; |
|
304 | + $update = true; |
|
305 | + } |
|
306 | + |
|
307 | + if ($update) { |
|
308 | + $user->save(); |
|
309 | + } |
|
310 | + } |
|
311 | 311 | } |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | \Auth::shouldUse('api'); |
220 | 220 | $this->middleware('auth:api', ['except' => $this->skipLoginCheck]); |
221 | 221 | |
222 | - if (! in_array($permission, $this->skipLoginCheck) && $user = \Auth::user()) { |
|
222 | + if ( ! in_array($permission, $this->skipLoginCheck) && $user = \Auth::user()) { |
|
223 | 223 | $user = \Auth::user(); |
224 | 224 | $permission = $permission !== 'index' ? $permission : 'list'; |
225 | 225 | $isPasswordClient = $user->token()->client->password_client; |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | } |
231 | 231 | |
232 | 232 | if ($isPasswordClient && (in_array($permission, $this->skipPermissionCheck) || \Core::users()->can($permission, $this->modelName))) { |
233 | - } elseif (! $isPasswordClient && $user->tokenCan($this->modelName.'-'.$permission)) { |
|
233 | + } elseif ( ! $isPasswordClient && $user->tokenCan($this->modelName.'-'.$permission)) { |
|
234 | 234 | } else { |
235 | 235 | \ErrorHandler::noPermissions(); |
236 | 236 | } |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | |
302 | 302 | if ($timezone && $timezone !== $user->timezone) { |
303 | 303 | $user->timezone = $timezone; |
304 | - $update = true; |
|
304 | + $update = true; |
|
305 | 305 | } |
306 | 306 | |
307 | 307 | if ($update) { |
@@ -34,7 +34,7 @@ |
||
34 | 34 | * @param \Illuminate\Http\Request $request |
35 | 35 | * @param string $reportName Name of the requested report |
36 | 36 | * @param integer $perPage Number of rows per page default all data. |
37 | - * @return \Illuminate\Http\Response |
|
37 | + * @return \Illuminate\Http\JsonResponse |
|
38 | 38 | */ |
39 | 39 | public function getReport(Request $request, $reportName, $perPage = 0) |
40 | 40 | { |
@@ -9,35 +9,35 @@ |
||
9 | 9 | |
10 | 10 | class ReportsController extends BaseApiController |
11 | 11 | { |
12 | - /** |
|
13 | - * List of all route actions that the base api controller |
|
14 | - * will skip permissions check for them. |
|
15 | - * @var array |
|
16 | - */ |
|
17 | - protected $skipPermissionCheck = ['getReport']; |
|
12 | + /** |
|
13 | + * List of all route actions that the base api controller |
|
14 | + * will skip permissions check for them. |
|
15 | + * @var array |
|
16 | + */ |
|
17 | + protected $skipPermissionCheck = ['getReport']; |
|
18 | 18 | |
19 | - /** |
|
20 | - * Init new object. |
|
21 | - * |
|
22 | - * @param ReportRepository $repo |
|
23 | - * @param CoreConfig $config |
|
24 | - * @return void |
|
25 | - */ |
|
26 | - public function __construct(ReportRepository $repo, CoreConfig $config) |
|
27 | - { |
|
28 | - parent::__construct($repo, $config, 'App\Modules\Reporting\Http\Resources\Report'); |
|
29 | - } |
|
19 | + /** |
|
20 | + * Init new object. |
|
21 | + * |
|
22 | + * @param ReportRepository $repo |
|
23 | + * @param CoreConfig $config |
|
24 | + * @return void |
|
25 | + */ |
|
26 | + public function __construct(ReportRepository $repo, CoreConfig $config) |
|
27 | + { |
|
28 | + parent::__construct($repo, $config, 'App\Modules\Reporting\Http\Resources\Report'); |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * Render the given report name with the given conditions. |
|
33 | - * |
|
34 | - * @param \Illuminate\Http\Request $request |
|
35 | - * @param string $reportName Name of the requested report |
|
36 | - * @param integer $perPage Number of rows per page default all data. |
|
37 | - * @return \Illuminate\Http\Response |
|
38 | - */ |
|
39 | - public function getReport(Request $request, $reportName, $perPage = 0) |
|
40 | - { |
|
41 | - return \Response::json($this->repo->getReport($reportName, $request->all(), $perPage), 200); |
|
42 | - } |
|
31 | + /** |
|
32 | + * Render the given report name with the given conditions. |
|
33 | + * |
|
34 | + * @param \Illuminate\Http\Request $request |
|
35 | + * @param string $reportName Name of the requested report |
|
36 | + * @param integer $perPage Number of rows per page default all data. |
|
37 | + * @return \Illuminate\Http\Response |
|
38 | + */ |
|
39 | + public function getReport(Request $request, $reportName, $perPage = 0) |
|
40 | + { |
|
41 | + return \Response::json($this->repo->getReport($reportName, $request->all(), $perPage), 200); |
|
42 | + } |
|
43 | 43 | } |