From f53c7cc544b56a1118275d4481e98a4a4fc07c67 Mon Sep 17 00:00:00 2001 From: Dmitrijs Mihailovs Date: Wed, 28 Feb 2018 13:37:46 +0200 Subject: [PATCH] New setting module version&other improvements - Use setting 2.0 version - Some code formatting - Remove unnecessary folders --- Console/.gitkeep | 0 Emails/.gitkeep | 0 Events/.gitkeep | 0 .../Admin/PermissionsController.php | 1 + Http/Controllers/Admin/RolesController.php | 1 + Http/Controllers/Admin/UsersController.php | 4 +-- Jobs/.gitkeep | 0 Listeners/.gitkeep | 0 Models/UserOauthIdentity.php | 3 +- Notifications/.gitkeep | 0 Traits/AdminUsersPagination.php | 2 +- Traits/ControllerSocialite.php | 29 +++++-------------- Traits/ModuleUser.php | 5 ++-- Traits/ReplaceableAttributes.php | 15 +++++----- Traits/UserPermissions.php | 8 ++--- composer.json | 3 +- 16 files changed, 30 insertions(+), 41 deletions(-) delete mode 100644 Console/.gitkeep delete mode 100644 Emails/.gitkeep delete mode 100644 Events/.gitkeep delete mode 100644 Jobs/.gitkeep delete mode 100644 Listeners/.gitkeep delete mode 100644 Notifications/.gitkeep diff --git a/Console/.gitkeep b/Console/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/Emails/.gitkeep b/Emails/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/Events/.gitkeep b/Events/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/Http/Controllers/Admin/PermissionsController.php b/Http/Controllers/Admin/PermissionsController.php index 036fdf0..f565b66 100644 --- a/Http/Controllers/Admin/PermissionsController.php +++ b/Http/Controllers/Admin/PermissionsController.php @@ -10,6 +10,7 @@ class PermissionsController extends Controller { /** * Display a listing of the resource. + * * @return Response */ public function index() diff --git a/Http/Controllers/Admin/RolesController.php b/Http/Controllers/Admin/RolesController.php index d301a8b..67b18ef 100644 --- a/Http/Controllers/Admin/RolesController.php +++ b/Http/Controllers/Admin/RolesController.php @@ -10,6 +10,7 @@ class RolesController extends Controller { /** * Display a listing of the resource. + * * @return Response */ public function index() diff --git a/Http/Controllers/Admin/UsersController.php b/Http/Controllers/Admin/UsersController.php index e351a7f..ca14b6b 100644 --- a/Http/Controllers/Admin/UsersController.php +++ b/Http/Controllers/Admin/UsersController.php @@ -42,9 +42,7 @@ public function __construct() $this->config = array_merge($this->config, $fromConfig); - $this->model = app( - config('auth.providers.users.model') - ); + $this->model = app(config('auth.providers.users.model')); } /** diff --git a/Jobs/.gitkeep b/Jobs/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/Listeners/.gitkeep b/Listeners/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/Models/UserOauthIdentity.php b/Models/UserOauthIdentity.php index bfe9485..04dee6e 100644 --- a/Models/UserOauthIdentity.php +++ b/Models/UserOauthIdentity.php @@ -52,6 +52,7 @@ class UserOauthIdentity extends Model /** * UserOauthIdentity constructor. + * * @param array $attributes */ public function __construct($attributes = []) @@ -80,4 +81,4 @@ public function setLastLoginTime() 'last_login_at' => Carbon::now() ]); } -} \ No newline at end of file +} diff --git a/Notifications/.gitkeep b/Notifications/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/Traits/AdminUsersPagination.php b/Traits/AdminUsersPagination.php index 8fabe05..582217c 100644 --- a/Traits/AdminUsersPagination.php +++ b/Traits/AdminUsersPagination.php @@ -61,7 +61,7 @@ private function modifyDatatableColumns(&$datatable, $presenter) foreach ($this->getDatatableColumns() as $name => $title) { $method = camel_case($name); - if (! method_exists($presenter, $method)) { + if (!method_exists($presenter, $method)) { continue; } diff --git a/Traits/ControllerSocialite.php b/Traits/ControllerSocialite.php index cd91632..2c70696 100644 --- a/Traits/ControllerSocialite.php +++ b/Traits/ControllerSocialite.php @@ -16,8 +16,8 @@ protected function getProviders() { $providers = []; - foreach(config('netcore.module-user.socialite-providers') as $provider => $state) { - if($state) { + foreach (config('netcore.module-user.socialite-providers') as $provider => $state) { + if ($state) { $providers[] = $provider; } } @@ -38,8 +38,6 @@ public function providerRedirect(string $provider) return Socialite::driver($provider)->redirect(); } - - /** * Check for provider existence * @@ -53,25 +51,16 @@ private function providerGate(string $provider) } // Set redirect URL on the fly (must be absolute) - config()->set( - 'services.' . $provider . '.client_id', - setting()->get($provider . '_client_id') - ); - config()->set( - 'services.' . $provider . '.client_secret', - setting()->get($provider . '_client_secret') - ); - config()->set( - 'services.' . $provider . '.redirect', - url('/login/' . $provider . '/callback') - ); + config()->set('services.' . $provider . '.client_id', setting()->get('oauth.' . $provider . '_client_id')); + config()->set('services.' . $provider . '.client_secret', setting()->get('oauth.' . $provider . '_client_secret')); + config()->set('services.' . $provider . '.redirect', url('/login/' . $provider . '/callback')); } /** * Bad response handler * * @param Exception $exception - * @param string $provider + * @param string $provider * @return \Illuminate\Http\RedirectResponse */ private function handleBadProviderResponse(Exception $exception, string $provider) @@ -81,9 +70,7 @@ private function handleBadProviderResponse(Exception $exception, string $provide if ($attempts > 5) { session()->forget($provider . '-attempts'); - return redirect()->route('login')->withErrors( - trans('login.unexpected_provider_error') - ); + return redirect()->route('login')->withErrors(trans('login.unexpected_provider_error')); } $attempts++; @@ -93,4 +80,4 @@ private function handleBadProviderResponse(Exception $exception, string $provide return $this->providerRedirect($provider); } -} \ No newline at end of file +} diff --git a/Traits/ModuleUser.php b/Traits/ModuleUser.php index 7ffcec7..679652f 100644 --- a/Traits/ModuleUser.php +++ b/Traits/ModuleUser.php @@ -2,7 +2,8 @@ namespace Modules\User\Traits; -trait ModuleUser { +trait ModuleUser +{ /** * Set "fullName" attribute on model @@ -25,4 +26,4 @@ public function gravatar($size = 90) return '//www.gravatar.com/avatar/' . md5($this->email) . '?s=' . $size . '&d=mm'; } -} \ No newline at end of file +} diff --git a/Traits/ReplaceableAttributes.php b/Traits/ReplaceableAttributes.php index 1902bb9..0534b51 100644 --- a/Traits/ReplaceableAttributes.php +++ b/Traits/ReplaceableAttributes.php @@ -1,7 +1,9 @@ replaceable ?? []; - $prefix = $this->replaceablePrefix ?? ''; - $replaceable = []; + $attributes = $this->replaceable ?? []; + $prefix = $this->replaceablePrefix ?? ''; + $replaceable = []; - foreach ($attributes as $attribute) - { + foreach ($attributes as $attribute) { $replaceable[strtoupper($prefix . $attribute)] = $this[$attribute] ?? null; } return $replaceable; } - + } diff --git a/Traits/UserPermissions.php b/Traits/UserPermissions.php index 761db8b..18464ad 100644 --- a/Traits/UserPermissions.php +++ b/Traits/UserPermissions.php @@ -16,7 +16,7 @@ public function role() { $module = Module::find('Permission'); - if (! $module || !$module->enabled()) { + if (!$module || !$module->enabled()) { return (object)[ 'levels' => collect() ]; @@ -34,8 +34,6 @@ public function isAdmin() } /** - * - * * @param Request $request * @return bool * @internal param $name @@ -61,7 +59,7 @@ public function hasPermission(Request $request): bool if (!$levels->count() && !$user->isAdmin()) { return false; } - + foreach ($levels as $level) { foreach ($level->routes as $route) { if ($route->route) { @@ -89,4 +87,4 @@ public function hasPermission(Request $request): bool return false; } -} \ No newline at end of file +} diff --git a/composer.json b/composer.json index 091b145..21ecc11 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,8 @@ "require": { "php": ">=7.0", "yajra/laravel-datatables-oracle": "~8.0", - "maatwebsite/excel": "~2.1.0" + "maatwebsite/excel": "~2.1.0", + "netcore/module-setting": "^2.0" }, "minimum-stability": "dev" }