mirror of
https://github.com/pixelfed/pixelfed.git
synced 2025-01-30 16:30:45 +00:00
Add LabsSettings controller
This commit is contained in:
parent
e3b9fb759c
commit
8946121334
1 changed files with 83 additions and 0 deletions
83
app/Http/Controllers/Settings/LabsSettings.php
Normal file
83
app/Http/Controllers/Settings/LabsSettings.php
Normal file
|
@ -0,0 +1,83 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Settings;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Cookie, Redis;
|
||||||
|
use App\Services\SuggestionService;
|
||||||
|
|
||||||
|
trait LabsSettings {
|
||||||
|
|
||||||
|
public function __constructor()
|
||||||
|
{
|
||||||
|
$this->middleware('auth');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function labs(Request $request)
|
||||||
|
{
|
||||||
|
$profile = $request->user()->profile;
|
||||||
|
return view('settings.labs', compact('profile'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function labsStore(Request $request)
|
||||||
|
{
|
||||||
|
$this->validate($request, [
|
||||||
|
'profile_layout' => 'nullable',
|
||||||
|
'dark_mode' => 'nullable',
|
||||||
|
'profile_suggestions' => 'nullable'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$changes = false;
|
||||||
|
|
||||||
|
$profile = $request->user()->profile;
|
||||||
|
|
||||||
|
$cookie = Cookie::forget('dark-mode');
|
||||||
|
if($request->has('dark_mode') && $profile->profile_layout != 'moment') {
|
||||||
|
if($request->dark_mode == 'on') {
|
||||||
|
$cookie = Cookie::make('dark-mode', true, 43800);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if($request->has('profile_layout')) {
|
||||||
|
if($profile->profile_layout != 'moment') {
|
||||||
|
$profile->profile_layout = 'moment';
|
||||||
|
$changes = true;
|
||||||
|
} else {
|
||||||
|
$profile->profile_layout = null;
|
||||||
|
$changes = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if($profile->profile_layout == 'moment') {
|
||||||
|
$profile->profile_layout = null;
|
||||||
|
$changes = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if($request->has('profile_suggestions')) {
|
||||||
|
if($profile->is_suggestable == false) {
|
||||||
|
$profile->is_suggestable = true;
|
||||||
|
$changes = true;
|
||||||
|
SuggestionService::set($profile->id);
|
||||||
|
} else {
|
||||||
|
$profile->is_suggestable = false;
|
||||||
|
$changes = true;
|
||||||
|
SuggestionService::del($profile->id);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if($profile->is_suggestable == true) {
|
||||||
|
$profile->is_suggestable = false;
|
||||||
|
$changes = true;
|
||||||
|
SuggestionService::del($profile->id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if($changes == true) {
|
||||||
|
$profile->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
return redirect(route('settings.labs'))
|
||||||
|
->with('status', 'Labs preferences successfully updated!')
|
||||||
|
->cookie($cookie);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue