diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index 12e9411b1..05299b1a6 100644 --- a/app/Http/Controllers/ProfileController.php +++ b/app/Http/Controllers/ProfileController.php @@ -18,6 +18,7 @@ class ProfileController extends Controller public function show(Request $request, $username) { $user = Profile::whereUsername($username)->firstOrFail(); + $settings = User::whereUsername($username)->firstOrFail()->settings; $mimes = [ 'application/activity+json', @@ -27,7 +28,12 @@ class ProfileController extends Controller if(in_array($request->header('accept'), $mimes) && config('pixelfed.activitypub_enabled')) { return $this->showActivityPub($request, $user); } - + if($user->is_private == true) { + $can_access = $this->privateProfileCheck($user); + if($can_access !== true) { + abort(403); + } + } // TODO: refactor this mess $owner = Auth::check() && Auth::id() === $user->user_id; $is_following = ($owner == false && Auth::check()) ? $user->followedBy(Auth::user()->profile) : false; @@ -39,7 +45,22 @@ class ProfileController extends Controller ->withCount(['comments', 'likes']) ->simplePaginate(21); - return view('profile.show', compact('user', 'owner', 'is_following', 'is_admin', 'timeline')); + return view('profile.show', compact('user', 'settings', 'owner', 'is_following', 'is_admin', 'timeline')); + } + + protected function privateProfileCheck(Profile $profile) + { + if(Auth::check() === false) { + return false; + } + + $follower_ids = (array) $profile->followers()->pluck('followers.profile_id'); + $pid = Auth::user()->profile->id; + if(!in_array($pid, $follower_ids) && $pid !== $profile->id) { + return false; + } + + return true; } public function showActivityPub(Request $request, $user) diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index 4beb45418..48ca6150a 100644 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -3,8 +3,8 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; -use App\{Profile, User}; -use Auth; +use App\{AccountLog, Profile, User}; +use Auth, DB; class SettingsController extends Controller { @@ -89,6 +89,34 @@ class SettingsController extends Controller return view('settings.avatar'); } + public function accessibility() + { + $settings = Auth::user()->settings; + return view('settings.accessibility', compact('settings')); + } + + public function accessibilityStore(Request $request) + { + $settings = Auth::user()->settings; + $fields = [ + 'compose_media_descriptions', + 'reduce_motion', + 'optimize_screen_reader', + 'high_contrast_mode', + 'video_autoplay' + ]; + 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!'); + } + public function notifications() { return view('settings.notifications'); @@ -96,12 +124,61 @@ class SettingsController extends Controller public function privacy() { - return view('settings.privacy'); + $settings = Auth::user()->settings; + $is_private = Auth::user()->profile->is_private; + $settings['is_private'] = (bool) $is_private; + return view('settings.privacy', compact('settings')); + } + + public function privacyStore(Request $request) + { + $settings = Auth::user()->settings; + $profile = Auth::user()->profile; + $fields = [ + 'is_private', + 'crawlable', + ]; + foreach($fields as $field) { + $form = $request->input($field); + if($field == 'is_private') { + if($form == 'on') { + $profile->{$field} = true; + $settings->show_guests = false; + $settings->show_discover = false; + $profile->save(); + } else { + $profile->{$field} = false; + $profile->save(); + } + } elseif($field == 'crawlable') { + if($form == 'on') { + $settings->{$field} = false; + } else { + $settings->{$field} = true; + } + } else { + if($form == 'on') { + $settings->{$field} = true; + } else { + $settings->{$field} = false; + } + } + $settings->save(); + } + return redirect(route('settings.privacy'))->with('status', 'Settings successfully updated!'); } public function security() { - return view('settings.security'); + $sessions = DB::table('sessions') + ->whereUserId(Auth::id()) + ->limit(20) + ->get(); + $activity = AccountLog::whereUserId(Auth::id()) + ->orderBy('created_at','desc') + ->limit(50) + ->get(); + return view('settings.security', compact('sessions', 'activity')); } public function applications() @@ -121,7 +198,7 @@ class SettingsController extends Controller public function dataImportInstagram() { - return view('settings.import.ig'); + return view('settings.import.instagram.home'); } public function developers() diff --git a/config/pixelfed.php b/config/pixelfed.php index 43d60717b..3e9782ac8 100644 --- a/config/pixelfed.php +++ b/config/pixelfed.php @@ -23,7 +23,7 @@ return [ | This value is the version of your PixelFed instance. | */ - 'version' => '0.1.1', + 'version' => '0.1.2', /* |-------------------------------------------------------------------------- diff --git a/resources/views/profile/show.blade.php b/resources/views/profile/show.blade.php index 525f24d18..2f5b3ec8d 100644 --- a/resources/views/profile/show.blade.php +++ b/resources/views/profile/show.blade.php @@ -4,7 +4,7 @@ @include('profile.partial.user-info') -@if($owner == true) +@if(true === $owner)
{{__('profile.savedWarning')}}
{{ __('profile.emptyTimeline') }}
+{{ __('profile.emptyTimeline') }}
+