diff --git a/app/Http/Controllers/Api/BaseApiController.php b/app/Http/Controllers/Api/BaseApiController.php index dd78b16f..29487fc5 100644 --- a/app/Http/Controllers/Api/BaseApiController.php +++ b/app/Http/Controllers/Api/BaseApiController.php @@ -3,15 +3,22 @@ namespace App\Http\Controllers\Api; use Auth; -use App\{Like, Profile, Status}; +use App\{ + Avatar, + Like, + Profile, + Status +}; use League\Fractal; use Illuminate\Http\Request; use App\Http\Controllers\Controller; +use App\Http\Controllers\AvatarController; use App\Util\Webfinger\Webfinger; use App\Transformer\Api\{ AccountTransformer, StatusTransformer }; +use App\Jobs\AvatarPipeline\AvatarOptimize; use League\Fractal\Serializer\ArraySerializer; class BaseApiController extends Controller @@ -68,4 +75,37 @@ class BaseApiController extends Controller $res = $this->fractal->createData($resource)->toArray(); return response()->json($res); } + + public function avatarUpdate(Request $request) + { + $this->validate($request, [ + 'upload' => 'required|mimes:jpeg,png,gif|max:2000', + ]); + try { + $user = Auth::user(); + $file = $request->file('upload'); + $path = (new AvatarController())->getPath($user, $file); + $dir = $path['root']; + $name = $path['name']; + $public = $path['storage']; + $currentAvatar = storage_path('app/'.$user->profile->avatar->media_path); + $loc = $request->file('upload')->storeAs($public, $name); + + $avatar = Avatar::whereProfileId($user->profile->id)->firstOrFail(); + $opath = $avatar->media_path; + $avatar->media_path = "$public/$name"; + $avatar->thumb_path = null; + $avatar->change_count = ++$avatar->change_count; + $avatar->last_processed_at = null; + $avatar->save(); + + AvatarOptimize::dispatch($user->profile, $currentAvatar); + } catch (Exception $e) { + } + + return response()->json([ + 'code' => 200, + 'msg' => 'Avatar successfully updated' + ]); + } } \ No newline at end of file diff --git a/app/Http/Controllers/AvatarController.php b/app/Http/Controllers/AvatarController.php index c0fd06cf..fb1515bd 100644 --- a/app/Http/Controllers/AvatarController.php +++ b/app/Http/Controllers/AvatarController.php @@ -17,7 +17,7 @@ class AvatarController extends Controller public function store(Request $request) { $this->validate($request, [ - 'avatar' => 'required|mimes:jpeg,png|max:1000' + 'avatar' => 'required|mimes:jpeg,png|max:2000' ]); try { $user = Auth::user(); diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index f3a8415c..95859efa 100644 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -3,7 +3,7 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; -use App\{AccountLog, Media, Profile, User}; +use App\{AccountLog, EmailVerification, Media, Profile, User}; use Auth, DB; use App\Util\Lexer\PrettyNumber; @@ -31,24 +31,45 @@ class SettingsController extends Controller { $this->validate($request, [ 'name' => 'required|string|max:30', - 'bio' => 'nullable|string|max:125' + 'bio' => 'nullable|string|max:125', + 'website' => 'nullable|url', + 'email' => 'nullable|email' ]); $changes = false; $name = $request->input('name'); $bio = $request->input('bio'); + $website = $request->input('website'); + $email = $request->input('email'); $user = Auth::user(); $profile = $user->profile; - if($profile->name != $name) { + + if($user->email != $email) { $changes = true; - $user->name = $name; - $profile->name = $name; + $user->email = $email; + $user->email_verified_at = null; + // Prevent old verifications from working + EmailVerification::whereUserId($user->id)->delete(); } - if($profile->bio != $bio) { - $changes = true; - $profile->bio = $bio; + // Only allow email to be updated if not yet verified + if(!$changes && $user->email_verified_at) { + if($profile->name != $name) { + $changes = true; + $user->name = $name; + $profile->name = $name; + } + + if($profile->website != $website) { + $changes = true; + $profile->website = $website; + } + + if($profile->bio != $bio) { + $changes = true; + $profile->bio = $bio; + } } if($changes === true) { diff --git a/app/Http/Middleware/EmailVerificationCheck.php b/app/Http/Middleware/EmailVerificationCheck.php index b9ff791d..1d748db3 100644 --- a/app/Http/Middleware/EmailVerificationCheck.php +++ b/app/Http/Middleware/EmailVerificationCheck.php @@ -18,8 +18,7 @@ class EmailVerificationCheck if($request->user() && config('pixelfed.enforce_email_verification') && is_null($request->user()->email_verified_at) && - !$request->is('i/verify-email') && !$request->is('log*') && - !$request->is('i/confirm-email/*') + !$request->is('i/verify-email', 'log*', 'i/confirm-email/*', 'settings/home') ) { return redirect('/i/verify-email'); } diff --git a/resources/views/settings/home.blade.php b/resources/views/settings/home.blade.php index c064853b..4c43b306 100644 --- a/resources/views/settings/home.blade.php +++ b/resources/views/settings/home.blade.php @@ -8,6 +8,15 @@
@csrf +
+
+ +
+
+

{{Auth::user()->username}}

+

Change Profile Photo

+
+
@@ -15,15 +24,21 @@
- +
- +
- +
- + +
+
+
+ +
+
@@ -32,15 +47,91 @@
- + +

+ @if(Auth::user()->email_verified_at) + Verified {{Auth::user()->email_verified_at->diffForHumans()}} + @else + Unverified You need to verify your email. + @endif +


-
- +
+
-@endsection \ No newline at end of file +@endsection + +@push('scripts') + +@endpush \ No newline at end of file diff --git a/resources/views/settings/partial/sidebar.blade.php b/resources/views/settings/partial/sidebar.blade.php index c8af3ce2..18588b59 100644 --- a/resources/views/settings/partial/sidebar.blade.php +++ b/resources/views/settings/partial/sidebar.blade.php @@ -3,9 +3,9 @@ - + --}} @@ -14,7 +14,8 @@ --}} + + --}} diff --git a/routes/web.php b/routes/web.php index 3a9a0eb2..53f34cc7 100644 --- a/routes/web.php +++ b/routes/web.php @@ -38,6 +38,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware('validemail')->group(fu Route::get('nodeinfo/2.0.json', 'FederationController@nodeinfo'); Route::group(['prefix' => 'v1'], function() { + Route::post('avatar/update', 'ApiController@avatarUpdate'); Route::get('likes', 'ApiController@hydrateLikes'); }); Route::group(['prefix' => 'local'], function() {