🚧 Commence la personnalisation de l'affichage des pages

Pour #12
This commit is contained in:
2022-04-19 16:55:18 +02:00
parent 2c56eb91af
commit 1dca0951e8
18 changed files with 695 additions and 24 deletions

View File

@@ -45,12 +45,14 @@ class PageController extends Controller
}
}, Storage::disk('pages')->files(Auth::user()->getAuthIdentifier())));
/** @var \App\Models\User $user */
$user = Auth::user();
return view('pages.index', [
'start_date'=> min((new DateTime())->sub(new DateInterval('P1Y')), $user->created_at),
'checkword' => $user->checkword,
'pages' => $pages,
'start_date' => min((new DateTime())->sub(new DateInterval('P1Y')), $user->created_at),
'checkword' => $user->checkword,
'settings' => json_encode($user->getSettings()),
'pages' => $pages,
]);
}
@@ -124,7 +126,7 @@ class PageController extends Controller
*/
public function edit($id)
{
throw new MethodNotAllowedHttpException('You can\'t edit a page.');
throw new MethodNotAllowedHttpException(['GET'], 'You can\'t edit a page.');
}
/**
@@ -137,7 +139,7 @@ class PageController extends Controller
*/
public function update(Request $request, $id)
{
throw new MethodNotAllowedHttpException('You can\'t edit a page.');
throw new MethodNotAllowedHttpException(['GET'], 'You can\'t edit a page.');
}
/**

View File

@@ -2,6 +2,7 @@
namespace App\Http\Controllers;
use App\Http\Requests\User\SettingsRequest;
use App\Http\Requests\User\WordCheckRequest;
use App\Models\User;
use Illuminate\Support\Facades\Auth;
@@ -23,4 +24,26 @@ class UserController extends Controller
return response()->json(['success' => true]);
}
public function settings()
{
return view('user.settings', [
'settings' => Auth::user()->getSettings(),
]);
}
public function storeSettings(SettingsRequest $request)
{
$validated = $request->validated();
$user = User::where('id', Auth::user()->getAuthIdentifier())->firstOrFail();
foreach ($validated as $name => $value) {
$user->{$name} = $value;
}
$user->save();
Auth::setUser($user);
$request->session()->flash('status', __('Settings saved!'));
return redirect()->route('user.settings');
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace App\Http\Requests\User;
use Illuminate\Foundation\Http\FormRequest;
class SettingsRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'text_color' => ['required', 'string', 'max:7'],
'background_color' => ['required', 'string', 'max:7'],
'font' => ['required', 'string', 'max:255'],
'font_size' => ['required', 'numeric'],
'line_spacing' => ['required', 'numeric'],
];
}
}

View File

@@ -33,6 +33,14 @@ class User extends Authenticatable
'remember_token',
];
protected $settings = [
'text_color',
'background_color',
'font',
'font_size',
'line_spacing',
];
/**
* The attributes that should be cast.
*
@@ -41,4 +49,17 @@ class User extends Authenticatable
protected $casts = [
'email_verified_at' => 'datetime',
];
/**
* @return array
*/
public function getSettings()
{
$settings = [];
foreach ($this->settings as $setting) {
$settings[$setting] = $this->{$setting};
}
return $settings;
}
}