Skip to content

Commit

Permalink
Merge pull request #3 from Proxeuse/v1.1.0
Browse files Browse the repository at this point in the history
🔖 v1.1.0
  • Loading branch information
roelreijneveld authored Dec 13, 2020
2 parents 683f84b + e3a5ae9 commit 30ee645
Show file tree
Hide file tree
Showing 25 changed files with 1,782 additions and 972 deletions.
26 changes: 14 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.17](https://github.com/tabler/tabler/releases/tag/v1.0.0-alpha.17).

- [Installation](#installation)
- [Two Factor Authentication](#2fa)
Expand All @@ -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
```

<a name="2fa"></a>
Expand Down
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
42 changes: 40 additions & 2 deletions src/Commands/FortifyUITablerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Proxeuse\FortifyUITabler\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Schema;

class FortifyUITablerCommand extends Command
{
Expand All @@ -12,13 +13,50 @@ 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
if(!Schema::hasTable('sessions')){
$this->changeSessionDriver();
}

// create symbolic link
\Artisan::call('storage:link');

// Clear the Route cache
\Artisan::call('route:clear');
\Artisan::call('route:cache');

// 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('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();
}
}
}
9 changes: 8 additions & 1 deletion src/FortifyUITablerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,17 @@ class FortifyUITablerServiceProvider extends ServiceProvider
public function boot()
{
if ($this->app->runningInConsole()) {
// 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'),
__DIR__ . '/../stubs/app/Http/Controllers' => base_path('app/Http/Controllers'),
], 'fortify-ui-tabler-resources');

$this->commands([
Expand Down
118 changes: 118 additions & 0 deletions stubs/app/Http/Controllers/ProfileController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?php

namespace App\Http\Controllers;

use App\Http\Controllers;
use Illuminate\Http\Request;
use Intervention\Image\Facades\Image;

class ProfileController extends Controller
{

/**
* Display the Edit Profile page
*
* @return \Illuminate\View\View
*/
public function editProfile(){
$devices = \DB::table('sessions')->where('user_id', \Auth::user()->id)->get()->reverse();
return view('profile.edit', ['devices' => $devices]);
}

/**
* Update the Avatar
*
* @param \Illuminate\Http\Request $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!');
}
}

/**
* Remove unused device
*
* @param \Illuminate\Http\Request $request
* @param $id
* @return \Illuminate\Http\Response
*/
public function removeDevice(Request $request, $id){
$delete = \DB::table('sessions')->where('id', $id)->delete();
return \Redirect::back()->with('success', 'The device has been deleted successfully!');
}
}
32 changes: 32 additions & 0 deletions stubs/database/migrations/2020_12_13_155612_update_users_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class UpdateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->string('avatar')->after('password')->nullable();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('avatar');
});
}
}
4 changes: 2 additions & 2 deletions stubs/public/dist/css/demo.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* Tabler v1.0.0-alpha.15 (https://tabler.io)
* @version 1.0.0-alpha.15
* Tabler v1.0.0-alpha.17 (https://tabler.io)
* @version 1.0.0-alpha.17
* @link https://tabler.io
* Copyright 2018-2020 The Tabler Authors
* Copyright 2018-2020 codecalm.net Paweł Kuna
Expand Down
4 changes: 2 additions & 2 deletions stubs/public/dist/css/demo.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions stubs/public/dist/css/tabler-flags.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* Tabler v1.0.0-alpha.15 (https://tabler.io)
* @version 1.0.0-alpha.15
* Tabler v1.0.0-alpha.17 (https://tabler.io)
* @version 1.0.0-alpha.17
* @link https://tabler.io
* Copyright 2018-2020 The Tabler Authors
* Copyright 2018-2020 codecalm.net Paweł Kuna
Expand Down
4 changes: 2 additions & 2 deletions stubs/public/dist/css/tabler-flags.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions stubs/public/dist/css/tabler-payments.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* Tabler v1.0.0-alpha.15 (https://tabler.io)
* @version 1.0.0-alpha.15
* Tabler v1.0.0-alpha.17 (https://tabler.io)
* @version 1.0.0-alpha.17
* @link https://tabler.io
* Copyright 2018-2020 The Tabler Authors
* Copyright 2018-2020 codecalm.net Paweł Kuna
Expand Down
4 changes: 2 additions & 2 deletions stubs/public/dist/css/tabler-payments.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions stubs/public/dist/css/tabler-vendors.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* Tabler v1.0.0-alpha.15 (https://tabler.io)
* @version 1.0.0-alpha.15
* Tabler v1.0.0-alpha.17 (https://tabler.io)
* @version 1.0.0-alpha.17
* @link https://tabler.io
* Copyright 2018-2020 The Tabler Authors
* Copyright 2018-2020 codecalm.net Paweł Kuna
Expand All @@ -27,9 +27,9 @@
.selectize-control.is-valid {
padding: 0; }
.selectize-control.is-valid .selectize-input {
border-color: #5eba00; }
border-color: #2fb344; }
.selectize-control.is-valid .selectize-input.focus {
box-shadow: 0 0 0 0.25rem rgba(94, 186, 0, 0.25); }
box-shadow: 0 0 0 0.25rem rgba(47, 179, 68, 0.25); }
.selectize-control.is-valid .selectize-dropdown {
background: none;
background-color: inherit;
Expand All @@ -38,9 +38,9 @@
.selectize-control.is-invalid {
padding: 0; }
.selectize-control.is-invalid .selectize-input {
border-color: #e53e3e; }
border-color: #d63939; }
.selectize-control.is-invalid .selectize-input.focus {
box-shadow: 0 0 0 0.25rem rgba(229, 62, 62, 0.25); }
box-shadow: 0 0 0 0.25rem rgba(214, 57, 57, 0.25); }
.selectize-control.is-invalid .selectize-dropdown {
background: none;
background-color: inherit;
Expand Down
Loading

0 comments on commit 30ee645

Please sign in to comment.