SettingsController.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\AccountLog;
  4. use App\Following;
  5. use App\Report;
  6. use App\UserFilter;
  7. use Auth, Cookie, DB, Cache, Purify;
  8. use Carbon\Carbon;
  9. use Illuminate\Http\Request;
  10. use App\Http\Controllers\Settings\{
  11. HomeSettings,
  12. PrivacySettings,
  13. SecuritySettings
  14. };
  15. use App\Jobs\DeletePipeline\DeleteAccountPipeline;
  16. class SettingsController extends Controller
  17. {
  18. use HomeSettings,
  19. PrivacySettings,
  20. SecuritySettings;
  21. public function __construct()
  22. {
  23. $this->middleware('auth');
  24. }
  25. public function accessibility()
  26. {
  27. $settings = Auth::user()->settings;
  28. return view('settings.accessibility', compact('settings'));
  29. }
  30. public function accessibilityStore(Request $request)
  31. {
  32. $settings = Auth::user()->settings;
  33. $fields = [
  34. 'compose_media_descriptions',
  35. 'reduce_motion',
  36. 'optimize_screen_reader',
  37. 'high_contrast_mode',
  38. 'video_autoplay',
  39. ];
  40. foreach ($fields as $field) {
  41. $form = $request->input($field);
  42. if ($form == 'on') {
  43. $settings->{$field} = true;
  44. } else {
  45. $settings->{$field} = false;
  46. }
  47. $settings->save();
  48. }
  49. return redirect(route('settings.accessibility'))->with('status', 'Settings successfully updated!');
  50. }
  51. public function notifications()
  52. {
  53. return view('settings.notifications');
  54. }
  55. public function applications()
  56. {
  57. return view('settings.applications');
  58. }
  59. public function dataExport()
  60. {
  61. return view('settings.dataexport');
  62. }
  63. public function exportFollowing()
  64. {
  65. $data = Cache::remember('account:export:profile:following:'.Auth::user()->profile->id, now()->addMinutes(60), function() {
  66. return Auth::user()->profile->following()->get()->map(function($i) {
  67. return $i->url();
  68. });
  69. });
  70. return response()->streamDownload(function () use($data) {
  71. echo $data;
  72. }, 'following.json');
  73. }
  74. public function exportFollowers()
  75. {
  76. $data = Cache::remember('account:export:profile:followers:'.Auth::user()->profile->id, now()->addMinutes(60), function() {
  77. return Auth::user()->profile->followers()->get()->map(function($i) {
  78. return $i->url();
  79. });
  80. });
  81. return response()->streamDownload(function () use($data) {
  82. echo $data;
  83. }, 'followers.json');
  84. }
  85. public function exportMuteBlockList()
  86. {
  87. $profile = Auth::user()->profile;
  88. $exists = UserFilter::select('id')
  89. ->whereUserId($profile->id)
  90. ->exists();
  91. if(!$exists) {
  92. return redirect()->back();
  93. }
  94. $data = Cache::remember('account:export:profile:muteblocklist:'.Auth::user()->profile->id, now()->addMinutes(60), function() use($profile) {
  95. return json_encode([
  96. 'muted' => $profile->mutedProfileUrls(),
  97. 'blocked' => $profile->blockedProfileUrls()
  98. ], JSON_PRETTY_PRINT);
  99. });
  100. return response()->streamDownload(function () use($data) {
  101. echo $data;
  102. }, 'muted-and-blocked-accounts.json');
  103. }
  104. public function dataImport()
  105. {
  106. return view('settings.import.home');
  107. }
  108. public function dataImportInstagram()
  109. {
  110. return view('settings.import.instagram.home');
  111. }
  112. public function developers()
  113. {
  114. return view('settings.developers');
  115. }
  116. public function removeAccountTemporary(Request $request)
  117. {
  118. return view('settings.remove.temporary');
  119. }
  120. public function removeAccountTemporarySubmit(Request $request)
  121. {
  122. $user = Auth::user();
  123. $profile = $user->profile;
  124. $user->status = 'disabled';
  125. $profile->status = 'disabled';
  126. $user->save();
  127. $profile->save();
  128. Auth::logout();
  129. Cache::forget('profiles:private');
  130. return redirect('/');
  131. }
  132. public function removeAccountPermanent(Request $request)
  133. {
  134. if(config('pixelfed.account_deletion') == false) {
  135. abort(404);
  136. }
  137. return view('settings.remove.permanent');
  138. }
  139. public function removeAccountPermanentSubmit(Request $request)
  140. {
  141. if(config('pixelfed.account_deletion') == false) {
  142. abort(404);
  143. }
  144. $user = Auth::user();
  145. if($user->is_admin == true) {
  146. return abort(400, 'You cannot delete an admin account.');
  147. }
  148. $profile = $user->profile;
  149. $ts = Carbon::now()->addMonth();
  150. $user->status = 'delete';
  151. $profile->status = 'delete';
  152. $user->delete_after = $ts;
  153. $profile->delete_after = $ts;
  154. $user->save();
  155. $profile->save();
  156. Cache::forget('profiles:private');
  157. Auth::logout();
  158. DeleteAccountPipeline::dispatch($user)->onQueue('high');
  159. return redirect('/');
  160. }
  161. public function requestFullExport(Request $request)
  162. {
  163. $user = Auth::user();
  164. return view('settings.export.show');
  165. }
  166. public function reportsHome(Request $request)
  167. {
  168. $profile = Auth::user()->profile;
  169. $reports = Report::whereProfileId($profile->id)->orderByDesc('created_at')->paginate(10);
  170. return view('settings.reports', compact('reports'));
  171. }
  172. public function metroDarkMode(Request $request)
  173. {
  174. $this->validate($request, [
  175. 'mode' => 'required|string|in:light,dark'
  176. ]);
  177. $mode = $request->input('mode');
  178. if($mode == 'dark') {
  179. $cookie = Cookie::make('dark-mode', true, 43800);
  180. } else {
  181. $cookie = Cookie::forget('dark-mode');
  182. }
  183. return response()->json([200])->cookie($cookie);
  184. }
  185. }