SettingsController.php 4.0 KB

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