From 4191dd39ea36ff0f7db8c10eb6d6e8d98b2f8119 Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Tue, 29 Jun 2021 12:29:17 +0300 Subject: [PATCH] Support images and multipart requests --- app/Http/Controllers/Api/UsersController.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php index 599f7ded55..ff7d9ef862 100644 --- a/app/Http/Controllers/Api/UsersController.php +++ b/app/Http/Controllers/Api/UsersController.php @@ -16,6 +16,7 @@ use App\Models\License; use App\Models\User; use Auth; use Illuminate\Http\Request; +use App\Http\Requests\ImageUploadRequest; use Illuminate\Support\Facades\Storage; class UsersController extends Controller @@ -228,6 +229,8 @@ class UsersController extends Controller $tmp_pass = substr(str_shuffle('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'), 0, 20); $user->password = bcrypt($request->get('password', $tmp_pass)); + app('App\Http\Requests\ImageUploadRequest')->handleImages($user, 600, 'image', 'avatars', 'avatar'); + if ($user->save()) { if ($request->filled('groups')) { $user->groups()->sync($request->input('groups')); @@ -280,7 +283,7 @@ class UsersController extends Controller } $user->fill($request->all()); - + if ($user->id == $request->input('manager_id')) { return response()->json(Helper::formatStandardApiResponse('error', null, 'You cannot be your own manager')); } @@ -306,6 +309,9 @@ class UsersController extends Controller Asset::where('assigned_type', User::class) ->where('assigned_to', $user->id)->update(['location_id' => $request->input('location_id', null)]); + + app('App\Http\Requests\ImageUploadRequest')->handleImages($user, 600, 'image', 'avatars', 'avatar'); + if ($user->save()) { // Sync group memberships: