From 9dc6892178b7cf1f586ee46b64d7388d41f20f86 Mon Sep 17 00:00:00 2001 From: RoelReijn <34895541+RoelReijn@users.noreply.github.com> Date: Sun, 13 Dec 2020 16:04:28 +0100 Subject: [PATCH 01/18] =?UTF-8?q?=F0=9F=93=9A=20Update=20README=20for=20ne?= =?UTF-8?q?w=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit New installation instructions and additional information about the new release. --- README.md | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 76464cc..c95b9a4 100644 --- a/README.md +++ b/README.md @@ -7,9 +7,9 @@ Laravel 8 has a new and very efficient application scaffolding package called [Jetstream](https://jetstream.laravel.com), many users however do not want to learn a new framework (TailWind CSS). Luckily, the backend of Jetstream has been made available under the name of Fortify. Fortify is a headless authentication backend without any pre-configured frontend templates which is a disadvantage. [FortifyUI](https://github.com/zacksmash/fortify-ui) improves Fortify by adding that missing feature. -This package is a preset for FortifyUI, it brings ready-to-use and beautiful templates for the most important pages which include: login, registration, password reset pages and two factor authentication. The templates are based and build on the [Tabler.io](https://tabler.io) framework which is build with Bootstrap 5.0. +This package is a preset for FortifyUI, it brings ready-to-use and beautiful templates for the most important pages which include: login, registration, password reset pages and two factor authentication. In the latest release, avatars and device management are introduced. The templates are based and build on the [Tabler.io](https://tabler.io) framework which is build with Bootstrap 5.0. -This preset includes Tabler assets for [release 1.0.0-alpha.13](https://github.com/tabler/tabler/releases/tag/v1.0.0-alpha.15). +This preset includes Tabler assets for [release 1.0.0-alpha.15](https://github.com/tabler/tabler/releases/tag/v1.0.0-alpha.15). - [Installation](#installation) - [Two Factor Authentication](#2fa) @@ -21,28 +21,30 @@ This preset includes Tabler assets for [release 1.0.0-alpha.13](https://github.c ## Installation -To get started, you'll need to have FortifyUI installed. Firstly, install it using composer: +To get started please install the package using composer. This command also installs [FortifyUI](https://github.com/zacksmash/fortify-ui) so you shouldn't install it first. ```bash -composer require zacksmash/fortify-ui +composer require proxeuse/fortify-tabler ``` -After the installation, run the install command. +Once installed, please run the installer using the following PHP artisan command. The installer will take you through the installation process and ask you some questions. ```bash -php artisan fortify-ui:install +php artisan fortify-ui:tabler ``` -After installing FortifyUI, you'll have to install **fortify-tabler**. Again using composer: +Please do not forget to run the `php artisan migrate` command after the successfull installation! -```bash -composer require proxeuse/fortify-tabler -``` +### Set session driver to database -Next, you'll need to run the install command. Please note the change from `fortify-ui:install` to `fortify-ui:tabler`. This command will publish **fortify-tabler's** views and resources to your project. +This package features a function for users to force-logout devices from their account. In order for this function to work you'll need to have set the session driver to database. This can be done by chaning the `SESSION_DRIVER` variable in the `.env` file to `database`. A part of the file will look like the one below. In this example the session lifetime is set to 5 days instead of the default 2 hours. ```bash -php artisan fortify-ui:tabler +BROADCAST_DRIVER=log +CACHE_DRIVER=file +QUEUE_CONNECTION=sync +SESSION_DRIVER=database +SESSION_LIFETIME=7200 ``` From 72201b07f13c23b72fa37ec16bfc1e05d6945772 Mon Sep 17 00:00:00 2001 From: RoelReijn <34895541+RoelReijn@users.noreply.github.com> Date: Sun, 13 Dec 2020 16:06:58 +0100 Subject: [PATCH 02/18] =?UTF-8?q?=E2=9A=A1=20Update=20FortifyUITabler=20Co?= =?UTF-8?q?mmand=20and=20the=20ServiceProvider?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make files ready for the latest release by adding an installer to the fortify-ui:tabler command. In addition, save the ServiceProvider for additional migrations, controllers, languages, etc. --- src/Commands/FortifyUITablerCommand.php | 32 +++++++++++++++++++++++-- src/FortifyUITablerServiceProvider.php | 11 ++++++++- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/Commands/FortifyUITablerCommand.php b/src/Commands/FortifyUITablerCommand.php index 2f05d17..f7fb02a 100644 --- a/src/Commands/FortifyUITablerCommand.php +++ b/src/Commands/FortifyUITablerCommand.php @@ -12,13 +12,41 @@ class FortifyUITablerCommand extends Command public function handle() { - $this->publishAssets(); + // confirm the installation + if ($this->confirm('Do you wish to continue? Please only continue on a fresh Laravel installation since multiple files are overwritten by the installer.', false)) { + // install fortifyUI + Artisan::call('fortify-ui:install'); + $this->info('FortifyUI has been installed. Proceeding to install Tabler.io.'); + + // publish the assets, routes, controllers, etc. + $this->publishAssets(); - $this->comment('The Tabler.io Framework is now installed.'); + // request information on session driver + $this->changeSessionDriver(); + + // print success message + $this->info('The Tabler.io Framework is now installed.'); + $this->newLine(); + $this->line('Please run \'php artisan migrate\' before continuing.'); + } else { + // print abort message + $this->error('Installation is aborted'); + } } protected function publishAssets() { $this->callSilent('vendor:publish', ['--tag' => 'fortify-ui-tabler-resources', '--force' => true]); } + + protected function changeSessionDriver(){ + if($this->confirm('This package only works out of the box if you have set your session driver to \'database\', have you already changed it?', true)) { + $this->line('Great! We\'ll create a new migration for the table right now.'); + Artisan::call('php artisan session:table'); + $this->newLine(); + } else { + $this->line('No problem! Please make sure however to change it manually according to the documentation at https://github.com/proxeuse/fortify-tabler/.'); + $this->newLine(); + } + } } diff --git a/src/FortifyUITablerServiceProvider.php b/src/FortifyUITablerServiceProvider.php index 1f65399..17aa105 100644 --- a/src/FortifyUITablerServiceProvider.php +++ b/src/FortifyUITablerServiceProvider.php @@ -10,10 +10,19 @@ class FortifyUITablerServiceProvider extends ServiceProvider public function boot() { if ($this->app->runningInConsole()) { + // Load translation files + $this->loadTranslationsFrom(__DIR__.'/../stubs/resources/lang', 'tabler'); + // Load Routes + $this->loadRoutesFrom(__DIR__.'/../stubs/routes/web.php'); + // Load Migrations + $this->loadMigrationsFrom(__DIR__.'/../stubs/database/migrations'); + + // Publis files $this->publishes([ __DIR__ . '/../stubs/resources/views' => base_path('resources/views'), __DIR__ . '/../stubs/public' => base_path('public'), - __DIR__ . '/../stubs/lang' => base_path('resources/lang'), + __DIR__ . '/../stubs/resources/lang' => base_path('resources/lang/vendor/tabler'), + __DIR__ . '/../stubs/app/Http/Controllers' => base_path('app/Http/Controllers'), ], 'fortify-ui-tabler-resources'); $this->commands([ From f1bda6e72f5f1e28009acbef4e816becfe49606f Mon Sep 17 00:00:00 2001 From: RoelReijn <34895541+RoelReijn@users.noreply.github.com> Date: Sun, 13 Dec 2020 16:07:34 +0100 Subject: [PATCH 03/18] =?UTF-8?q?=E2=9A=A1=20Update=20composer.json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Require intervention/image and add extra keywords. --- composer.json | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 8420aa7..bcfeb30 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,9 @@ "name": "proxeuse/fortify-tabler", "description": "A preset for FortifyUI based on the Tabler Bootstrap framework.", "keywords": [ - "fortify-ui" + "fortify-ui", + "laravel", + "tabler.io" ], "homepage": "https://github.com/Proxeuse/fortify-tabler/", "license": "MIT", @@ -22,7 +24,8 @@ "require": { "php": "^7.4", "illuminate/contracts": "^8.0", - "zacksmash/fortify-ui": "^1.0" + "zacksmash/fortify-ui": "^1.0", + "intervention/image": "^2.5.1" }, "require-dev": { "friendsofphp/php-cs-fixer": "^2.16", From 7e44cd8b59e21d4677a9e077108f9f5e46a9d2cf Mon Sep 17 00:00:00 2001 From: RoelReijn <34895541+RoelReijn@users.noreply.github.com> Date: Sun, 13 Dec 2020 16:10:23 +0100 Subject: [PATCH 04/18] =?UTF-8?q?=F0=9F=9A=80=20deploy=20routes=20and=20co?= =?UTF-8?q?ntroller?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit By adding the routes and controller we create a possibility for many additional features. These include avatars and device management in this release. --- .../Http/Controllers/ProfileController.php | 107 ++++++++++++++++++ stubs/routes/web.php | 6 + 2 files changed, 113 insertions(+) create mode 100644 stubs/app/Http/Controllers/ProfileController.php create mode 100644 stubs/routes/web.php diff --git a/stubs/app/Http/Controllers/ProfileController.php b/stubs/app/Http/Controllers/ProfileController.php new file mode 100644 index 0000000..81485a1 --- /dev/null +++ b/stubs/app/Http/Controllers/ProfileController.php @@ -0,0 +1,107 @@ +where('user_id', \Auth::user()->id)->get()->reverse(); + return view('profile.edit', ['devices' => $devices]); + } + + /** + * Update the Avatar + * + * @param Request + * @return \Illuminate\Http\Response + */ + public function updateAvatar(Request $request){ + // validate + $request->validate([ + 'avatar' => 'required|image|mimes:jpeg,png,jpg,gif,webp|max:2048|dimensions:min_width=200,min_height=200', + ]); + + // remove old avatar from storage + $this->removeOldAvatar(true); + + // process avatar and redirect back + if($this->processAvatar($request)) { + return Redirect::back()->with('success', 'Updated the avatar successfully!'); + } else { + return Redirect::back()->withErrors(['avatar', 'Failed to update the avatar']); + } + } + + /** + * Process the resize and storage of the image + * + * @param $request + * @return boolean + */ + private function processAvatar($request){ + // get file + $file = $request->file('avatar'); + // get filename name with extension + $filename = pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME); + // remove unwanted characters + $filename = preg_replace("/[^A-Za-z0-9 ]/", '', $filename); + $filename = preg_replace("/\s+/", '-', $filename); + // create unique file name + $uniqueFileName = substr(md5($filename), 0, 15).'_'.time().'.'.$file->getClientOriginalExtension(); + + // resize avatar + $resize = Image::make($file)->fit(400, null, function($constraint){ + $constraint->upsize(); + })->encode('png'); + // save avatar to public storage + $save = \Storage::put("public/avatars/{$uniqueFileName}", $resize->__toString()); + + // if avatar has been stored successfully + if($save){ + // update user table + $user = \Auth::user(); + $user->avatar = $uniqueFileName; + $user->save(); + // return success + return true; + } else { + return false; + } + } + + /** + * Remove avatar currently in use + * + * @param $internalRequest + * @return boolean + * @return \Illuminate\Http\Response + */ + public function removeOldAvatar($internalRequest = false){ + $user = \Auth::user(); + // if user has an avatar currently in use + if($user->avatar){ + // delete avatar from storage + \Storage::delete('public/avatars/'.$user->avatar); + } + $user->avatar = null; + $user->save(); + + // if request comes from front-end + if($internalRequest){ + return true; + } else { + return Redirect::back()->with('success', 'The avatar has been deleted successfully!'); + } + } +} \ No newline at end of file diff --git a/stubs/routes/web.php b/stubs/routes/web.php new file mode 100644 index 0000000..0f01dba --- /dev/null +++ b/stubs/routes/web.php @@ -0,0 +1,6 @@ +name('profile'); +Route::post('/profile/avatar', [\App\Http\Controllers\ProfileController::class, 'updateAvatar'])->name('profile.avatar'); +Route::delete('/profile/avatar', [\App\Http\Controllers\ProfileController::class, 'removeOldAvatar'])->name('profile.deleteavatar'); +Route::delete('/profile/device', [\App\Http\Controllers\ProfileController::class, ''])->name('profile.deletedevice'); \ No newline at end of file From 7ef1ab96cca2184a9540a5e1d23fbe3c56a7343c Mon Sep 17 00:00:00 2001 From: RoelReijn <34895541+RoelReijn@users.noreply.github.com> Date: Sun, 13 Dec 2020 16:11:05 +0100 Subject: [PATCH 05/18] =?UTF-8?q?=F0=9F=9A=80=20update=20user=20table=20mi?= =?UTF-8?q?gration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Required for the functioning of the avatars. --- .../2020_12_13_155612_update_users_table.php | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 stubs/database/migrations/2020_12_13_155612_update_users_table.php diff --git a/stubs/database/migrations/2020_12_13_155612_update_users_table.php b/stubs/database/migrations/2020_12_13_155612_update_users_table.php new file mode 100644 index 0000000..936c39f --- /dev/null +++ b/stubs/database/migrations/2020_12_13_155612_update_users_table.php @@ -0,0 +1,32 @@ +string('avatar')->after('password')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('users', function (Blueprint $table) { + $table->dropColumn('avatar'); + }); + } +} From 73a56b5f2d65a65f9e218ce433929f6b328689aa Mon Sep 17 00:00:00 2001 From: RoelReijn <34895541+RoelReijn@users.noreply.github.com> Date: Sun, 13 Dec 2020 16:12:45 +0100 Subject: [PATCH 06/18] =?UTF-8?q?=F0=9F=9A=9A=F0=9F=8C=90=20moved=20langua?= =?UTF-8?q?ge=20files?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- stubs/{ => resources}/lang/en/auth.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename stubs/{ => resources}/lang/en/auth.php (100%) diff --git a/stubs/lang/en/auth.php b/stubs/resources/lang/en/auth.php similarity index 100% rename from stubs/lang/en/auth.php rename to stubs/resources/lang/en/auth.php From 4cb8481fe0051ccc38796e9ea9dd500f8f432e44 Mon Sep 17 00:00:00 2001 From: RoelReijn <34895541+RoelReijn@users.noreply.github.com> Date: Sun, 13 Dec 2020 16:15:45 +0100 Subject: [PATCH 07/18] =?UTF-8?q?=F0=9F=8C=90=20update=20localization=20st?= =?UTF-8?q?rings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit By moving the language files a necessary update in the language strings. --- .../views/auth/confirm-password.blade.php | 10 ++++----- .../views/auth/forgot-password.blade.php | 10 ++++----- stubs/resources/views/auth/login.blade.php | 22 +++++++++---------- stubs/resources/views/auth/register.blade.php | 22 +++++++++---------- .../views/auth/reset-password.blade.php | 18 +++++++-------- .../views/auth/two-factor-challenge.blade.php | 18 +++++++-------- .../views/auth/verify-email.blade.php | 8 +++---- stubs/resources/views/layouts/auth.blade.php | 2 +- 8 files changed, 55 insertions(+), 55 deletions(-) diff --git a/stubs/resources/views/auth/confirm-password.blade.php b/stubs/resources/views/auth/confirm-password.blade.php index df4428b..cc01637 100644 --- a/stubs/resources/views/auth/confirm-password.blade.php +++ b/stubs/resources/views/auth/confirm-password.blade.php @@ -5,23 +5,23 @@
@csrf
-

{{ __('auth.confirmpassword') }}

+

{{ __('tabler::auth.confirmpassword') }}

- - {{ __('tabler::auth.fields.password') }} +
@if (Route::has('password.request')) @endif diff --git a/stubs/resources/views/auth/forgot-password.blade.php b/stubs/resources/views/auth/forgot-password.blade.php index ebd8df3..d693ed7 100644 --- a/stubs/resources/views/auth/forgot-password.blade.php +++ b/stubs/resources/views/auth/forgot-password.blade.php @@ -4,17 +4,17 @@
@csrf
-

{{ __('auth.forgotpassword') }}

-

{{ __('auth.forgotpasswordtext') }}

+

{{ __('tabler::auth.forgotpassword') }}

+

{{ __('tabler::auth.forgotpasswordtext') }}

- - {{ __('tabler::auth.fields.email') }} +
diff --git a/stubs/resources/views/auth/login.blade.php b/stubs/resources/views/auth/login.blade.php index ae82cc9..15bf454 100644 --- a/stubs/resources/views/auth/login.blade.php +++ b/stubs/resources/views/auth/login.blade.php @@ -5,26 +5,26 @@
@csrf
-

{{ __('auth.login') }}

+

{{ __('tabler::auth.login') }}

- - {{ __('tabler::auth.fields.email') }} +
@if(Route::has('register')) @endif diff --git a/stubs/resources/views/auth/register.blade.php b/stubs/resources/views/auth/register.blade.php index 178d021..6ba7b68 100644 --- a/stubs/resources/views/auth/register.blade.php +++ b/stubs/resources/views/auth/register.blade.php @@ -4,22 +4,22 @@
@csrf
-

{{ __('auth.register') }}

+

{{ __('tabler::auth.register') }}

- + + class="form-control" placeholder="{{ __('tabler::auth.placeholder.name') }}" tabindex="1">
- + + placeholder="{{ __('tabler::auth.placeholder.email') }}" tabindex="2">
@endsection diff --git a/stubs/resources/views/auth/reset-password.blade.php b/stubs/resources/views/auth/reset-password.blade.php index d053ed9..1f079ce 100644 --- a/stubs/resources/views/auth/reset-password.blade.php +++ b/stubs/resources/views/auth/reset-password.blade.php @@ -5,20 +5,20 @@ @csrf
-

{{ __('auth.forgotpassword') }}

-

{{ __('auth.forgotpasswordtext') }}

+

{{ __('tabler::auth.forgotpassword') }}

+

{{ __('tabler::auth.forgotpasswordtext') }}

- - {{ __('tabler::auth.fields.email') }} +
- +
+ placeholder="{{ __('tabler::auth.placeholder.password') }}" tabindex="3">
- + + class="form-control" placeholder="{{ __('tabler::auth.placeholder.passwordconfirmation') }}" tabindex="4">
diff --git a/stubs/resources/views/auth/two-factor-challenge.blade.php b/stubs/resources/views/auth/two-factor-challenge.blade.php index 7056f88..771f7ea 100644 --- a/stubs/resources/views/auth/two-factor-challenge.blade.php +++ b/stubs/resources/views/auth/two-factor-challenge.blade.php @@ -5,32 +5,32 @@
@csrf
-

{{ __('auth.2fa.title') }}

+

{{ __('tabler::auth.2fa.title') }}

- +
- {{ __('auth.2fa.codehelp') }} + {{ __('tabler::auth.2fa.codehelp') }}
- +
- {{ __('auth.2fa.emergencycodehelp') }} + {{ __('tabler::auth.2fa.emergencycodehelp') }}