From b29ca1823d56b798a958f8b68df71f0471e5ff27 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 23 Jul 2018 23:09:45 -0600 Subject: [PATCH 1/3] Update settings template --- resources/views/settings/template.blade.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/resources/views/settings/template.blade.php b/resources/views/settings/template.blade.php index 2c7fb2a94..c3ad7dbc5 100644 --- a/resources/views/settings/template.blade.php +++ b/resources/views/settings/template.blade.php @@ -10,15 +10,15 @@ @include('settings.partial.sidebar')
@if (session('status')) -
+
{{ session('status') }}
@endif @if ($errors->any())
-
    +
      @foreach ($errors->all() as $error) -
    • {{ $error }}
    • +
    • {{ $error }}
    • @endforeach
From 4ba9e2cd6c4ad29cddb400b0d733de01894d24cf Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 24 Jul 2018 22:33:55 -0600 Subject: [PATCH 2/3] Add infinite scroll to profiles, and support private profiles --- app/Http/Controllers/ProfileController.php | 25 +++++- app/Http/Controllers/SettingsController.php | 87 +++++++++++++++++-- resources/views/profile/show.blade.php | 86 +++++++++++------- .../views/settings/partial/sidebar.blade.php | 22 ++--- resources/views/settings/privacy.blade.php | 29 ++++++- routes/web.php | 15 +--- 6 files changed, 201 insertions(+), 63 deletions(-) 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/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)
@endif -
-
+
@if($owner && request()->is('*/saved'))

{{__('profile.savedWarning')}}

@endif +
+ +
+
+ {{$timeline->links()}} +
+
@else -
-
-
-
-

{{ __('profile.emptyTimeline') }}

+
+
+
+
+

{{ __('profile.emptyTimeline') }}

+
-
- @endif
+ @endif +
@endsection -@push('meta') - - +@push('meta') + + @if(false == $settings->crawlable || $user->remote_url) + + @endif +@endpush + +@push('scripts') + + @endpush diff --git a/resources/views/settings/partial/sidebar.blade.php b/resources/views/settings/partial/sidebar.blade.php index 60ae2bb5c..97e14824d 100644 --- a/resources/views/settings/partial/sidebar.blade.php +++ b/resources/views/settings/partial/sidebar.blade.php @@ -1,44 +1,44 @@ \ No newline at end of file diff --git a/resources/views/settings/privacy.blade.php b/resources/views/settings/privacy.blade.php index b322d4201..2142366fd 100644 --- a/resources/views/settings/privacy.blade.php +++ b/resources/views/settings/privacy.blade.php @@ -6,8 +6,31 @@

Privacy Settings


-
- Coming Soon -
+
+ @csrf +
+ is_private ? 'checked=""':''}}> + +

When your account is private, only people you approve can see your photos and videos on pixelfed. Your existing followers won't be affected.

+
+
+ crawlable ? 'checked=""':''}} {{$settings->is_private ? 'disabled=""':''}}> + +

When your account is visible to search engines, your information can be crawled and stored by search engines.

+
+ + + +
+
+
+ +
+
+
@endsection \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index eb9fe2ad1..5af11925a 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,17 +1,5 @@ group(function() { Route::redirect('/', '/dashboard'); Route::redirect('timeline', config('app.url').'/timeline'); @@ -91,6 +79,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware('validemail')->group(fu Route::get('email', 'SettingsController@email')->name('settings.email'); Route::get('notifications', 'SettingsController@notifications')->name('settings.notifications'); Route::get('privacy', 'SettingsController@privacy')->name('settings.privacy'); + Route::post('privacy', 'SettingsController@privacyStore'); Route::get('security', 'SettingsController@security')->name('settings.security'); Route::get('applications', 'SettingsController@applications')->name('settings.applications'); Route::get('data-export', 'SettingsController@dataExport')->name('settings.dataexport'); @@ -137,4 +126,4 @@ Route::domain(config('pixelfed.domain.app'))->middleware('validemail')->group(fu Route::get('{username}/following', 'ProfileController@following'); Route::get('{username}', 'ProfileController@show'); -}); +}); \ No newline at end of file From c674845a644317855478136136213c6336d89739 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 24 Jul 2018 22:38:59 -0600 Subject: [PATCH 3/3] Update pixelfed config --- config/pixelfed.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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', /* |--------------------------------------------------------------------------