diff --git a/.env.docker b/.env.docker index 276a5b75..9efda3e9 100644 --- a/.env.docker +++ b/.env.docker @@ -12,12 +12,6 @@ APP_KEY= # Enable the debug more if you are running into issues or while developing APP_DEBUG=true -## LinkAce settings -# The page title configures the content of the element -PAGE_TITLE='' -# If set to true, guests can access your public bookmarks and notes -GUEST_ACCESS=false - ## Configuration of the database connection # Set the database driver (mysql, ) DB_CONNECTION=mysql diff --git a/.env.example b/.env.example index 7e6b0a02..f108f333 100644 --- a/.env.example +++ b/.env.example @@ -12,12 +12,6 @@ APP_KEY= # Enable the debug more if you are running into issues or while developing APP_DEBUG=true -## LinkAce settings -# The page title configures the content of the element -PAGE_TITLE='' -# If set to true, guests can access your public bookmarks and notes -GUEST_ACCESS=false - ## Configuration of the database connection # Set the database driver (mysql, ) DB_CONNECTION=mysql diff --git a/app/Console/RegisterUserCommand.php b/app/Console/RegisterUserCommand.php index 04d37a91..bea9d0a7 100644 --- a/app/Console/RegisterUserCommand.php +++ b/app/Console/RegisterUserCommand.php @@ -30,11 +30,6 @@ class RegisterUserCommand extends Command */ protected $description = 'Register a new user'; - private $user_roles = [ - 'admin', - 'user', - ]; - /** * RegisterUser constructor. */ @@ -69,16 +64,12 @@ public function handle() $password = $this->secret('Please enter a password for ' . $name); - $role = $this->choice('Please choose the user role:', $this->user_roles, 'user'); - $new_user = User::create([ 'name' => $name, 'email' => $email, 'password' => Hash::make($password), ]); - $new_user->assignRole($role); - $this->info('User ' . $name . ' registered.'); return; } diff --git a/app/Http/Controllers/App/SystemSettingsController.php b/app/Http/Controllers/App/SystemSettingsController.php index 013058ea..7ea1551c 100644 --- a/app/Http/Controllers/App/SystemSettingsController.php +++ b/app/Http/Controllers/App/SystemSettingsController.php @@ -19,19 +19,37 @@ class SystemSettingsController extends Controller */ public function getSystemSettings() { - if (!auth()->user()->hasRole('admin')) { - abort(403); - } - return view('actions.settings.system'); } /** + * Syve the new system settings to the database + * * @param Request $request + * @return \Illuminate\Http\RedirectResponse */ public function saveSystemSettings(Request $request) { - // + $request->validate([ + 'system_guest_access' => 'numeric', + ]); + + $settings = $request->except(['_token']); + + foreach ($settings as $key => $value) { + Setting::updateOrCreate([ + 'key' => $key, + 'user_id' => null, + ], [ + 'key' => $key, + 'value' => $value, + 'user_id' => null, + ]); + } + + alert(trans('settings.settings_saved')); + + return redirect()->back(); } /** @@ -42,10 +60,6 @@ public function saveSystemSettings(Request $request) */ public function generateCronToken(Request $request) { - if (!auth()->user()->hasRole('admin')) { - abort(403); - } - $new_token = Str::random(32); Setting::updateOrCreate( diff --git a/app/Http/Controllers/FrontController.php b/app/Http/Controllers/FrontController.php index 18bd8f11..f9362823 100644 --- a/app/Http/Controllers/FrontController.php +++ b/app/Http/Controllers/FrontController.php @@ -17,7 +17,7 @@ class FrontController extends Controller public function index() { if (!auth()->check()) { - if (env('GUEST_ACCESS', false)) { + if (systemsettings('system_guest_access')) { return redirect()->route('guest.links.index'); } diff --git a/app/Http/Controllers/Guest/CategoryController.php b/app/Http/Controllers/Guest/CategoryController.php index c0dc6d8c..ce5e6b6b 100644 --- a/app/Http/Controllers/Guest/CategoryController.php +++ b/app/Http/Controllers/Guest/CategoryController.php @@ -8,32 +8,6 @@ class CategoryController extends Controller { - /** - * Display a listing of the resource. - * - * @param Request $request - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View - */ - public function index(Request $request) - { - $categories = Category::parentOnly(); - - if ($request->has('orderBy') && $request->has('orderDir')) { - $categories->orderBy($request->get('orderBy'), $request->get('orderDir')); - } else { - $categories->orderBy('name', 'ASC'); - } - - $categories = $categories->paginate(getPaginationLimit()); - - return view('guest.categories.index', [ - 'categories' => $categories, - 'route' => $request->fullUrl(), - 'order_by' => $request->get('orderBy'), - 'order_dir' => $request->get('orderDir'), - ]); - } - /** * Display the specified resource. * diff --git a/app/Http/Controllers/Guest/TagController.php b/app/Http/Controllers/Guest/TagController.php index 9855390f..1227a8b0 100644 --- a/app/Http/Controllers/Guest/TagController.php +++ b/app/Http/Controllers/Guest/TagController.php @@ -8,30 +8,6 @@ class TagController extends Controller { - /** - * Display a listing of the resource. - * - * @param Request $request - * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View - */ - public function index(Request $request) - { - if ($request->has('orderBy') && $request->has('orderDir')) { - $tags = Tag::orderBy($request->get('orderBy'), $request->get('orderDir')); - } else { - $tags = Tag::orderBy('name', 'ASC'); - } - - $tags = $tags->paginate(getPaginationLimit()); - - return view('guest.tags.index', [ - 'tags' => $tags, - 'route' => $request->fullUrl(), - 'order_by' => $request->get('orderBy'), - 'order_dir' => $request->get('orderDir'), - ]); - } - /** * Display the specified resource. * diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index d775f991..2fca81fa 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -58,6 +58,7 @@ class Kernel extends HttpKernel 'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class, 'can' => \Illuminate\Auth\Middleware\Authorize::class, 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, + 'guestaccess' => \App\Http\Middleware\GuestAccess::class, 'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class, 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, ]; diff --git a/app/Http/Middleware/GuestAccess.php b/app/Http/Middleware/GuestAccess.php new file mode 100644 index 00000000..2e1ae229 --- /dev/null +++ b/app/Http/Middleware/GuestAccess.php @@ -0,0 +1,30 @@ +check()) { + return redirect()->route('dashboard'); + } + + // Check if guest access is enabled + if (systemsettings('system_guest_access') === '1') { + return $next($request); + } + + return redirect()->route('login'); + } +} diff --git a/app/Models/User.php b/app/Models/User.php index e03c939a..26b85e23 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -4,7 +4,6 @@ use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; -use Spatie\Permission\Traits\HasRoles; /** * Class User @@ -21,7 +20,6 @@ class User extends Authenticatable { use Notifiable; - use HasRoles; /** * The attributes that are mass assignable. diff --git a/composer.json b/composer.json index 618d0a3a..203e4a7f 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "A small, selfhosted bookmark manager with advanced features, built with Laravel and Docker", "license": "MIT", "type": "project", - "version": "0.0.7", + "version": "0.0.8", "require": { "php": "^7.1.3", "doctrine/dbal": "^2.8", @@ -12,7 +12,6 @@ "laravel/tinker": "^1.0", "predis/predis": "^1.1", "shaarli/netscape-bookmark-parser": "^2.1", - "spatie/laravel-permission": "^2.31", "vinkla/alert": "^3.0.0", "watson/rememberable": "^2.0" }, diff --git a/composer.lock b/composer.lock index d4511416..b5cef9bd 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "61ecf329332d3fe2925409dede678144", + "content-hash": "313cf8fe91a97df39b0ea11a2008533a", "packages": [ { "name": "dnoegel/php-xdg-base-dir", @@ -2385,71 +2385,6 @@ ], "time": "2018-10-06T14:43:38+00:00" }, - { - "name": "spatie/laravel-permission", - "version": "2.31.0", - "source": { - "type": "git", - "url": "https://github.com/spatie/laravel-permission.git", - "reference": "5f9960854295c6aec1c706aaa3b146962d6ee905" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/spatie/laravel-permission/zipball/5f9960854295c6aec1c706aaa3b146962d6ee905", - "reference": "5f9960854295c6aec1c706aaa3b146962d6ee905", - "shasum": "" - }, - "require": { - "illuminate/auth": "~5.3.0|~5.4.0|~5.5.0|~5.6.0|~5.7.0", - "illuminate/container": "~5.3.0|~5.4.0|~5.5.0|~5.6.0|~5.7.0", - "illuminate/contracts": "~5.3.0|~5.4.0|~5.5.0|~5.6.0|~5.7.0", - "illuminate/database": "~5.4.0|~5.5.0|~5.6.0|~5.7.0", - "php": ">=7.0" - }, - "require-dev": { - "orchestra/testbench": "~3.4.2|~3.5.0|~3.6.0|~3.7.0", - "phpunit/phpunit": "^5.7|6.2|^7.0", - "predis/predis": "^1.1" - }, - "type": "library", - "extra": { - "laravel": { - "providers": [ - "Spatie\\Permission\\PermissionServiceProvider" - ] - } - }, - "autoload": { - "psr-4": { - "Spatie\\Permission\\": "src" - }, - "files": [ - "src/helpers.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Freek Van der Herten", - "email": "freek@spatie.be", - "homepage": "https://spatie.be", - "role": "Developer" - } - ], - "description": "Permission handling for Laravel 5.4 and up", - "homepage": "https://github.com/spatie/laravel-permission", - "keywords": [ - "acl", - "laravel", - "permission", - "security", - "spatie" - ], - "time": "2019-02-04T03:56:54+00:00" - }, { "name": "swiftmailer/swiftmailer", "version": "v6.1.3", @@ -3574,6 +3509,7 @@ "flash", "laravel" ], + "abandoned": "laracasts/flash", "time": "2018-08-23T11:35:12+00:00" }, { diff --git a/package.json b/package.json index 0b747031..742e4374 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "linkace", - "version": "0.0.7", + "version": "0.0.8", "description": "A small, selfhosted bookmark manager with advanced features, built with Laravel and Docker", "homepage": "https://github.com/Kovah/LinkAce", "repository": { diff --git a/resources/lang/en/settings.php b/resources/lang/en/settings.php index 76764d82..152c7b46 100644 --- a/resources/lang/en/settings.php +++ b/resources/lang/en/settings.php @@ -42,6 +42,10 @@ 'api_token_generate_info' => 'Caution: If you already have an API token, generating a new one will break all existing integrations!', 'api_token_generate_failure' => 'A new API token could not be generated. Please check your browser console and application logs for more information.', + 'sys_page_title' => 'Page Title', + 'sys_guest_access' => 'Enable Guest Access', + 'sys_guest_access_help' => 'If enabled, guest will be able to see all links that are not private.', + 'cron_token' => 'Cron Token', 'cron_token_generate' => 'Generate Token', 'cron_token_generate_confirm' => 'Do you really want to generate a new token?', diff --git a/resources/views/actions/settings/partials/cron.blade.php b/resources/views/actions/settings/partials/system/cron.blade.php similarity index 100% rename from resources/views/actions/settings/partials/cron.blade.php rename to resources/views/actions/settings/partials/system/cron.blade.php diff --git a/resources/views/actions/settings/partials/system/general-settings.blade.php b/resources/views/actions/settings/partials/system/general-settings.blade.php new file mode 100644 index 00000000..8d9a8b42 --- /dev/null +++ b/resources/views/actions/settings/partials/system/general-settings.blade.php @@ -0,0 +1,70 @@ +
+
+ @lang('settings.user_settings') +
+
+ +
+ @csrf + +
+
+ +
+ + + @if ($errors->has('system_page_title')) + + @endif +
+ +
+
+ +
+ + +

@lang('settings.sys_guest_access_help')

+ @if ($errors->has('system_guest_access')) + + @endif +
+ +
+
+ + + +
+ +
+
+ +@push('scripts') + +@endpush diff --git a/resources/views/actions/settings/system.blade.php b/resources/views/actions/settings/system.blade.php index f958b457..5428ab59 100644 --- a/resources/views/actions/settings/system.blade.php +++ b/resources/views/actions/settings/system.blade.php @@ -2,6 +2,8 @@ @section('content') - @include('actions.settings.partials.cron') + @include('actions.settings.partials.system.cron') + + @include('actions.settings.partials.system.general-settings') @endsection diff --git a/resources/views/guest/categories/partials/single.blade.php b/resources/views/guest/categories/partials/single.blade.php index ff30b815..2dec922d 100644 --- a/resources/views/guest/categories/partials/single.blade.php +++ b/resources/views/guest/categories/partials/single.blade.php @@ -13,7 +13,4 @@ {{ $category->links->count() }} - - {{ $category->user->name }} - diff --git a/resources/views/guest/categories/partials/table.blade.php b/resources/views/guest/categories/partials/table.blade.php index 6ed5773e..964282c5 100644 --- a/resources/views/guest/categories/partials/table.blade.php +++ b/resources/views/guest/categories/partials/table.blade.php @@ -11,9 +11,6 @@ @lang('link.links') - - {!! tableSorter(trans('user.user'), $route, 'user_id', $order_by, $order_dir) !!} - diff --git a/resources/views/guest/categories/show.blade.php b/resources/views/guest/categories/show.blade.php index 14c2ebff..ebc4593c 100644 --- a/resources/views/guest/categories/show.blade.php +++ b/resources/views/guest/categories/show.blade.php @@ -3,13 +3,8 @@ @section('content')
-
- - @lang('category.category') - -
- @lang('category.author', ['user' => $category->user->name]) -
+
+ @lang('category.category')
diff --git a/resources/views/guest/links/partials/single-table.blade.php b/resources/views/guest/links/partials/single-table.blade.php index b68f45bf..514f213c 100644 --- a/resources/views/guest/links/partials/single-table.blade.php +++ b/resources/views/guest/links/partials/single-table.blade.php @@ -12,7 +12,4 @@ {!! $link->addedAt() !!} - - {{ $link->user->name }} - diff --git a/resources/views/guest/links/partials/single.blade.php b/resources/views/guest/links/partials/single.blade.php index b9fcee7e..281f294c 100644 --- a/resources/views/guest/links/partials/single.blade.php +++ b/resources/views/guest/links/partials/single.blade.php @@ -55,12 +55,6 @@
-
- - @lang('link.author', ['user' => $link->user->name]) - -
-
diff --git a/resources/views/guest/links/partials/table.blade.php b/resources/views/guest/links/partials/table.blade.php index 6f9b4333..66ddad72 100644 --- a/resources/views/guest/links/partials/table.blade.php +++ b/resources/views/guest/links/partials/table.blade.php @@ -11,9 +11,6 @@ {!! tableSorter(trans('linkace.added_at'), $route, 'created_at', $order_by, $order_dir) !!} - - {!! tableSorter(trans('user.user'), $route, 'user_id', $order_by, $order_dir) !!} - diff --git a/resources/views/guest/partials/nav.blade.php b/resources/views/guest/partials/nav.blade.php index af70ae05..6059b555 100644 --- a/resources/views/guest/partials/nav.blade.php +++ b/resources/views/guest/partials/nav.blade.php @@ -16,16 +16,6 @@ @lang('link.links') - -