SettingsController.php 4.7 KB

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