pixelfed/app/Http/Controllers/SettingsController.php

167 lines
4.1 KiB
PHP
Raw Normal View History

2018-05-26 22:53:21 +00:00
<?php
namespace App\Http\Controllers;
2018-08-28 03:07:36 +00:00
use App\AccountLog;
use App\Following;
2019-02-05 20:59:31 +00:00
use App\Report;
use App\UserFilter;
2019-04-22 05:39:00 +00:00
use Auth, Cookie, DB, Cache, Purify;
2018-12-25 05:41:53 +00:00
use Carbon\Carbon;
2018-08-28 03:07:36 +00:00
use Illuminate\Http\Request;
2018-09-17 01:47:19 +00:00
use App\Http\Controllers\Settings\{
2019-04-24 19:32:23 +00:00
ExportSettings,
2018-09-17 01:47:19 +00:00
HomeSettings,
PrivacySettings,
SecuritySettings
};
2018-12-21 06:18:06 +00:00
use App\Jobs\DeletePipeline\DeleteAccountPipeline;
2018-05-26 22:53:21 +00:00
class SettingsController extends Controller
{
2019-04-24 19:32:23 +00:00
use ExportSettings,
HomeSettings,
2018-09-17 01:47:19 +00:00
PrivacySettings,
SecuritySettings;
2018-05-26 22:53:21 +00:00
public function __construct()
{
2018-08-10 03:17:24 +00:00
$this->middleware('auth');
2018-05-26 22:53:21 +00:00
}
public function accessibility()
{
2018-08-28 03:07:36 +00:00
$settings = Auth::user()->settings;
return view('settings.accessibility', compact('settings'));
}
public function accessibilityStore(Request $request)
{
2018-08-28 03:07:36 +00:00
$settings = Auth::user()->settings;
$fields = [
'compose_media_descriptions',
'reduce_motion',
'optimize_screen_reader',
'high_contrast_mode',
2018-08-28 03:07:36 +00:00
'video_autoplay',
2018-12-21 06:18:06 +00:00
];
2018-08-28 03:07:36 +00:00
foreach ($fields as $field) {
$form = $request->input($field);
if ($form == 'on') {
$settings->{$field} = true;
} else {
$settings->{$field} = false;
}
$settings->save();
}
return redirect(route('settings.accessibility'))->with('status', 'Settings successfully updated!');
}
2018-05-26 22:53:21 +00:00
public function notifications()
{
2018-08-28 03:07:36 +00:00
return view('settings.notifications');
2018-05-26 22:53:21 +00:00
}
public function applications()
{
2018-08-28 03:07:36 +00:00
return view('settings.applications');
2018-05-26 22:53:21 +00:00
}
public function dataImport()
{
2018-08-28 03:07:36 +00:00
return view('settings.import.home');
2018-05-26 22:53:21 +00:00
}
public function dataImportInstagram()
{
2018-08-28 03:07:36 +00:00
return view('settings.import.instagram.home');
2018-05-26 22:53:21 +00:00
}
public function developers()
{
2018-08-28 03:07:36 +00:00
return view('settings.developers');
2018-05-26 22:53:21 +00:00
}
2018-12-21 06:18:06 +00:00
public function removeAccountTemporary(Request $request)
{
return view('settings.remove.temporary');
}
2018-12-25 05:41:53 +00:00
public function removeAccountTemporarySubmit(Request $request)
{
$user = Auth::user();
$profile = $user->profile;
$user->status = 'disabled';
$profile->status = 'disabled';
$user->save();
$profile->save();
Auth::logout();
2019-02-25 06:22:06 +00:00
Cache::forget('profiles:private');
2018-12-25 05:41:53 +00:00
return redirect('/');
}
2018-12-21 06:18:06 +00:00
public function removeAccountPermanent(Request $request)
{
2018-12-30 05:39:39 +00:00
if(config('pixelfed.account_deletion') == false) {
abort(404);
}
2018-12-21 06:18:06 +00:00
return view('settings.remove.permanent');
}
public function removeAccountPermanentSubmit(Request $request)
{
2018-12-30 05:39:39 +00:00
if(config('pixelfed.account_deletion') == false) {
abort(404);
}
2018-12-21 06:18:06 +00:00
$user = Auth::user();
if($user->is_admin == true) {
return abort(400, 'You cannot delete an admin account.');
}
2018-12-25 05:41:53 +00:00
$profile = $user->profile;
$ts = Carbon::now()->addMonth();
$user->status = 'delete';
$profile->status = 'delete';
$user->delete_after = $ts;
$profile->delete_after = $ts;
$user->save();
$profile->save();
2019-02-25 06:22:06 +00:00
Cache::forget('profiles:private');
2018-12-21 06:18:06 +00:00
Auth::logout();
2019-04-22 05:39:00 +00:00
DeleteAccountPipeline::dispatch($user)->onQueue('high');
2018-12-21 06:18:06 +00:00
return redirect('/');
}
2019-02-05 20:59:31 +00:00
public function requestFullExport(Request $request)
{
$user = Auth::user();
return view('settings.export.show');
}
public function reportsHome(Request $request)
{
$profile = Auth::user()->profile;
$reports = Report::whereProfileId($profile->id)->orderByDesc('created_at')->paginate(10);
return view('settings.reports', compact('reports'));
}
2019-04-22 05:39:00 +00:00
public function metroDarkMode(Request $request)
{
$this->validate($request, [
'mode' => 'required|string|in:light,dark'
]);
$mode = $request->input('mode');
if($mode == 'dark') {
$cookie = Cookie::make('dark-mode', true, 43800);
} else {
$cookie = Cookie::forget('dark-mode');
}
return response()->json([200])->cookie($cookie);
}
2018-05-26 22:53:21 +00:00
}
2018-08-31 04:29:38 +00:00